annotate diagmfl.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
1 ###############################################################################################
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
2 ## Diagnostics graphics pour les modèles linéaires mixtes de type "mfl" ##
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 ## Input: ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
5 ## mfl, un modèle linéaire mixte généré par le module lmixedm de JF Martin (fonction ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
6 ## lmRepeated2FF), i.e. : un modèle linéaire mixte de type lmer créé par la formule ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
7 ## mfl <- lmer( vd ~ time + fixfact + time:fixfact + (1| subject), ids) ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
8 ## => noms de colonnes importants ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
9 ## => 1 seul effet aléatoire sur l'intercept ##
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 ## Output : ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
12 ## Les graphics, les calculs associés et les notations* utilisées dans le script suivent ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
13 ## l'article de Singer et al (2016) Graphical Tools for detedcting departures from linear ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
14 ## mixed model assumptions and some remedial measures, International Statistical Review ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
15 ## (doi:10.1111/insr.12178) ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
16 ## * ajout d'une ou 2 lettres de typage de la variables ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
17 ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
18 ## Script adapté de http://www.ime.unicamp.br/~cnaber/residdiag_nlme_v22.R pour fonction- ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
19 ## ner avec un modèle lmer (et non lme), des sujets avec des identifiants non numériques, ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
20 ## et des observations non ordonnées sujet par sujet (dernier point à vérifier.) ##
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 ## Remarques sur les calculs numériques ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
23 ## - l'inverse d'une matrice est calculée à partir de la fonction ginv du package MASS ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
24 ## (Moore- Penrose generalized inverse) au lieu de la fonction "solve" ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
25 ## - la racine carrée des matrices sont calculées grâce à une déomposition SVD (car ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
26 ## s'applique normalement ici uniquement à des matrices symétriques positives). A ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
27 ## remplacer par la fonction sqrtm{expm} si des erreurs apparaissent ??? ##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
28 ###############################################################################################
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
29
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
30
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
31 library(ggplot2)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
32 library(gridExtra)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
33 library(grid)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
34
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
35
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
36 ##-------------------------------------------------------------------------------------------------##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
37 ## Helpers
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
38 ##-------------------------------------------------------------------------------------------------##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
39
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
40 ## square root of a matrix
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
41 ## http://www.cs.toronto.edu/~jepson/csc420/notes/introSVD.pdf (page 6)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
42 ## (for matMN a n x n matrix that symetric and non-negative definite)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
43
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
44 sqrtmF<-function(matMN){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
45 matMN <- as.matrix(matMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
46 # ## check that matMN is symetric
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
47 # if(!all(t(matMN==matMN)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
48 # stop("matMN must be symetric.")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
49 svd_dec <- svd(matMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
50 invisible(svd_dec$u%*%sqrt(diag(svd_dec$d))%*%t(svd_dec$v))
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
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
53
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
54 ## qqplotF
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
55 ## adapted from https://gist.github.com/rentrop/d39a8406ad8af2a1066c
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
56
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
57
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
58 qqplotF <- function(x,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
59 distribution = "norm", ...,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
60 line.estimate = NULL,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
61 conf = 0.95,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
62 labels = names(x)){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
63 q.function <- eval(parse(text = paste0("q", distribution)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
64 d.function <- eval(parse(text = paste0("d", distribution)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
65 x <- na.omit(x)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
66 ord <- order(x)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
67 n <- length(x)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
68 P <- ppoints(length(x))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
69 daf <- data.frame(ord.x = x[ord], z = q.function(P, ...))
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 if(is.null(line.estimate)){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
72 Q.x <- quantile(daf$ord.x, c(0.25, 0.75))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
73 Q.z <- q.function(c(0.25, 0.75), ...)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
74 b <- diff(Q.x)/diff(Q.z)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
75 coef <- c(Q.x[1] - b * Q.z[1], b)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
76 } else {
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
77 coef <- coef(line.estimate(ord.x ~ z))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
78 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
79
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
80 zz <- qnorm(1 - (1 - conf)/2)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
81 SE <- (coef[2]/d.function(daf$z,...)) * sqrt(P * (1 - P)/n)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
82 fit.value <- coef[1] + coef[2] * daf$z
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
83 daf$upper <- fit.value + zz * SE
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
84 daf$lower <- fit.value - zz * SE
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 if(!is.null(labels)){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
87 daf$label <- ifelse(daf$ord.x > daf$upper | daf$ord.x < daf$lower, labels[ord],"")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
88 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
89
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
90 p <- ggplot(daf, aes(x=z, y=ord.x)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
91 geom_point() +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
92 geom_abline(intercept = coef[1], slope = coef[2], col = "red") +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
93 geom_line(aes(x=z, y = lower),daf, col = "red", linetype = "dashed") +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
94 geom_line(aes(x=z, y = upper),daf, col = "red", linetype = "dashed") +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
95 #geom_ribbon(aes(ymin = lower, ymax = upper), alpha=0.2)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
96 xlab("")+ylab("")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
97 if(!is.null(labels)) p <- p + geom_text( aes(label = label))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
98
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
99 return(p)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
100 #print(p)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
101 #coef
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
102 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
103
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
104
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
105 ## histogramm
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
106 histF <- function(x, sd_x = NULL, breaks = "scott"){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
107
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
108 if(is.null(sd_x)){ sd_x <- sd(x)}
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
109
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
110 ## Bandwith estimation (default is Scott)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
111 if(!breaks %in% c("sqrt", "sturges", "rice", "scott", "fd"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
112 breaks <- "scott"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
113
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
114 if(breaks %in% c("sqrt", "sturges", "rice")){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
115 k <- switch(breaks,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
116 sqrt = sqrt(length(x)),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
117 sturges = floor(log2(x))+1,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
118 rice = floor(2*length(x)^(1/3))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
119 )
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
120 bw <- diff(range(x))/k
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
121 }else{
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
122 bw <- switch(breaks,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
123 scott = 3.5*sd_x/length(x)^(1/3),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
124 fd = diff(range(x))/(2*IQR(x)/length(x)^(1/3))
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
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
129 daf <- data.frame(x=x)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
130 ## graph
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
131 return(ggplot(data=daf, aes(x)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
132 geom_histogram(aes(y = ..density..),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
133 col="black", fill = "grey", binwidth = bw)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
134 geom_density(size = 1.2,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
135 col = "blue",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
136 linetype = "blank",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
137 fill = rgb(0,0,1, 0.1))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
138 stat_function(fun = dnorm,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
139 args = list(mean = 0, sd = sd_x),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
140 col = "blue", size = 1.2)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
141 theme(legend.position="none")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
142 xlab(""))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
143 }
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
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 ## Main function
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
149 ##-------------------------------------------------------------------------------------------------##
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
150
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
151
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
152 diagmflF <- function(mfl, title = "",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
153 outlier.limit = 3,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
154 pvalCutof = 0.05,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
155 least.confounded = FALSE){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
156
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
157 ## initialisation -------------------------------------------------------------------------------------
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
158 responseC<- "vd"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
159 unitC <- "subject"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
160 timeC<- "time"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
161 fixfactC<-"fixfact"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
162 hlimitN <- outlier.limit
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
163
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
164
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 ## extracting information from mfl models -------------------------------------------------------------
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
167 df <- mfl@frame
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
168 yVn <- df[, responseC]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
169 nobsN <- length(yVn)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
170 idunitVc <- unique(df[, unitC])
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
171 nunitN <- length(unique(idunitVc))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
172 xMN <- mfl@pp$X
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
173 pN <- ncol(xMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
174 zMN <- as.matrix(t(mfl@pp$Zt))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
175 gMN <- as.matrix(as.data.frame(VarCorr(mfl))[1, "vcov"]) ## Valable seulement pour 1 seul effet aléatoire
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
176 gammaMN <- as.matrix(kronecker(diag(nunitN), gMN))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
177 sigsqN <- as.data.frame(VarCorr(mfl))[2, "vcov"]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
178 rMN <- sigsqN*diag(nobsN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
179 vMN <- (zMN%*%gammaMN%*%t(zMN)) + rMN
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
180 invvMN <- MASS::ginv(vMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
181 hMN <- MASS::ginv(t(xMN)%*%invvMN%*%xMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
182 qMN <- invvMN - invvMN%*%xMN%*%(hMN)%*%t(xMN)%*%invvMN
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
183 eblueVn<-mfl@beta
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
184 eblupVn<-gammaMN%*%t(zMN)%*%invvMN%*%(yVn-xMN%*%eblueVn) ## equivalent de ranef(mfl)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
185 rownames(eblupVn) <- colnames(zMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
186
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 ## Calculs of matrices and vectors used in graph diagnosics ---------------------------------------------
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
189
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
190 ## Marginal and individual predictions, residuals and variances
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
191 marpredVn <- xMN%*%eblueVn
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
192 marresVn <- yVn - marpredVn
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
193 marvarMN <- vMN - xMN%*%hMN%*%t(xMN)
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 condpredVn <- marpredVn + zMN%*%eblupVn
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
196 condresVn <- yVn - condpredVn
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
197 condvarMN <- rMN%*%qMN%*%rMN
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
198
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
199
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
200 ## Analysis of marginal and conditional residuals
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
201 stmarresVn <-stcondresVn <- rep(0,nobsN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
202 lesverVn <- rep(0, nunitN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
203 names(lesverVn )<- idunitVc
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
204
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
205 for(i in 1:nunitN){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
206
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
207 idxiVn <- which(df[, unitC] == idunitVc[i]) ## position des observations du sujet i
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
208 miN <- length(idxiVn)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
209
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
210 ## standardization of marginal residual
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
211 stmarresVn[idxiVn] <- as.vector(solve(sqrtmF(marvarMN[idxiVn,idxiVn]))%*%marresVn[idxiVn])
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
212
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
213 ##Standardized Lessafre and Verbeke's measure
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
214 auxMN <- diag(1, ncol = miN, nrow =miN)- stmarresVn[idxiVn]%*%t(stmarresVn[idxiVn])
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
215 lesverVn[i] <- sum(diag(auxMN%*%t(auxMN)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
216
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
217 ## standardization of conditional residual
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
218 stcondresVn[idxiVn] <- as.vector(solve(sqrtmF(condvarMN[idxiVn,idxiVn]))%*%condresVn[idxiVn])
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
219 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
220 lesverVn <- lesverVn/sum(lesverVn)
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
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
223 ## Least confounded residuals (à valider !)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
224 ## résultats différents des valeurs estimées via le script de Singer, car
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
225 ## non unicité des vecteurs propres de la décomposition spectrale ?
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
226 if(least.confounded){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
227 sqrMN <- sqrtmF(rMN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
228 specDec <- eigen((sqrMN%*%qMN%*%sqrMN), symmetric = TRUE, only.values = FALSE)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
229
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
230 cMN <- t(sqrt(solve(diag((specDec$values[1:(nobsN -pN)])))) %*% t(specDec$vectors[1:(nobsN -pN),1:(nobsN -pN)]) %*%
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
231 solve(sqrtmF(rMN[1:(nobsN -pN),1:(nobsN -pN)])) )
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 lccondresVn <- (cMN%*%condresVn[1:(nobsN -pN)])/sqrt(diag(cMN%*%condvarMN[1:(nobsN -pN),1:(nobsN -pN)]%*%t(cMN)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
234 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
235
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
236
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
237 ## EBLUP analysis (Mahalanobis' distance)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
238 varbMN <- gammaMN%*%t(zMN)%*%qMN%*%zMN%*%gammaMN
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
239 mdistVn <- rep(0, nunitN)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
240 for(i in 1:nunitN){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
241 mdistVn[i] <- eblupVn[i]^2/varbMN[i, i]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
242 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
243 mdistVn <- mdistVn/sum(mdistVn)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
244
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
245
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
246 ## Combine data and results in 2 data frames for easy plotting with ggplot2 -----------------------------
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
247
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
248 ## long data frame (all observations)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
249
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
250 df <- data.frame(df,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
251 mar.pred = marpredVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
252 mar.res = marresVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
253 st.mar.res = stmarresVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
254 cond.pred = condpredVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
255 cond.res = condresVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
256 st.cond.res = stcondresVn)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
257
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
258 if(!("fixfact" %in% colnames(df)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
259 df$fixfact <- rep(1, nrow(df))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
260 df$numTime <- as.numeric(levels(as.factor(df$time)))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
261
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 ## short data frame (1 row per unit)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
264
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
265 unitDf <- data.frame(unit = idunitVc,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
266 eblup = eblupVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
267 lvm = lesverVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
268 mal = mdistVn)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
269
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
270 unitDf$fixfact <- sapply(1:nrow(unitDf),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
271 function(i){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
272 unique(df[which(df[, unitC] == unitDf$unit[i]),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
273 fixfactC])
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
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
276 unitDf$se <- rep(NA, nrow(unitDf))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
277 re <- ranef(mfl, condVar =TRUE)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
278 for(i in 1:nrow(unitDf))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
279 unitDf$se[i] <- sqrt(attr(re[[unitC]], "postVar")[1,1,i])
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
280 unitDf$upper <- unitDf$eblup+unitDf$se*1.96
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
281 unitDf$lower <- unitDf$eblup-unitDf$se*1.96
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
282
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
283
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
284 ## Outliers "annotations"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
285 df$marres.out <- rep("", nrow(df))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
286 df$marres.out[abs(df$st.mar.res)>hlimitN] <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
287 paste(df[abs(df$st.mar.res)>hlimitN, unitC],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
288 df[abs(df$st.mar.res)>hlimitN, timeC],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
289 sep = ".")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
290 df$marres.out <- paste(" ", df$marres.out, sep ="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
291
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
292 df$condres.out <- rep("", nrow(df))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
293 df$condres.out[abs(df$st.cond.res)>hlimitN] <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
294 paste(df[abs(df$st.cond.res)>hlimitN, unitC],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
295 df[abs(df$st.cond.res)>hlimitN, timeC],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
296 sep = ".")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
297 df$condres.out <- paste(" ", df$condres.out, sep ="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
298
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
299 ## Diagnostic Plots -------------------------------------------------------------------------------------
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 ## Linearity of effect and outlying observations
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
302 p1 <- ggplot(data = df,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
303 aes(x=mar.pred,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
304 y=st.mar.res,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
305 colour=fixfact)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
306 geom_point(size =2) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
307 geom_hline(yintercept = 0, col = "grey")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
308 geom_smooth(aes(x=mar.pred, y=st.mar.res), data = df, se = FALSE, col = "blue", method = "loess")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
309 ggtitle("Linearity of effects/outlying obervations")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
310 xlab("Marginal predictions")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
311 ylab("Standardized marginal residuals")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
312 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
313 geom_hline(yintercept = c(-1,1)*hlimitN, linetype = "dashed")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
314 geom_text(aes(label = marres.out, col = fixfact), hjust=0, vjust=0)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
315
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
316 # p1hist <- histF(df$st.mar.res, sd_x =1)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
317 # xlab("Standardized marginal residuals")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
318
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
319
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
320 ## Presence of outlying observations and homoscedacity of residuals
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
321 p2 <- ggplot(data = df,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
322 aes(x=cond.pred,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
323 y=st.cond.res,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
324 colour=fixfact)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
325 geom_point(size =2) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
326 geom_hline(yintercept = 0, col = "grey")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
327 geom_smooth(aes(x=cond.pred, y=st.cond.res), data = df, se = FALSE, col = "blue", method = "loess")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
328 ggtitle("Homosedasticity of conditional residuals/outlying observations")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
329 xlab("Individual predictions")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
330 ylab("Standardized conditional residuals")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
331 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
332 geom_hline(yintercept = c(-1,1)*hlimitN, linetype = "dashed")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
333 geom_text(aes(label = condres.out, col = fixfact), hjust=0, vjust=0)
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 # p2hist <- histF(df$st.cond.res, sd_x =1)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
336 # xlab("Standardized conditional residuals")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
337
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
338
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
339 ## Normality of residuals
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
340 if(least.confounded){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
341 p3 <- qqplotF(x = lccondresVn,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
342 distribution = "norm",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
343 line.estimate = NULL,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
344 conf = 0.95)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
345 xlab("Standard normal quantiles")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
346 ylab("Least confounded conditional residual quantiles")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
347 ggtitle("Normality of conditional error (least confounded)")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
348 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
349
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
350 # p3hist <- histF(lccondresVn, sd_x =1)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
351 # xlab("Least confounded conditional residuals")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
352 }else{
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
353 p3 <-qqplotF(x = df$st.cond.res,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
354 distribution = "norm",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
355 line.estimate = NULL,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
356 conf = 0.95)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
357 xlab("Standard normal quantiles")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
358 ylab("Standardized conditional residual quantiles")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
359 ggtitle("Normality of conditional error")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
360 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
361 # p3hist <-p2hist
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
362 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
363
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
364 ## Within-units covariance structure
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
365 p4 <- ggplot(data = unitDf,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
366 aes(x=unit,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
367 y=lvm,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
368 colour=fixfact)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
369 geom_point(size =2) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
370 theme(legend.position="none")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
371 xlab(unitC)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
372 ylab("Standardized Lesaffre-Verbeke measure")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
373 geom_hline(yintercept = 2*mean(unitDf$lvm), linetype = "dashed")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
374 geom_text(aes(label = unit, col = fixfact),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
375 data = unitDf[unitDf$lvm>2*mean(unitDf$lvm), ],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
376 hjust=0, vjust=0)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
377 ggtitle("Within-units covariance matrice")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
378 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
379
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
380 ## EBLUP modif lmerTest v3 mais plante si pas d'effet aléatoire
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
381 #pvl <- ranova(model=mfl, reduce.terms = TRUE)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
382 #pvrnd <- pvl[[6]][2]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
383 #ggtitle(paste("Random effect on intercept (LRT p-value = ",round(pvrnd,digits = 5), ")", sep = ""))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
384
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
385 p5 <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
386 ggplot(aes(x = eblup, y = unit, col = fixfact), data = unitDf)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
387 geom_point(size =3)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
388 geom_segment(aes(xend = lower, yend = unit)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
389 geom_segment(aes(xend = upper, yend = unit))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
390 ggtitle("Random effect on intercept")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
391 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
392 geom_vline(xintercept = 0, linetype = "dashed")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
393 ylab(unitC)
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 ## p6
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
396 p6 <-qqplotF(x = unitDf$mal,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
397 distribution = "chisq",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
398 df= 1,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
399 line.estimate = NULL,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
400 conf = 0.95)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
401 xlab("Chi-squared quantiles")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
402 ylab("Standadized Mahalanobis distance")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
403 ggtitle("Normality of random effect")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
404 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
405
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
406 ## Outlying subjects
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
407 p7 <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
408 ggplot(aes(y = mal, x= unit, col = fixfact), data = unitDf)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
409 geom_point(size =3)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
410 ylab("Standardized Mahalanobis distance")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
411 geom_vline(xintercept = 0, linetype = "dashed")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
412 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
413 geom_hline(yintercept = 2*mean(unitDf$mal), linetype = "dashed")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
414 geom_text(aes(label = unit, col = fixfact),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
415 data = unitDf[unitDf$mal>2*mean(unitDf$mal), ],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
416 hjust=1, vjust=0)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
417 ggtitle("Outlying subjects")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
418 xlab(unitC)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
419
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
420 ## "Data" and "modeling" Plots --------------------------------------------------------------------------
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
421
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
422 ## Individual time-course
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
423 rawPlot <- ggplot(data = df,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
424 aes(x=time, y=vd, colour=fixfact, group=subject)) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
425 geom_line() + ggtitle("Individual time-courses ")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
426 theme(legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
427
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
428 ## Post-hoc estimates (modification due to lmerTest v3)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
429 ddlsm1 <- data.frame(difflsmeans(mfl,test.effs=NULL))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
430 colnames(ddlsm1)[9] <- "pvalue"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
431 # ddlsm1$name <- sapply(rownames(ddlsm1),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
432 # function(nam){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
433 # strsplit(nam, split = " ", fixed =TRUE)[[1]][1]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
434 # })
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
435 # ddlsm1$detail <- sapply(rownames(ddlsm1),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
436 # function(nam){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
437 # paste(strsplit(nam, split = " ", fixed =TRUE)[[1]][-1],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
438 # collapse= "")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
439 # })
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
440 #
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
441 # colnames(ddlsm1)<- make.names(colnames(ddlsm1))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
442 ddlsm1$Significance <- rep("NS", nrow(ddlsm1))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
443
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
444 ## modif JF pour tenir compte du seuil de pvalues defini par le user
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
445 ddlsm1$Significance[which(ddlsm1$pvalue <pvalCutof & ddlsm1$pvalue >=0.01)] <- "p-value < threshold"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
446 ddlsm1$Significance[which(ddlsm1$pvalue <0.01 & ddlsm1$pvalue >=0.005)] <- "p-value < 0.01"
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
447 ddlsm1$Significance[which(ddlsm1$pvalue <0.005)] <- "p-value < 0.005"
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 phPlot <- ggplot(ddlsm1, aes(x = levels, y = Estimate))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
450 facet_grid(facets = ~term, ddlsm1,scales = "free", space = "free")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
451 geom_bar( aes(fill = Significance), stat="identity")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
452 theme(axis.text.x = element_text(angle = 90, hjust = 1))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
453 scale_fill_manual(
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
454 values = c("NS" = "grey",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
455 "p-value < threshold" = "yellow",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
456 "p-value < 0.01" = "orange",
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
457 "p-value < 0.005" = "red"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
458 geom_errorbar(aes(ymin = lower, ymax =upper ), width=0.25)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
459 ggtitle("Post-hoc estimates")+xlab("")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
460 theme(plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
461
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
462 ## Final plotting
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
463
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
464 blank<-rectGrob(gp=gpar(col="white"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
465 rectspacer<-rectGrob(height = unit(0.1, "npc"), gp=gpar(col="grey"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
466
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
467 grid.arrange(blank,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
468 rawPlot, blank, phPlot,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
469 rectspacer,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
470 p1,blank, p2, blank, p3, blank, p4,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
471 blank,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
472 p5,blank, p6, blank, p7, blank,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
473 blank,blank,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
474 top = textGrob(title,gp=gpar(fontsize=40,font=4)),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
475 layout_matrix = matrix(c(rep(1,7),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
476 2, 3, rep(4,3), 20,21,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
477 rep(5,7),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
478 6:12,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
479 rep(13,7),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
480 14:18, rep(19,2)),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
481 ncol=7, nrow=6, byrow=TRUE),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
482 heights= c(0.1/3, 0.3, 0.1/3, 0.3, 0.1/3, 0.3 ),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
483 widths = c(0.22, 0.04, 0.22,0.04 , 0.22, 0.04, 0.22))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
484
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
485 invisible(NULL)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
486
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
487 }
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
488
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
489 #diagmflF(mfl, title = "", outlier.limit = 3, least.confounded =TRUE)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
490
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
491 plot.res.Lmixed <- function(mfl, df, title = "", pvalCutof = 0.05) {
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
492
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
493 nameVar <- colnames(df)[4]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
494 fflab <- colnames(df)[1]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
495 ## Individual time-course
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
496 rawPlot <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
497 ggplot(data = df, aes(x=df[[2]], y=df[[4]], colour=df[[1]], group=df[[3]])) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
498 geom_line() + ggtitle("Individual time-courses (raw data)")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
499 ylab(nameVar) +
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
500 xlab(label = colnames(df)[2])+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
501 theme(legend.title = element_blank() , legend.position="none", plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
502
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
503 ## Boxplot of fixed factor
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
504 bPlot <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
505 ggplot(data = df, aes(y=df[[4]], x=df[[1]], color=df[[1]]))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
506 geom_boxplot(outlier.colour="red", outlier.shape=8, outlier.size=4)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
507 ggtitle(paste("Boxplot by ",fflab,sep=""))+xlab("")+ylab("")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
508 theme(legend.title = element_blank(), plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
509
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
510 ## Post-hoc estimates
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
511
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
512 ddlsm1 <- mfl
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
513 ddlsm1$name <- rownames(ddlsm1)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
514 # ddlsm1$name <- sapply(rownames(ddlsm1),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
515 # function(nam){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
516 # strsplit(nam, split = " ", fixed =TRUE)[[1]][1]
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
517 # })
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
518 # ddlsm1$detail <- sapply(rownames(ddlsm1),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
519 # function(nam){
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
520 # paste(strsplit(nam, split = " ", fixed =TRUE)[[1]][-1],
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
521 # collapse= "")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
522 # })
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
523 #
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
524 #colnames(ddlsm1)<- make.names(colnames(ddlsm1))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
525 ddlsm1$Significance <- rep("NS", nrow(ddlsm1))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
526
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
527 ## modif JF pour tenir compte du seuil de pvalues defini par le user
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
528 options("scipen"=100, "digits"=5)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
529 pvalCutof <- as.numeric(pvalCutof)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
530 bs=0.05; bm=0.01; bi=0.005
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
531 if (pvalCutof >bm) {bs <- pvalCutof} else
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
532 if (pvalCutof <bm & pvalCutof >bi) {bm <- pvalCutof; bs <- pvalCutof} else
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
533 if (pvalCutof < bi) {bi <- pvalCutof; bm <- pvalCutof; bs <- pvalCutof}
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
534 lbs <- paste("p-value < ",bs, sep="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
535 lbm <- paste("p-value < ",bm, sep="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
536 lbi <- paste("p-value < ",bi, sep="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
537
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
538 cols <- paste("p-value < ",bs, sep="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
539 colm <- paste("p-value < ",bm, sep="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
540 coli <- paste("p-value < ",bi, sep="")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
541 valcol <- c("grey","yellow","orange","red")
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
542 names (valcol) <- c("NS",lbs,lbm,lbi)
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
543 ddlsm1$Significance[which(ddlsm1$p.value<= bs)] <- lbs
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
544 ddlsm1$Significance[which(ddlsm1$p.value<bs & ddlsm1$p.value>= bm)] <- lbm
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
545 ddlsm1$Significance[which(ddlsm1$p.value<bi)] <- lbi
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
546
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
547 phPlot <-
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
548 ggplot(ddlsm1, aes(x = levels, y = Estimate))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
549 facet_grid(facets = ~term, ddlsm1,scales = "free", space = "free")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
550 geom_bar( aes(fill = Significance), stat="identity")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
551 theme(axis.text.x = element_text(angle = 90, hjust = 1))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
552 scale_fill_manual(
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
553 # values = c("NS" = "grey", "p-value < threshold" = "yellow","p-value < 0.01" = "orange","p-value < 0.005" = "red"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
554 # values = c("NS" = 'grey', "pvalue < 0.05 "= 'yellow',"p-value < 0.01" = 'orange',"p-value < 0.005" = 'red'))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
555 # values = c("NS = grey", "p-value < threshold = yellow","p-value < 0.01 = orange","p-value < 0.005 = red"))+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
556 values = valcol )+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
557 geom_errorbar(aes(ymin = Lower.CI, ymax =Upper.CI ), width=0.25)+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
558 # ggtitle(paste("Post-hoc estimates with p-value threshold = ",pvalCutof,sep=""))+xlab("")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
559 ggtitle("Post-hoc estimates ")+xlab("")+
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
560 theme(plot.title = element_text(size = rel(1.2), face = "bold"))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
561
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
562 ## Final plotting
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
563 grid.arrange(arrangeGrob(rawPlot,bPlot,ncol=2),
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
564 phPlot,nrow=2,
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
565 top = textGrob(title,gp=gpar(fontsize=32,font=4))
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
566 )
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
567
1422de181204 planemo upload for repository https://github.com/workflow4metabolomics/mixmodel4repeated_measures commit 6ea32b3182383c19e5333201d2385a61d8da3d50
jfrancoismartin
parents:
diff changeset
568 }