This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(tidyr) | |
| library(dplyr) | |
| # load in data | |
| d <- read.csv('~/Desktop/orig_ratings.csv', stringsAsFactors = FALSE) | |
| # stack participants | |
| d_stack <- gather(d, 'participant', 'score', 2:ncol(d)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(ggplot2) | |
| library(dplyr) | |
| library(tidyr) | |
| # create dummy data | |
| df=data.frame(PM=as.factor(1:8), | |
| phase=rep(c('1', '2'),each = 4), | |
| y=rnorm(8, mean = 10, sd = 3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load package | |
| library(dplyr) | |
| library(tidyr) | |
| # read in data | |
| d <- readRDS('~/Desktop/subs_GUD') | |
| glimpse(d) | |
| # need to group by tray1,day, site, trayno, type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load package | |
| library(ggplot2) | |
| # write function | |
| label_facets <- function(string){ | |
| len <- length(string) | |
| string = paste('(', letters[1:len], ') ', string, sep = '') | |
| return(string) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # forcing a segmented regression through the origin. | |
| # load packages | |
| library(segmented) | |
| # make data | |
| d <- data.frame(x = c(3, 13, 18, 19, 19, 26, 26, 33, 40, 49, 51, 53, 67, 70, 88 | |
| ), | |
| y = c(3.56211608128595, 10.5214485148819, 3.66063708049802, 6.11000808621074, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # quick linear regression using broom and the tidyverse #### | |
| # load packages | |
| library(tidyr) | |
| library(ggplot2) | |
| library(dplyr) | |
| library(broom) | |
| library(gapminder) | |
| library(janitor) | |
| library(purrr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load packages | |
| library(ggplot2) | |
| library(broom) | |
| # load in data | |
| d <- read.csv('where/your/data/is.csv', stringsAsFactors = FALSE) | |
| # try and fit an nls model using the exponential decay model | |
| N(t) = N0 * e^-a*t | |
| # N0 = number at t 0. here t is FiO2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # example for Cat | |
| # set seed | |
| set.seed(42) | |
| # load packages #### | |
| library(ggplot2) | |
| library(dplyr) | |
| library(tidyr) | |
| library(broom) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # want to model the data as a segmented regression, so the curve has two straight lines, segmented regression can do this | |
| # xChange is the x value at which the gradients change when the gradient after xChange is forced to be 0 | |
| lin_segment <- function(a, x, xChange, c){ | |
| lin.segment <- a*(abs(x - xChange) - (x + xChange)) + c | |
| return(lin.segment) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # stock sol vol 2 | |
| # stock_sol_conc is the concentration of the stock solution - current OD | |
| # new_sol_conc is the concentration of the new solution - the desired OD | |
| # diluent vol is the volume of the diluent you want to use (i.e. the amount of water/M9) | |
| stock_sol_vol2 <- function (stock_sol_conc, new_sol_conc, diluent_vol) | |
| { | |
| return((new_sol_conc * diluent_vol)/(stock_sol_conc - new_sol_conc)) | |
| } |