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