Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error in UseMethod("predict") :
- no applicable method for 'predict' applied to an object of class "character"
- In addition: Warning messages:
- 1: In `[<-.factor`(`*tmp*`, n, value = "A1") :
- invalid factor level, NA generated
- 2: In `[<-.factor`(`*tmp*`, n, value = "A2") :
- invalid factor level, NA generated
- 3: In `[<-.factor`(`*tmp*`, n, value = "A3") :
- invalid factor level, NA generated
- 4: In min(data_n[data_n > 0]) :
- no non-missing arguments to min; returning Inf
- 5: In `[<-.factor`(`*tmp*`, n, value = "A4") :
- invalid factor level, NA generated
- library(growthcurver)
- d <- growthdata
- file<-"C:/Users/bedro/Downloads/growth curve.csv"
- d <- read.table(file, sep=",", header=TRUE, stringsAsFactors=FALSE)
- #d$time <- d$time / 60
- num_analyses <- length(names(d)) - 1
- d_gc <- data.frame(sample = character(num_analyses),k = numeric(num_analyses),n0 = numeric(num_analyses),r = numeric(num_analyses),t_mid = numeric(num_analyses),t_gen = numeric(num_analyses),auc_l = numeric(num_analyses),auc_e = numeric(num_analyses), sigma = numeric(num_analyses),tringsAsFactors = FALSE)
- par(mfcol = c(8,12))
- par(mar = c(0.25,0.25,0.25,0.25))
- trim_at_time <- 10
- y_lim_max <- max(d[,setdiff(names(d), "time")]) - min(d[,setdiff(names(d), "time")])
- n <- 1
- pdf("C:/Desktop/Users/bedro/Desktop/growthcurverplot2.pdf", height = 8.5, width = 11)
- par(mfcol = c(8,12))
- par(mar = c(0.25,0.25,0.25,0.25))
- y_lim_max <- max(d[,setdiff(names(d), "time")]) - min(d[,setdiff(names(d), "time")])
- n <- 1 # keeps track of the current row in the output data frame
- for (col_name in names(d)) {
- # Don't process the column called "time".
- # It contains time and not absorbance data.
- if (col_name != "time") {
- # Create a temporary data frame that contains just the time and current col
- d_loop <- d[, c("time", col_name)]
- # Do the background correction.
- # Background correction option 1: subtract the minimum value in a column
- # from all measurements in that column
- min_value <- min(d_loop[, col_name])
- d_loop[, col_name] <- d_loop[, col_name] - min_value
- # Background correction option 2: subtract the mean value of blank wells
- # over the course the experiment
- # (Replace B2, D8, G11 with the column
- # names of your media-only wells)
- #d$blank <- apply(d[, c("B2", "D8", "G11")], 1, mean)
- #d$A1 <- d$A1 - d$blank
- # Now, call Growthcurver to calculate the metrics using SummarizeGrowth
- gc_fit <- SummarizeGrowth(data_t = d_loop[, "time"],
- data_n = d_loop[, col_name],
- t_trim = trim_at_time,
- bg_correct = "none")
- # Now, add the metrics from this column to the next row (n) in the
- # output data frame, and increment the row counter (n)
- d_gc$sample[n] <- col_name
- d_gc[n, 2:9] <- c(gc_fit$vals$k,
- gc_fit$vals$n0,
- gc_fit$vals$r,
- gc_fit$vals$t_mid,
- gc_fit$vals$t_gen,
- gc_fit$vals$auc_l,
- gc_fit$vals$auc_e,
- gc_fit$vals$sigma)
- n <- n + 1
- # Finally, plot the raw data and the fitted curve
- # Here, I'll just print some of the data points to keep the file size smaller
- n_obs <- length(gc_fit$data$t)
- idx_to_plot <- 1:20 / 20 * n_obs
- plot(gc_fit$data$t[idx_to_plot], gc_fit$data$N[idx_to_plot],
- pch = 20,
- xlim = c(0, trim_at_time),
- ylim = c(0, y_lim_max),
- cex = 0.6, xaxt = "n", yaxt = "n")
- text(x = trim_at_time / 4, y = y_lim_max, labels = col_name, pos = 1)
- lines(gc_fit$data$t, predict(gc_fit$model), col = "red")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement