annotate mixmodel_script.R @ 0:a4d89d47646f draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
author workflow4metabolomics
date Mon, 16 May 2022 09:25:01 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
1 ####### R functions to perform linear mixed model for repeated measures
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
2 ####### on a multi var dataset using 3 files as used in W4M
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
3 ##############################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
4 lmRepeated2FF <- function(ids, ifixfact, itime, isubject, ivd, ndim, nameVar=colnames(ids)[[ivd]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
5 pvalCutof = 0.05, dffOption, visu = visu, tit = "", least.confounded = FALSE, outlier.limit = 3) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
6 ### function to perform linear mixed model with 1 Fixed factor + Time + random factor subject
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
7 ### based on lmerTest package providing functions giving the same results as SAS proc mixed
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
8 options(scipen = 50, digits = 5)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
9
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
10 if (!is.numeric(ids[[ivd]])) stop("Dependant variable is not numeric")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
11 if (!is.factor(ids[[ifixfact]])) stop("fixed factor is not a factor")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
12 if (!is.factor(ids[[itime]])) stop("Repeated factor is not a factor")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
13 if (!is.factor(ids[[isubject]])) stop("Random factor is not a factor")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
14
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
15 ## factors
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
16 time <- ids[[itime]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
17 fixfact <- ids[[ifixfact]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
18 subject <- ids[[isubject]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
19 # dependant variables
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
20 vd <- ids[[ivd]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
21
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
22 # argument of the function instead of re re-running ndim <- defColRes(ids, ifixfact, itime)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
23 # nfp : number of main factors + model infos (REML, varSubject) + normality test
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
24 nfp <- ndim[1];
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
25 # ncff number of comparison of the fixed factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
26 nlff <- ndim[2]; ncff <- ndim[3]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
27 # nct number of comparison of the time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
28 nlt <- ndim[4]; nct <- ndim[5]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
29 # nci number of comparison of the interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
30 nli <- ndim[6]; nci <- ndim[7]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
31 # number of all lmer results
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
32 nresT <- ncff + nct + nci
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
33 ## initialization of the result vector (1 line)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
34 ## 4 * because nresf for : pvalues + Etimates + lower CI + Upper CI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
35 res <- data.frame(array(rep(NA, (nfp + 4 * nresT))))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
36 colnames(res)[1] <- "resultLM"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
37
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
38 ### if at least one subject have data for only 1 time, mixed model is not possible and variable must be skip
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
39 ### after excluding NA, table function is used to seek subjects with only 1 data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
40 ids <- ids[!is.na(ids[[ivd]]), ]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
41 skip <- length(which(table(ids[[isubject]]) == 1))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
42
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
43 if (skip == 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
44
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
45 mfl <- lmer(vd ~ time + fixfact + time:fixfact + (1 | subject), ids) # lmer remix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
46
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
47 rsum <- summary(mfl, ddf = dffOption)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
48 ## test Shapiro Wilks on the residus of the model
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
49 rShapiro <- shapiro.test(rsum$residuals)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
50 raov <- anova(mfl, ddf = dffOption)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
51 dlsm1 <- data.frame(difflsmeans(mfl, test.effs = NULL))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
52 ddlsm1 <- dlsm1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
53 ## save rownames and factor names
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
54 rn <- rownames(ddlsm1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
55 fn <- ddlsm1[, c(1, 2)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
56 ## writing the results on a single line
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
57 namesFactEstim <- paste("estimate ", rownames(ddlsm1)[c(1:(nct + ncff))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
58 namesFactPval <- paste("pvalue ", rownames(ddlsm1)[c(1:(nct + ncff))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
59 namesInter <- rownames(ddlsm1)[-c(1:(nct + ncff))]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
60 namesEstimate <- paste("estimate ", namesInter)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
61 namespvalues <- paste("pvalue ", namesInter)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
62 namesFactprinc <- c("pval_time", "pval_trt", "pval_inter")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
63 namesFactEstim <- paste("estimate ", rownames(ddlsm1)[c(1:(nct + ncff))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
64
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
65 namesFactLowerCI <- paste("lowerCI ", rownames(ddlsm1)[c(1:(nct + ncff))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
66 namesLowerCI <- paste("lowerCI ", namesInter, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
67
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
68 namesFactUpperCI <- paste("UpperCI ", rownames(ddlsm1)[c(1:(nct + ncff))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
69 namesUpperCI <- paste("UpperCI ", namesInter, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
70
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
71
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
72 ### lmer results on 1 vector row
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
73 # pvalue of shapiro Wilks test of the residuals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
74 res[1, ] <- rShapiro$p.value; rownames(res)[1] <- "Shapiro.pvalue.residuals"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
75 res[2, ] <- rsum$varcor$subject[1] ;rownames(res)[2] <- "Subject.Variance"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
76 res[3, ] <- rsum$devcomp$cmp[7] ; rownames(res)[3] <- "REML"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
77 ### 3 principal factors pvalues results + shapiro test => nfp <- 4
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
78 res[c((nfp - 2):nfp), ] <- raov[, 6]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
79 rownames(res)[c((nfp - 2):nfp)] <- namesFactprinc
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
80
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
81 #################### Residuals diagnostics for significants variables #########################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
82 ### Il at least 1 factor is significant and visu=TRUE NL graphics add to pdf
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
83 ## ajout JF du passage de la valeur de p-value cutoff
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
84 if (length(which(raov[, 6] <= pvalCutof)) > 0 & visu == "yes") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
85 diagmflF(mfl, title = tit, pvalCutof = pvalCutof, least.confounded = least.confounded,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
86 outlier.limit = outlier.limit)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
87 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
88
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
89 # pvalue of fixed factor comparisons
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
90 nresf <- nresT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
91 res[(nfp + 1):(nfp + nct), ] <- ddlsm1[c(1:nct), 9]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
92 res[(nfp + nct + 1):(nfp + nct + ncff), ] <- ddlsm1[(nct + 1):(nct + ncff), 9]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
93 rownames(res)[(nfp + 1):(nfp + nct + ncff)] <- namesFactPval
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
94 res[(nfp + nct + ncff + 1):(nfp + nresf), ] <- ddlsm1[(nct + ncff + 1):(nresT), 9]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
95 rownames(res)[(nfp + nct + ncff + 1):(nfp + nresT)] <- namespvalues
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
96 # Estimate of the difference between levels of factors
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
97 res[(nfp + nresf + 1):(nfp + nresf + nct), ] <- ddlsm1[c(1:nct), 3]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
98 res[(nfp + nresf + nct + 1):(nfp + nresf + nct + ncff), ] <- ddlsm1[(nct + 1):(nct + ncff), 3]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
99 rownames(res)[(nfp + nresf + 1):(nfp + nresf + nct + ncff)] <- namesFactEstim
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
100 res[(nfp + nresf + nct + ncff + 1):(nfp + 2 * nresf), ] <- ddlsm1[(nct + ncff + 1):(nresT), 3]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
101 rownames(res)[(nfp + nresf + nct + ncff + 1):(nfp + 2 * nresf)] <- namesEstimate
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
102 # lower CI of the difference between levels of factors
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
103 nresf <- nresf + nresT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
104 res[(nfp + nresf + 1):(nfp + nresf + nct), ] <- ddlsm1[c(1:nct), 7]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
105 res[(nfp + nresf + nct + 1):(nfp + nresf + nct + ncff), ] <- ddlsm1[(nct + 1):(nct + ncff), 7]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
106 rownames(res)[(nfp + nresf + 1):(nfp + nresf + nct + ncff)] <- namesFactLowerCI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
107 res[(nfp + nresf + nct + ncff + 1):(nfp + 2 * nresf), ] <- ddlsm1[(nct + ncff + 1):(nresf), 7]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
108 rownames(res)[(nfp + nresf + nct + ncff + 1):(nfp + nresf + (nresf / 2))] <- namesLowerCI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
109 # Upper CI of the difference between levels of factors
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
110 nresf <- nresf + nresT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
111 res[(nfp + nresf + 1):(nfp + nresf + nct), ] <- ddlsm1[c(1:nct), 8]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
112 res[(nfp + nresf + nct + 1):(nfp + nresf + nct + ncff), ] <- ddlsm1[(nct + 1):(nct + ncff), 8]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
113 rownames(res)[(nfp + nresf + 1):(nfp + nresf + nct + ncff)] <- namesFactUpperCI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
114 res[(nfp + nresf + nct + ncff + 1):(nfp + nresf + (nresT)), ] <- ddlsm1[(nct + ncff + 1):(nresT), 8]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
115 rownames(res)[(nfp + nresf + nct + ncff + 1):(nfp + nresf + (nresT))] <- namesUpperCI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
116
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
117 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
118 ## one of the subject has only one time, subject can't be a random variable
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
119 ## A repeated measure could be run instead function lme of package nlme, in next version?
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
120 res[1, ] <- NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
121 cat("\n Computing impossible for feature ", tit, ": at least one subject has only one time.\n")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
122 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
123 tres <- data.frame(t(res))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
124 rownames(tres)[1] <- nameVar
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
125 cres <- list(tres, rn, fn)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
126 return(cres)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
127 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
128
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
129 ##############################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
130 lmRepeated1FF <- function(ids, ifixfact = 0, itime, isubject, ivd, ndim, nameVar = colnames(ids)[[ivd]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
131 dffOption, pvalCutof = 0.05) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
132 ### function to perform linear mixed model with factor Time + random factor subject
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
133 ### based on lmerTest package providing functions giving the same results as SAS proc mixed
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
134
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
135
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
136 if (!is.numeric(ids[[ivd]])) stop("Dependant variable is not numeric")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
137 if (!is.factor(ids[[itime]])) stop("Repeated factor is not a factor")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
138 if (!is.factor(ids[[isubject]])) stop("Random factor is not a factor")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
139 # Could be interesting here to add an experience plan check to give back a specific error message
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
140 # in case time points are missing for some individuals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
141
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
142 time <- ids[[itime]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
143 subject <- ids[[isubject]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
144 vd <- ids[[ivd]] ## dependant variables (quatitative)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
145
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
146 # nfp : nombre de facteurs principaux + model infos + normality test
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
147 nfp <- ndim[1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
148 # nlt number of time levels; nct number of comparisons of the time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
149 nlt <- ndim[4]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
150 nct <- ndim[5]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
151 # number of all lmer results
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
152 nresT <- nct
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
153 ## initialization of the result vector (1 line)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
154 res <- data.frame(array(rep(NA, (nfp + 4 * nresT))))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
155 colnames(res)[1] <- "resultLM"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
156
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
157 ### if at least one subject have data for only 1 time, mixed model is not possible and variable must be skip
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
158 ### after excluding NA, table function is used to seek subjects with only 1 data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
159 ids <- ids[!is.na(ids[[ivd]]), ]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
160 skip <- length(which(table(ids[[isubject]]) == 1))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
161
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
162 if (skip == 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
163
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
164 mfl <- lmer(vd ~ time + (1 | subject), ids) # lmer remix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
165 rsum <- summary(mfl, ddf = dffOption)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
166 ## test Shapiro Wilks on the residus of the model
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
167 rShapiro <- shapiro.test(rsum$residuals)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
168 raov <- anova(mfl, ddf = dffOption)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
169 ## Sum of square : aov$'Sum Sq', Mean square : aov$`Mean Sq`, proba : aov$`Pr(>F)`
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
170
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
171 ## Test of all differences estimates between levels as SAS proc mixed.
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
172 ## results are in diffs.lsmeans.table dataframe
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
173 ## test.effs=NULL perform all pairs comparisons including interaction effect
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
174 dlsm1 <- data.frame(difflsmeans(mfl, test.effs = NULL))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
175 ddlsm1 <- dlsm1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
176 ## save rownames and factor names
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
177 rn <- rownames(ddlsm1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
178 fn <- ddlsm1[, c(1, 2)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
179 ## writing the results on a single line
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
180 namesFactEstim <- paste("estimate ", rownames(ddlsm1)[c(1:(nct))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
181 namesFactPval <- paste("pvalue ", rownames(ddlsm1)[c(1:(nct))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
182 namesFactprinc <- "pval_time"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
183 namesLowerCI <- paste("lowerCI ", rownames(ddlsm1)[c(1:(nct))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
184 namesUpperCI <- paste("upperCI ", rownames(ddlsm1)[c(1:(nct))], sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
185
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
186 ### lmer results on 1 vector
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
187 # pvalue of shapiro Wilks test of the residuals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
188 res[1, ] <- rShapiro$p.value; rownames(res)[1] <- "Shapiro.pvalue.residuals"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
189 res[2, ] <- rsum$varcor$subject[1] ;rownames(res)[2] <- "Subject.Variance"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
190 res[3, ] <- rsum$devcomp$cmp[7] ; rownames(res)[3] <- "REML"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
191
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
192 ### factor time pvalue results + shapiro test
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
193 res[nfp, ] <- raov[, 6]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
194 rownames(res)[nfp] <- namesFactprinc
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
195
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
196 # pvalues of time factor levels comparisons
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
197 res[(nfp + 1):(nfp + nct), ] <- ddlsm1[c(1:nct), 9]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
198 rownames(res)[(nfp + 1):(nfp + nct)] <- namesFactPval
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
199
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
200 # Estimates of time factor levels
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
201 nresf <- nresT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
202 res[(nfp + nresf + 1):(nfp + nresf + nct), ] <- ddlsm1[c(1:nct), 3]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
203 rownames(res)[(nfp + nresf + 1):(nfp + nresf + nct)] <- namesFactEstim
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
204
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
205 # Lower CI of the difference between levels of factors
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
206 # nresf is incremeted
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
207 nresf <- nresf + nresT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
208 res[(nfp + nresf + 1):(nfp + nresf + nct), ] <- ddlsm1[c(1:nct), 7]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
209 rownames(res)[(nfp + nresf + 1):(nfp + nresf + nct)] <- namesLowerCI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
210 # Lower CI of the difference between levels of factors
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
211 # nresf is incremeted
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
212 nresf <- nresf + nresT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
213 res[(nfp + nresf + 1):(nfp + nresf + nct), ] <- ddlsm1[c(1:nct), 8]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
214 rownames(res)[(nfp + nresf + 1):(nfp + nresf + nct)] <- namesUpperCI
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
215
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
216
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
217 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
218 ## one of the subject has only one time, subject can't be a random variable
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
219 ## A repeated measure could be run instead function lme of package nlme, next version
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
220 res[1, ] <- NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
221 cat("\n Computing impossible for feature ", colnames(ids)[4], ": at least one subject has only one time.\n")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
222 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
223 tres <- data.frame(t(res))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
224 rownames(tres)[1] <- nameVar
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
225 cres <- list(tres, rn, fn)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
226 return(cres)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
227
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
228 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
229
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
230 ##############################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
231 defColRes <- function(ids, ifixfact, itime) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
232 ## define the size of the result file depending on the numbers of levels of the fixed and time factor.
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
233 ## Numbers of levels define the numbers of comparisons with pvalue and estimate of the difference.
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
234 ## The result file also contains the pvalue of the fixed factor, time factor and interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
235 ## plus Shapiro normality test. This is define by nfp
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
236 ## subscript of fixed factor=0 means no other fixed factor than "time"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
237 if (ifixfact > 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
238 nfp <- 6 # shapiro + subject variance + REML + time + fixfact + interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
239 time <- ids[[itime]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
240 fixfact <- ids[[ifixfact]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
241
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
242 cat("\n Levels fixfact: ", levels(fixfact))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
243 cat("\n Levels time: ", levels(time))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
244
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
245 # ncff number of comparisons of the fixed factor (nlff number of levels of fixed factor)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
246 nlff <- length(levels(fixfact))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
247 ncff <- (nlff * (nlff - 1)) / 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
248 # nct number of comparison of the time factor (nlt number of levels of time factor)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
249 nlt <- length(levels(time))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
250 nct <- (nlt * (nlt - 1)) / 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
251 # nci number of comparison of the interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
252 nli <- nlff * nlt
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
253 nci <- (nli * (nli - 1)) / 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
254 ndim <- c(NA, NA, NA, NA, NA, NA, NA)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
255
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
256 ndim[1] <- nfp # pvalues of fixed factor, time factor and interaction (3columns) and shapiro test pvalue
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
257 ndim[2] <- nlff # number of levels of fixed factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
258 ndim[3] <- ncff # number of comparisons (2by2) of the fixed factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
259 ndim[4] <- nlt # number of levels of time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
260 ndim[5] <- nct # number of comparisons (2by2) of the time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
261 ndim[6] <- nli # number of levels of interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
262 ndim[7] <- nci # number of comparisons (2by2) of the interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
263
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
264 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
265 else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
266 nfp <- 4 # Mandatory columns: shapiro + subject variance + REML + time
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
267 time <- ids[[itime]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
268 # nct number of comparison of the time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
269 nlt <- length(levels(time))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
270 nct <- (nlt * (nlt - 1)) / 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
271 ndim <- c(NA, NA, NA, NA, NA, NA, NA)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
272
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
273 ndim[1] <- nfp # pvalues of shapiro test + subject variance + REML + time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
274 ndim[4] <- nlt # number of levels of time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
275 ndim[5] <- nct # number of comparisons (2by2) of the time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
276 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
277 return(ndim)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
278 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
279
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
280 ##############################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
281 lmixedm <- function(datMN,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
282 samDF,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
283 varDF,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
284 fixfact, time, subject,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
285 logtr = "none",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
286 pvalCutof = 0.05,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
287 pvalcorMeth = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none")[7],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
288 dffOption,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
289 visu = "no",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
290 least.confounded = FALSE,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
291 outlier.limit = 3,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
292 pdfC,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
293 pdfE
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
294 ) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
295 sampids <- samDF
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
296 dataMatrix <- datMN
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
297 varids <- varDF
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
298
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
299 options("scipen" = 50, "digits" = 5)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
300 pvalCutof <- as.numeric(pvalCutof)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
301
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
302 cat("\n dff computation method=", dffOption)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
303 ### Function running lmer function on a set of variables described in
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
304 ### 3 different dataframes as used by W4M
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
305 ### results are merge with the metadata variables varids
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
306 ### ifixfact, itime, isubject are subscripts of the dependant variables. if only time factor the ifixfat is set to 0 and no diag is performed (visu="no")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
307 if (fixfact == "none") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
308 ifixfact <- 0 ; visu <- "no"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
309 } else ifixfact <- which(colnames(sampids) == fixfact)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
310 itime <- which(colnames(sampids) == time)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
311 isubject <- which(colnames(sampids) == subject)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
312
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
313 lmmds <- dataMatrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
314 if (logtr != "log10" & logtr != "log2") logtr <- "none"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
315 if (logtr == "log10") lmmds <- log10(lmmds + 1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
316 if (logtr == "log2") lmmds <- log2(lmmds + 1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
317
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
318 dslm <- cbind(sampids, lmmds)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
319
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
320 nvar <- ncol(lmmds)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
321 firstvar <- ncol(sampids) + 1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
322 lastvar <- firstvar + ncol(lmmds) - 1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
323
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
324 if (ifixfact > 0) dslm[[ifixfact]] <- factor(dslm[[ifixfact]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
325 dslm[[itime]] <- factor(dslm[[itime]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
326 dslm[[isubject]] <- factor(dslm[[isubject]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
327 ## call defColres to define the numbers of test and so the number of columns of results
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
328 ## depends on whether or not there is a fixed factor with time. If only time factor ifixfact=0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
329 if (ifixfact > 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
330 ndim <- defColRes(dslm[, c(ifixfact, itime)], ifixfact = 1, itime = 2)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
331 nColRes <- ndim[1] + (4 * (ndim[3] + ndim[5] + ndim[7]))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
332 firstpval <- ndim[1] - 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
333 lastpval <- ndim[1] + ndim[3] + ndim[5] + ndim[7]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
334 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
335 ndim <- defColRes(dslm[, itime], ifixfact = 0, itime = 1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
336 nColRes <- ndim[1] + (4 * (ndim[5]))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
337 firstpval <- ndim[1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
338 lastpval <- ndim[1] + ndim[5]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
339 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
340 ## initialisation of the result file
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
341 resLM <- data.frame(array(rep(NA, nvar * nColRes), dim = c(nvar, nColRes)))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
342 rownames(resLM) <- rownames(varids)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
343
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
344 ## PDF initialisation
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
345 if (visu == "yes") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
346 pdf(pdfC, onefile = TRUE, height = 15, width = 30)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
347 par(mfrow = c(1, 3))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
348 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
349
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
350
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
351 for (i in firstvar:lastvar) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
352
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
353 subds <- dslm[, c(ifixfact, itime, isubject, i)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
354
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
355 tryCatch({
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
356 if (ifixfact > 0)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
357 reslmer <- lmRepeated2FF(subds, ifixfact = 1, itime = 2, isubject = 3, ivd = 4, ndim = ndim, visu = visu,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
358 tit = colnames(dslm)[i], pvalCutof = pvalCutof,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
359 dffOption = dffOption, least.confounded = least.confounded,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
360 outlier.limit = outlier.limit)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
361 else
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
362 reslmer <- lmRepeated1FF(subds, ifixfact = 0, itime = 1, isubject = 2, ivd = 3, ndim = ndim,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
363 pvalCutof = pvalCutof, dffOption = dffOption)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
364
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
365 resLM[i - firstvar + 1, ] <- reslmer[[1]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
366 }, error = function(e) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
367 cat("\nERROR with ", rownames(resLM)[i - firstvar + 1], ": ", conditionMessage(e), "\n")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
368 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
369 )
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
370
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
371 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
372
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
373 if (exists("reslmer")) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
374 colnames(resLM) <- colnames(reslmer[[1]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
375 labelRow <- reslmer[[2]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
376 factorRow <- reslmer[[3]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
377 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
378 stop("\n- - - - -\nModel computation impossible for every single variables in the dataset: no result returned.\n- - - - -\n")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
379 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
380
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
381 if (visu == "yes") dev.off()
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
382
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
383
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
384 ## pvalue correction with p.adjust library multtest
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
385 ## Possible methods of pvalue correction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
386 AdjustMeth <- c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
387 if (length(which(pvalcorMeth == AdjustMeth)) == 0) pvalcorMeth <- "none"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
388
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
389 if (pvalcorMeth != "none") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
390 for (k in firstpval:lastpval) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
391 resLM[[k]] <- p.adjust(resLM[[k]], method = pvalcorMeth, n = dim(resLM[k])[[1]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
392
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
393 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
394 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
395
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
396 ## for each variables, set pvalues to NA and estimates = 0 when pvalue of factor > pvalCutof value define by user
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
397 if (ifixfact > 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
398 ## time effect
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
399 resLM[which(resLM[, firstpval] > pvalCutof), c((lastpval + 1):(lastpval + ndim[5]))] <- 0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
400 resLM[which(resLM[, firstpval] > pvalCutof), c((ndim[1] + 1):(ndim[1] + ndim[5]))] <- NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
401 ## treatment effect
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
402 resLM[which(resLM[, firstpval + 1] > pvalCutof), c((lastpval + ndim[5] + 1):(lastpval + ndim[5] + ndim[3]))] <- 0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
403 resLM[which(resLM[, firstpval + 1] > pvalCutof), c((ndim[1] + ndim[5] + 1):(ndim[1] + ndim[5] + ndim[3]))] <- NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
404 ## interaction effect
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
405 resLM[which(resLM[, firstpval + 2] > pvalCutof), c((lastpval + ndim[5] + ndim[3] + 1):(lastpval + ndim[5] + ndim[3] + ndim[7]))] <- 0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
406 resLM[which(resLM[, firstpval + 2] > pvalCutof), c((ndim[1] + ndim[5] + ndim[3] + 1):(ndim[1] + ndim[5] + ndim[3] + ndim[7]))] <- NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
407 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
408 ## time effect only
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
409 resLM[which(resLM[, firstpval] > pvalCutof), c((lastpval + 1):(lastpval + ndim[5]))] <- 0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
410 resLM[which(resLM[, firstpval] > pvalCutof), c((firstpval + 1):(firstpval + ndim[5]))] <- NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
411 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
412
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
413 ## for each variable, estimates plots are performed if at least one factor is significant after p-value correction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
414 pdf(pdfE, onefile = TRUE, height = 15, width = 30)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
415
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
416 ## for each variable (in row)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
417 for (i in seq_len(nrow(resLM))) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
418
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
419 ## if any fixed factor + time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
420 if (ifixfact > 0)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
421
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
422 ## if any main factor after p-value correction is significant -> plot estimates and time course
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
423 if (length(which(resLM[i, c(4:6)] < pvalCutof)) > 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
424
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
425 ## Plot of time course by fixfact : data prep with factors and quantitative var to be plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
426 subv <- dslm[, colnames(dslm) == rownames(resLM)[i]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
427 subds <- data.frame(dslm[[ifixfact]], dslm[[itime]], dslm[[isubject]], subv)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
428 libvar <- c(fixfact, time, subject)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
429 colnames(subds) <- c(libvar, rownames(resLM)[i])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
430
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
431 ## Plot of estimates with error bars for all fixed factors and interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
432 rddlsm1 <- t(resLM[i, ])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
433 pval <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "pvalue"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
434 esti <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "estima"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
435 loci <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "lowerC"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
436 upci <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "UpperC"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
437 rddlsm1 <- data.frame(pval, esti, loci, upci, factorRow)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
438 colnames(rddlsm1) <- c("p.value", "Estimate", "Lower.CI", "Upper.CI", colnames(factorRow))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
439 rownames(rddlsm1) <- labelRow
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
440
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
441 ## function for plotting these 2 graphs
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
442 plot.res.Lmixed(rddlsm1, subds, title = rownames(resLM)[i], pvalCutof = pvalCutof)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
443
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
444 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
445
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
446 ## if only a time factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
447 if (ifixfact == 0)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
448
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
449 ## if time factor after p-value correction is significant -> plot time course
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
450 if (length(which(resLM[i, 4] < pvalCutof)) > 0) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
451
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
452 ## Plot of time course : data prep with factors and quantitative var to be plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
453 subv <- dslm[, colnames(dslm) == rownames(resLM)[i]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
454 subds <- data.frame(dslm[[itime]], dslm[[isubject]], subv)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
455 libvar <- c(time, subject)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
456 colnames(subds) <- c(libvar, rownames(resLM)[i])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
457
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
458 ## Plot of estimates with error bars for all fixed factors and interaction
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
459 rddlsm1 <- t(resLM[i, ])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
460 pval <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "pvalue"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
461 esti <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "estima"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
462 loci <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "lowerC"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
463 upci <- rddlsm1[substr(rownames(rddlsm1), 1, 6) == "upperC"]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
464 rddlsm1 <- data.frame(pval, esti, loci, upci, factorRow)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
465 colnames(rddlsm1) <- c("p.value", "Estimate", "Lower.CI", "Upper.CI", colnames(factorRow))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
466 rownames(rddlsm1) <- labelRow
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
467
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
468 ## function for plotting these 2 graphs
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
469 plot.res.Lmixed(rddlsm1, subds, title = rownames(resLM)[i], pvalCutof = pvalCutof)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
470
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
471 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
472
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
473 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
474 dev.off()
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
475
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
476 ## return result file with pvalues and estimates (exclude confidence interval used for plotting)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
477 iCI <- which(substr(colnames(resLM), 4, 7) == "erCI")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
478 resLM <- resLM[, - iCI]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
479 resLM <- cbind(varids, resLM)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
480 return(resLM)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
481 }