Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. Error in UseMethod("predict") :
  2. no applicable method for 'predict' applied to an object of class "character"
  3. In addition: Warning messages:
  4. 1: In `[<-.factor`(`*tmp*`, n, value = "A1") :
  5. invalid factor level, NA generated
  6. 2: In `[<-.factor`(`*tmp*`, n, value = "A2") :
  7. invalid factor level, NA generated
  8. 3: In `[<-.factor`(`*tmp*`, n, value = "A3") :
  9. invalid factor level, NA generated
  10. 4: In min(data_n[data_n > 0]) :
  11. no non-missing arguments to min; returning Inf
  12. 5: In `[<-.factor`(`*tmp*`, n, value = "A4") :
  13. invalid factor level, NA generated
  14.  
  15. library(growthcurver)
  16. d <- growthdata
  17. file<-"C:/Users/bedro/Downloads/growth curve.csv"
  18. d <- read.table(file, sep=",", header=TRUE, stringsAsFactors=FALSE)
  19. #d$time <- d$time / 60
  20. num_analyses <- length(names(d)) - 1
  21. 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)
  22. par(mfcol = c(8,12))
  23. par(mar = c(0.25,0.25,0.25,0.25))
  24. trim_at_time <- 10
  25. y_lim_max <- max(d[,setdiff(names(d), "time")]) - min(d[,setdiff(names(d), "time")])
  26. n <- 1
  27. pdf("C:/Desktop/Users/bedro/Desktop/growthcurverplot2.pdf", height = 8.5, width = 11)
  28. par(mfcol = c(8,12))
  29. par(mar = c(0.25,0.25,0.25,0.25))
  30. y_lim_max <- max(d[,setdiff(names(d), "time")]) - min(d[,setdiff(names(d), "time")])
  31. n <- 1 # keeps track of the current row in the output data frame
  32. for (col_name in names(d)) {
  33. # Don't process the column called "time".
  34. # It contains time and not absorbance data.
  35. if (col_name != "time") {
  36.  
  37. # Create a temporary data frame that contains just the time and current col
  38. d_loop <- d[, c("time", col_name)]
  39.  
  40. # Do the background correction.
  41. # Background correction option 1: subtract the minimum value in a column
  42. # from all measurements in that column
  43. min_value <- min(d_loop[, col_name])
  44. d_loop[, col_name] <- d_loop[, col_name] - min_value
  45. # Background correction option 2: subtract the mean value of blank wells
  46. # over the course the experiment
  47. # (Replace B2, D8, G11 with the column
  48. # names of your media-only wells)
  49. #d$blank <- apply(d[, c("B2", "D8", "G11")], 1, mean)
  50. #d$A1 <- d$A1 - d$blank
  51.  
  52. # Now, call Growthcurver to calculate the metrics using SummarizeGrowth
  53. gc_fit <- SummarizeGrowth(data_t = d_loop[, "time"],
  54. data_n = d_loop[, col_name],
  55. t_trim = trim_at_time,
  56. bg_correct = "none")
  57.  
  58. # Now, add the metrics from this column to the next row (n) in the
  59. # output data frame, and increment the row counter (n)
  60. d_gc$sample[n] <- col_name
  61. d_gc[n, 2:9] <- c(gc_fit$vals$k,
  62. gc_fit$vals$n0,
  63. gc_fit$vals$r,
  64. gc_fit$vals$t_mid,
  65. gc_fit$vals$t_gen,
  66. gc_fit$vals$auc_l,
  67. gc_fit$vals$auc_e,
  68. gc_fit$vals$sigma)
  69. n <- n + 1
  70.  
  71. # Finally, plot the raw data and the fitted curve
  72. # Here, I'll just print some of the data points to keep the file size smaller
  73. n_obs <- length(gc_fit$data$t)
  74. idx_to_plot <- 1:20 / 20 * n_obs
  75. plot(gc_fit$data$t[idx_to_plot], gc_fit$data$N[idx_to_plot],
  76. pch = 20,
  77. xlim = c(0, trim_at_time),
  78. ylim = c(0, y_lim_max),
  79. cex = 0.6, xaxt = "n", yaxt = "n")
  80. text(x = trim_at_time / 4, y = y_lim_max, labels = col_name, pos = 1)
  81.  
  82. lines(gc_fit$data$t, predict(gc_fit$model), col = "red")
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement