names(concs) <- concs <- c("CTRL",paste0(c(0.01,0.1,1,10,100),"X"))
e <- bind_rows(lapply(concs, FUN=function(x){
x <- read_excel("Data/DoseResponse/zebrafish.xlsx", sheet=x)
x$Time <- as.numeric(gsub(" min","",x$Time))
x$Light <- rep(rep(factor(c("dark","light"), c("light","dark")), each=5),nrow(x)/10)
reshape2::melt(x[,-2], id.vars=c("Time","Light"), variable.name="Tadpole", value.name="Movement")
}), .id="Concentration")
e$Tadpole <- as.factor(paste(e$Concentration,e$Tadpole))
e$Concentration <- relevel(factor(e$Concentration, unique(e$Concentration)), "CTRL")
# sanity check
ag <- aggregate(x=e$Movement, by=e[,c("Time","Concentration")], FUN=mean)
ggplot(ag, aes(Time, x, colour=Concentration)) + geom_line() + labs(x="Time (min)", y="Movement")
Mixed linear models
mod <- lmer(Movement~(1|Tadpole)+Time+Light*Concentration, data=e)
co <- as.data.frame(coef(summary(mod)))[-1:-3,]
co$FDR <- p.adjust(co[,5])
colnames(co)[2] <- "StdErr"
co$coef <- factor(row.names(co), unique(row.names(co)))
levels(co$coef) <- gsub("Concentration","",levels(co$coef))
levels(co$coef) <- gsub("Lightdark:","Dark+",levels(co$coef))
ggplot(co, aes(Estimate, coef, colour=-log10(FDR))) +
geom_vline(xintercept=0, linetype="dashed") + geom_point(size=3) +
geom_segment(aes(x=Estimate-StdErr, xend=Estimate+StdErr, y=coef, yend=coef), size=1.3) +
geom_text(label=ifelse(co$FDR<0.05,"*",""), size=10, aes(x=Estimate+StdErr+0.025)) +
labs(x="Change in movement", y="Coefficient")

co1 <- dround(co[,c(7,1,2,5,6)])
row.names(co1) <- NULL
co1
## coef Estimate StdErr Pr(>|t|) FDR
## 1 0.01X -0.0137 0.0591 8.16e-01 1.00e+00
## 2 0.1X 0.0838 0.0578 1.48e-01 7.39e-01
## 3 1X 0.0402 0.0582 4.90e-01 1.00e+00
## 4 10X 0.0339 0.0574 5.55e-01 1.00e+00
## 5 100X 0.1790 0.0574 1.91e-03 1.34e-02
## 6 Dark+0.01X -0.0383 0.0275 1.64e-01 7.39e-01
## 7 Dark+0.1X 0.0431 0.0269 1.09e-01 6.52e-01
## 8 Dark+1X 0.0966 0.0271 3.62e-04 2.90e-03
## 9 Dark+10X 0.1350 0.0267 4.46e-07 4.02e-06
## 10 Dark+100X 0.8120 0.0267 1.54e-197 1.54e-196
co2 <- co[,c("Estimate","StdErr")]
co2$cycle <- ifelse(grepl("Light",row.names(co2)),"Light","Dark")
co2$Conc2 <- gsub("Concentration","",gsub("Lightdark:","",row.names(co2),fixed=TRUE))
co2 <- rbind(data.frame(Estimate=c(0,0),StdErr=c(0,0),cycle=c("Light","Dark"),Conc2="CTRL"),co2)
co2$Conc2 <- factor(co2$Conc2, unique(co2$Conc2))
ggplot(co2, aes(as.integer(Conc2), Estimate, colour=cycle)) +
geom_hline(yintercept=0, linetype="dashed") + geom_point() +
geom_segment(aes(y=Estimate-StdErr,yend=Estimate+StdErr,xend=as.integer(Conc2))) +
geom_smooth(method="loess", span=1, level=0.9) +
scale_x_continuous(breaks=1:6, labels=levels(co2$Conc2)) +
labs(x="Concentration", y="Change in movement")
## `geom_smooth()` using formula 'y ~ x'

Authors
Nicolò Caporale: nicolo.caporale@ieo.it, nicolo.caporale@unimi.it
Cristina Cheroni: cristina.cheroni@ieo.it
Pierre-Luc Germain: pierre-luc.germain@ieo.it
Giuseppe Testa: giuseppe.testa@ieo.it
Lab: http://www.testalab.eu/
‘Date: December 01, 2021’
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur 10.16
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] parallel stats4 stats graphics grDevices utils datasets
## [8] methods base
##
## other attached packages:
## [1] readxl_1.3.1 lmerTest_3.1-3
## [3] lme4_1.1-26 Matrix_1.3-2
## [5] sva_3.38.0 BiocParallel_1.24.1
## [7] genefilter_1.72.1 mgcv_1.8-34
## [9] nlme_3.1-152 dplyr_1.0.5
## [11] plotly_4.9.3 ggplot2_3.3.3
## [13] pheatmap_1.0.12 DT_0.17
## [15] edgeR_3.32.1 limma_3.46.0
## [17] SEtools_1.4.0 SummarizedExperiment_1.20.0
## [19] Biobase_2.50.0 GenomicRanges_1.42.0
## [21] GenomeInfoDb_1.26.2 IRanges_2.24.1
## [23] S4Vectors_0.28.1 BiocGenerics_0.36.0
## [25] MatrixGenerics_1.2.1 matrixStats_0.58.0
##
## loaded via a namespace (and not attached):
## [1] minqa_1.2.4 Rtsne_0.15 colorspace_2.0-0
## [4] rjson_0.2.20 ellipsis_0.3.1 circlize_0.4.12
## [7] XVector_0.30.0 GlobalOptions_0.1.2 clue_0.3-58
## [10] farver_2.1.0 bit64_4.0.5 AnnotationDbi_1.52.0
## [13] fansi_0.4.2 codetools_0.2-18 splines_4.0.3
## [16] cachem_1.0.4 knitr_1.31 jsonlite_1.7.2
## [19] nloptr_1.2.2.2 Cairo_1.5-12.2 annotate_1.68.0
## [22] cluster_2.1.1 png_0.1-7 compiler_4.0.3
## [25] httr_1.4.2 assertthat_0.2.1 fastmap_1.1.0
## [28] lazyeval_0.2.2 htmltools_0.5.1.1 tools_4.0.3
## [31] gtable_0.3.0 glue_1.4.2 GenomeInfoDbData_1.2.4
## [34] reshape2_1.4.4 V8_3.4.0 Rcpp_1.0.6
## [37] cellranger_1.1.0 jquerylib_0.1.3 vctrs_0.3.7
## [40] iterators_1.0.13 xfun_0.21 stringr_1.4.0
## [43] openxlsx_4.2.3 lifecycle_1.0.0 statmod_1.4.35
## [46] XML_3.99-0.5 MASS_7.3-53.1 zlibbioc_1.36.0
## [49] scales_1.1.1 TSP_1.1-10 RColorBrewer_1.1-2
## [52] ComplexHeatmap_2.6.2 yaml_2.2.1 curl_4.3
## [55] memoise_2.0.0 sass_0.3.1 stringi_1.5.3
## [58] RSQLite_2.2.3 highr_0.8 randomcoloR_1.1.0.1
## [61] foreach_1.5.1 seriation_1.2-9 boot_1.3-27
## [64] zip_2.1.1 shape_1.4.5 rlang_0.4.10
## [67] pkgconfig_2.0.3 bitops_1.0-6 evaluate_0.14
## [70] lattice_0.20-41 purrr_0.3.4 labeling_0.4.2
## [73] htmlwidgets_1.5.3 bit_4.0.4 tidyselect_1.1.0
## [76] plyr_1.8.6 magrittr_2.0.1 R6_2.5.0
## [79] generics_0.1.0 DelayedArray_0.16.1 DBI_1.1.1
## [82] pillar_1.5.1 withr_2.4.1 survival_3.2-7
## [85] RCurl_1.98-1.2 tibble_3.1.0 crayon_1.4.1
## [88] utf8_1.2.1 rmarkdown_2.7 GetoptLong_1.0.5
## [91] locfit_1.5-9.4 grid_4.0.3 data.table_1.14.0
## [94] blob_1.2.1 digest_0.6.27 xtable_1.8-4
## [97] numDeriv_2016.8-1.1 tidyr_1.1.3 munsell_0.5.0
## [100] registry_0.5-1 viridisLite_0.3.0 bslib_0.2.4