annotate diagmfl.R @ 0:a4d89d47646f draft default tip

planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
author workflow4metabolomics
date Mon, 16 May 2022 09:25:01 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
1 #' Calcul des grandeurs "diagnostiques"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
2 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
3 #' Script adapte de http://www.ime.unicamp.br/~cnaber/residdiag_nlme_v22.R pour fonctionner
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
4 #' avec un modele lmer (et non lme), des sujets avec des identifiants non numeriques,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
5 #' et des observations non ordonnees sujet par sujet (dernier point a verifier.)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
6 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
7 #' @detail Les graphiques, les calculs associƩs et les notations utilisees dans le script suivent
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
8 #' l'article de Singer et al (2016) Graphical Tools for detedcting departures from linear
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
9 #' mixed model assumptions and some remedial measures, International Statistical Review
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
10 #' (doi:10.1111/insr.12178)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
11 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
12 #' @param mfl A linear mixed model fitted via lmer or a data frame containing data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
13 #' @return A list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
14 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
15 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
16 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
17 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
18 #' @export lmer.computeDiag
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
19
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
20
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
21
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
22 lmer.computeDiag <- function(mfl) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
23
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
24 ## Check arguments ---------------------------------------------------------
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
25
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
26 if (length(mfl@flist) > 1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
27 stop("Several 'grouping level' for random effect not implemented yet.")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
28
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
29
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
30 ## extracting information from mfl models -------------------------------------------------------------
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
31 # data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
32 df <- mfl@frame
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
33 responseC <- names(df)[1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
34 unitC <- names(mfl@flist)[1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
35 # observations
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
36 yVn <- df[, responseC]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
37 nobsN <- length(yVn)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
38 # units
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
39 idunitVc <- levels(mfl@flist[[1]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
40 nunitN <- length(unique(idunitVc))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
41 #X
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
42 xMN <- mfl@pp$X
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
43 pN <- ncol(xMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
44 #Z
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
45 zMN <- t(as.matrix(mfl@pp$Zt))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
46 # Estimated covariance matrix of random effects (Gam)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
47 aux <- VarCorr(mfl)[[1]] ## assuming only one level of grouping
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
48 aux2 <- attr(aux, "stddev")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
49 gMN <- attr(aux, "correlation") * (aux2 %*% t(aux2))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
50 gammaMN <- as.matrix(kronecker(diag(nunitN), gMN))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
51 q <- dim(gMN)[1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
52 # Estimated covariance matrix of conditonal error (homoskedastic conditional independance model)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
53 sigsqN <- attr(VarCorr(mfl), "sc")^2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
54 rMN <- sigsqN * diag(nobsN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
55 # Estimated covariance matrix of Y
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
56 vMN <- (zMN %*% gammaMN %*% t(zMN)) + rMN
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
57 invvMN <- MASS::ginv(vMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
58 # H and Q matrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
59 hMN <- MASS::ginv(t(xMN) %*% invvMN %*% xMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
60 qMN <- invvMN - invvMN %*% xMN %*% (hMN) %*% t(xMN) %*% invvMN
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
61 # eblue and eblup
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
62 eblueVn <- mfl@beta
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
63 eblupVn <- gammaMN %*% t(zMN) %*% invvMN %*% (yVn - xMN %*% eblueVn) ## equivalent de ranef(mfl)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
64 rownames(eblupVn) <- colnames(zMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
65 ## Calculs of matrices and vectors used in graph diagnosics ---------------------------------------------
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
66 ## Marginal and individual predictions, residuals and variances
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
67 marpredVn <- xMN %*% eblueVn
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
68 marresVn <- yVn - marpredVn
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
69 marvarMN <- vMN - xMN %*% hMN %*% t(xMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
70 condpredVn <- marpredVn + zMN %*% eblupVn
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
71 condresVn <- yVn - condpredVn
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
72 condvarMN <- rMN %*% qMN %*% rMN
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
73 ## Analysis of marginal and conditional residuals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
74 stmarresVn <- stcondresVn <- rep(0, nobsN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
75 lesverVn <- rep(0, nunitN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
76 names(lesverVn) <- idunitVc
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
77 for (i in 1:nunitN) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
78 idxiVn <- which(df[, unitC] == idunitVc[i]) ## position des observations du sujet i
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
79 miN <- length(idxiVn)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
80 ## standardization of marginal residual
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
81 stmarresVn[idxiVn] <- as.vector(solve(sqrtmF(marvarMN[idxiVn, idxiVn])) %*% marresVn[idxiVn])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
82 ##Standardized Lessafre and Verbeke's measure
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
83 auxMN <- diag(1, ncol = miN, nrow = miN) - stmarresVn[idxiVn] %*% t(stmarresVn[idxiVn])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
84 lesverVn[i] <- sum(diag(auxMN %*% t(auxMN)))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
85 ## standardization of conditional residual
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
86 stcondresVn[idxiVn] <- as.vector(solve(sqrtmF(condvarMN[idxiVn, idxiVn])) %*% condresVn[idxiVn])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
87 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
88 lesverVn <- lesverVn / sum(lesverVn)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
89 ## Least confounded conditional residuals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
90 ## EBLUP analysis (Mahalanobis' distance)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
91 varbMN <- gammaMN %*% t(zMN) %*% qMN %*% zMN %*% gammaMN
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
92 mdistVn <- rep(0, nunitN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
93 qm <- q - 1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
94 for (j in 1:nunitN) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
95 gbi <- varbMN[(q * j - qm):(q * j), (q * j - qm):(q * j)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
96 eblupi <- eblupVn[(q * j - qm):(q * j)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
97 mdistVn[j] <- t(eblupi) %*% ginv(gbi) %*% eblupi
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
98 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
99 names(mdistVn) <- levels(mfl@flist[[1]])
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
100 ## output ----------------------------------------------
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
101 return(list(
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
102 data = df,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
103 q = q,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
104 eblue = eblueVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
105 eblup = eblupVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
106 marginal.prediction = marpredVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
107 conditional.prediction = condpredVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
108 std.marginal.residuals = stmarresVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
109 std.conditional.residuals = stcondresVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
110 mahalanobis.distance = mdistVn,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
111 std.mahalanobis.distance = mdistVn / sum(mdistVn),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
112 std.lesaffreverbeke.measure = lesverVn
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
113 ))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
114 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
115
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
116
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
117 #' Wrapper function for diagnostic plots of 'lmer' linear mixed models
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
118 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
119 #' (W4M mixmod)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
120 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
121 #' @param mfl A linear mixed model fitted via lmer or a data frame containing data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
122 #' @param title aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
123 #' @param outlier.limit aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
124 #' @param pvalCutof aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
125 #' @param resC aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
126 #' @param uniC aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
127 #' @param fixC aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
128 #' @param lest.confounded Not used yet.
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
129 #' @return NULL
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
130 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
131 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
132 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
133 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
134 #' @export diagmflF
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
135
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
136
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
137 diagmflF <- function(mfl,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
138 title = "",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
139 outlier.limit = 3,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
140 pvalCutof = 0.05,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
141 resC = "vd",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
142 uniC = "subject",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
143 timC = "time",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
144 fixC = "fixfact",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
145 least.confounded = FALSE) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
146 ## diagnostics
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
147 diagLs <- lmer.computeDiag(mfl)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
148 ## plots
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
149 blank <- rectGrob(gp = gpar(col = "white"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
150 rectspacer <- rectGrob(height = unit(0.1, "npc"), gp = gpar(col = "grey"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
151 grid.arrange(blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
152 plot_linearity(diagLs, hlimitN = outlier.limit, plotL = FALSE,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
153 label_factor = c(uniC, fixC, timC)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
154 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
155 plot_conditionalResiduals(diagLs, hlimitN = outlier.limit, plotL = FALSE,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
156 label_factor = c(uniC, fixC, timC)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
157 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
158 plot_condresQQplot(diagLs, plotL = FALSE),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
159 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
160 plot_lesaffreVeerbeke(diagLs, plotL = FALSE),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
161 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
162 plot_randomEffect(mfl, plotL = FALSE)[[1]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
163 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
164 plot_mahalanobisKhi2(diagLs, plotL = FALSE),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
165 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
166 plot_mahalanobis(diagLs, plotL = FALSE),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
167 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
168 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
169 blank,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
170 top = textGrob(title, gp = gpar(fontsize = 40, font = 4)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
171 layout_matrix = matrix(c(rep(1, 7),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
172 2, 3, rep(4, 3), 20, 21,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
173 rep(5, 7),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
174 6:12,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
175 rep(13, 7),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
176 14:18, rep(19, 2)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
177 ncol = 7, nrow = 6, byrow = TRUE),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
178 heights = c(0.1 / 3, 0.3, 0.1 / 3, 0.3, 0.1 / 3, 0.3),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
179 widths = c(0.22, 0.04, 0.22, 0.04, 0.22, 0.04, 0.22))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
180 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
181
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
182 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
183 ## Raw data time courses
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
184 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
185
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
186 #' Visualization of raw time course
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
187 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
188 #' Une
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
189 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
190 #' @param mfl A linear mixed model fitted via lmer or a data frame containing data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
191 #' @param responseC Name of the 'response' variable
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
192 #' @param timeC Name of the 'time' variable
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
193 #' @param subjectC Name of the 'subject' variable
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
194 #' @param fixfactC Name of the 'fixed factor' variable (e.g.treatment)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
195 #' @param offset_subject Boolean indicating if an offset value (subject's mean) should substracted to each data point. Default is FALSE
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
196 #' @param plotL Boolean
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
197 #' @param colorType One of NA, FIXFACT or SUBJECT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
198 #' @param shapeType One of NA, FIXFACT or SUBJECT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
199 #' @param lineType One of NA, FIXFACT or SUBJECT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
200 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
201 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
202 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
203 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
204 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
205 #' @export plot_timeCourse
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
206
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
207
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
208
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
209 plot_timeCourse <- function(mfl,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
210 responseC,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
211 timeC,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
212 subjectC,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
213 fixfactC = NULL,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
214 offset_subject = FALSE,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
215 plotL = TRUE,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
216 colorType = NA, ## subject, fixfact, none or NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
217 shapeType = NA, ## subject, fixfact, none or NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
218 lineType = NA ## subject, fixfact, none or NA
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
219 ) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
220 ## Data -----
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
221 if (class(mfl) %in% c("merModLmerTest", "lmerMod", "lmerModLmerTest")) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
222 DF <- mfl@frame
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
223 } else if (class(mfl) == "data.frame") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
224 DF <- mfl
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
225 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
226 stop("'mfl' argument must be a linear mixed effect model or a data frame.")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
227 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
228 ## Format data -----
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
229 if (is.null(fixfactC)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
230 DF <- DF[, c(responseC, timeC, subjectC)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
231 colnames(DF) <- c("DV", "TIME", "SUBJECT")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
232 meanDF <- aggregate(DF$DV,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
233 by = list(SUBJECT = DF$SUBJECT,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
234 TIME = DF$TIME),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
235 FUN = mean,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
236 na.rm = TRUE)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
237 colnames(meanDF) <- c("SUBJECT", "TIME", "DV")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
238 meanDF$GROUP <- meanDF$SUBJECT
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
239 } else{
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
240 DF <- DF[, c(responseC, fixfactC, timeC, subjectC)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
241 colnames(DF) <- c("DV", "FIXFACT", "TIME", "SUBJECT")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
242 meanDF <- aggregate(DF$DV,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
243 by = list(SUBJECT = DF$SUBJECT,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
244 TIME = DF$TIME,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
245 FIXFACT = DF$FIXFACT),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
246 FUN = mean,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
247 na.rm = TRUE)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
248 colnames(meanDF) <- c("SUBJECT", "TIME", "FIXFACT", "DV")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
249 meanDF$GROUP <- paste(meanDF$SUBJECT, meanDF$FIXFACT, sep = "_")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
250 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
251 ## Offset -----
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
252 if (offset_subject) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
253 offsetMN <- aggregate(DF$DV, by = list(DF$SUBJECT), mean, na.rm = TRUE)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
254 offsetVn <- offsetMN[, 2]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
255 names(offsetVn) <- offsetMN[, 1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
256 rm(offsetMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
257 DF$DV <- DF$DV - offsetVn[DF$SUBJECT]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
258 meanDF$DV <- meanDF$DV - offsetVn[as.character(meanDF$SUBJECT)]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
259 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
260 ## Graphical parameters -----
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
261 xlabC <- timeC
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
262 ylabC <- responseC
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
263 titC <- "Individual time-courses"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
264 if (offset_subject) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
265 ylabC <- paste(ylabC, "minus 'within-subject' empirical mean")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
266 titC <- paste(titC, "('within-subject' empirical mean offset)")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
267 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
268 ## color
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
269 if (is.na(colorType)) { ## automaticatical attribution
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
270 if (is.null(fixfactC)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
271 colorType <- "SUBJECT"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
272 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
273 colorType <- "FIXFACT"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
274 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
275 colTxt <- paste(", colour=", colorType)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
276 } else if (colorType == "none") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
277 colTxt <- ""
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
278 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
279 colTxt <- paste(", colour=", colorType)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
280 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
281 ## lineType
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
282 if (is.na(lineType)) { ## automaticatical attribution
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
283 if (is.null(fixfactC)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
284 linTxt <- ""
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
285 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
286 linTxt <- paste(", linetype=",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
287 ifelse(colorType == "SUBJECT", "FIXFACT", "SUBJECT"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
288 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
289 } else if (lineType == "none") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
290 linTxt <- ""
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
291 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
292 linTxt <- paste(", linetype=", lineType)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
293 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
294 ## shapeType
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
295 if (is.na(shapeType)) { ## automaticatical attribution
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
296 if (is.null(fixfactC)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
297 shaTxt <- ""
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
298 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
299 shaTxt <- paste(", shape=",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
300 ifelse(colorType == "SUBJECT", "FIXFACT", "SUBJECT"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
301 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
302 } else if (shapeType == "none") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
303 shaTxt <- ""
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
304 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
305 shaTxt <- paste(", shape=", shapeType)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
306 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
307 ## aes mapping
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
308 txtMap <- paste("aes(x = TIME, y = DV",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
309 colTxt, shaTxt, ")", sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
310 txtLineMap <- paste("aes(x = TIME, y = DV, group = GROUP ",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
311 colTxt, linTxt, ")", sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
312 ## plot and output
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
313 p <- ggplot(data = DF, mapping = eval(parse(text = txtMap))) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
314 ggtitle(titC) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
315 xlab(xlabC) + ylab(ylabC) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
316 theme(legend.position = "left",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
317 plot.title = element_text(size = rel(1.2), face = "bold")) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
318 geom_point() +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
319 geom_line(eval(parse(text = txtLineMap)), data = meanDF) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
320 theme_bw() +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
321 NULL
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
322 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
323 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
324 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
325
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
326 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
327 ## Post-hoc estimate
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
328 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
329 #' Visualization of fixed effects (post-hoc estimates)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
330 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
331 #' Description
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
332 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
333 #' @param mfl A linear mixed model fitted via lmer or a data frame containing data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
334 #' @param pvalCutof User pvalue cut of
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
335 #' @param plotL Boolean
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
336 #' @param titC Title of the plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
337 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
338 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
339 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
340 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
341 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
342 #' @export plot_posthoc
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
343 plot_posthoc <- function(mfl, pvalCutof = 0.05, plotL = TRUE, titC = "Post-hoc estimates") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
344 ddlsm1 <- as.data.frame(difflsmeans(mfl, test.effs = NULL))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
345 colnames(ddlsm1)[ncol(ddlsm1)] <- "pvalue"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
346 ddlsm1$Significance <- rep("NS", nrow(ddlsm1))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
347 ## modif JF pour tenir compte du seuil de pvalues defini par le user
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
348 ddlsm1$Significance[which(ddlsm1$pvalue < pvalCutof)] <- paste("p-value < ", pvalCutof, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
349 ddlsm1$Significance[which(ddlsm1$pvalue < pvalCutof / 5)] <- paste("p-value < ", pvalCutof / 5, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
350 ddlsm1$Significance[which(ddlsm1$pvalue < pvalCutof / 10)] <- paste("p-value < ", pvalCutof / 10, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
351 ddlsm1$levels <- rownames(ddlsm1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
352 ddlsm1$term <- sapply(rownames(ddlsm1), function(namC) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
353 strsplit(namC, split = " ", fixed = TRUE)[[1]][1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
354 })
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
355 colValue <- c("grey", "yellow", "orange", "red")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
356 names(colValue) <- c("NS",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
357 paste("p-value < ", pvalCutof, sep = ""),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
358 paste("p-value < ", pvalCutof / 5, sep = ""),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
359 paste("p-value < ", pvalCutof / 10, sep = ""))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
360 p <- ggplot(ddlsm1, aes(x = levels, y = Estimate)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
361 facet_grid(facets = ~term, ddlsm1, scales = "free", space = "free") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
362 geom_bar(aes(fill = Significance), stat = "identity") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
363 theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
364 scale_fill_manual(values = colValue) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
365 geom_errorbar(aes(ymin = lower, ymax = upper), width = 0.25) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
366 ggtitle(titC) + xlab("") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
367 NULL
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
368 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
369 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
370 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
371
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
372 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
373 ## Visualisation des effets alƩatoires
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
374 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
375 #' Visualization of random effects
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
376 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
377 #' Equivalent of dotplot(ranef)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
378 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
379 #' @param mfl A linear mixed model fitted via lmer or a data frame containing data
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
380 #' @param plotL Logical
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
381 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
382 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
383 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
384 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
385 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
386 #' @export plot_randomEffect
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
387
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
388
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
389 plot_randomEffect <- function(mfl, plotL = TRUE) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
390 ## Estimation et format des effets alƩatoires
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
391 randomEffect <- ranef(mfl, condVar = TRUE)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
392 DF <- data.frame(randomEffect = rep(names(randomEffect),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
393 times = sapply(seq_len(length(randomEffect)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
394 function(lsi) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
395 return(length(unlist(randomEffect[[lsi]])))})))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
396 DF$condVar <- DF$estimate <- DF$x2 <- DF$x1 <- rep(NA, nrow(DF))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
397 for (rafC in names(randomEffect)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
398 eff <- randomEffect[[rafC]]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
399 DF$x1[which(DF$randomEffect == rafC)] <- rep(colnames(eff), each = nrow(eff))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
400 DF$x2[which(DF$randomEffect == rafC)] <- rep(rownames(eff), ncol(eff))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
401 DF$estimate[which(DF$randomEffect == rafC)] <- unlist(eff)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
402 condvar <- attr(randomEffect[[rafC]], "postVar")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
403 se <- NULL
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
404 for (coli in seq_len(ncol(eff))) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
405 se <- c(se,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
406 sapply(seq_len(nrow(eff)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
407 function(i) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
408 return(condvar[coli, coli, i])}))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
409 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
410 DF$condVar[which(DF$randomEffect == rafC)] <- se
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
411 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
412 DF$se <- sqrt(DF$condVar)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
413 DF$lower <- DF$estimate - 1.96 * DF$se
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
414 DF$upper <- DF$estimate + 1.96 * DF$se
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
415 ## Plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
416 plotLs <- vector("list", length(randomEffect))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
417 names(plotLs) <- names(randomEffect)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
418 for (pi in seq_len(length(plotLs))) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
419 subDF <- DF[DF$randomEffect == names(plotLs)[pi], ]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
420 subDF <- subDF[order(subDF$x1, subDF$estimate, decreasing = FALSE), ]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
421 p <- ggplot(data = subDF,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
422 mapping = aes(x = estimate, y = reorder(x2, estimate))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
423 ) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
424 geom_point(size = 3) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
425 geom_segment(aes(xend = lower, yend = x2)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
426 geom_segment(aes(xend = upper, yend = x2)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
427 facet_wrap(~x1, ncol = length(unique(subDF$x1))) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
428 ylab("") + xlab("") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
429 ggtitle(paste("Random effect - ", names(plotLs)[pi], sep = "")) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
430 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold")) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
431 geom_vline(xintercept = 0, linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
432 theme_bw()
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
433 plotLs[[pi]] <- p
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
434 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
435 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
436 invisible(plotLs)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
437 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
438
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
439 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
440 ## LinearitƩ des effets et outlying observations
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
441 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
442 #' Linarity of the fixed effect with regard to the continuous time
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
443 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
444 #' @param diagLs diagnostic list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
445 #' @param hlimitN Limit value for outliers (e.g.2 or 3)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
446 #' @param plotL Boolean
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
447 #' @param label_factor Column of observation names used to label outlying values
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
448 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
449 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
450 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
451 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
452 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
453 #' @export plot_linearity
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
454 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
455
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
456 plot_linearity <- function(diagLs, hlimitN, plotL = TRUE, label_factor = NULL) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
457 df <- cbind.data.frame(diagLs$data,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
458 marginal.prediction = diagLs$marginal.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
459 standardized.marginal.residuals = diagLs$std.marginal.residuals)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
460 # outlier annotation
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
461 df$outliers <- rep("", nrow(df))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
462 outidx <- which(abs(df$standardized.marginal.residuals) > hlimitN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
463 df[outidx, "outliers"] <- (seq_len(nrow(df)))[outidx]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
464 if (length(label_factor) >= 1) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
465 df[outidx, "outliers"] <- paste(df[outidx, "outliers"],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
466 df[outidx, label_factor[1]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
467 sep = "_")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
468 if (length(label_factor) > 1) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
469 for (li in 2:length(label_factor)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
470 df[outidx, "outliers"] <- paste(df[outidx, "outliers"],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
471 df[outidx, label_factor[li]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
472 sep = ".")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
473 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
474 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
475 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
476 p <- ggplot(data = df,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
477 aes(x = marginal.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
478 y = standardized.marginal.residuals)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
479 geom_point(size = 2) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
480 geom_hline(yintercept = 0, col = "grey") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
481 geom_smooth(aes(x = marginal.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
482 y = standardized.marginal.residuals), data = df, se = FALSE, col = "blue", method = "loess") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
483 ggtitle("Linearity of effects/outlying obervations") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
484 xlab("Marginal predictions") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
485 ylab("Standardized marginal residuals") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
486 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold")) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
487 geom_hline(yintercept = c(-1, 1) * hlimitN, linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
488 geom_text(aes(label = outliers), hjust = 0, vjust = 0)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
489 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
490 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
491 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
492
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
493
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
494 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
495 ## EBLUP
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
496 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
497
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
498
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
499 #' Mahalanobis distance
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
500 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
501 #' @param diagLs diagnostic list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
502 #' @param plotL Boolean
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
503 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
504 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
505 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
506 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
507 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
508 #' @export plot_mahalanobis
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
509 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
510
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
511
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
512 plot_mahalanobis <- function(diagLs, plotL = TRUE) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
513 unitDf <- data.frame(unit = names(diagLs$std.mahalanobis.distance),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
514 mal = diagLs$std.mahalanobis.distance)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
515 ## Outlying subjects
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
516 p <-
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
517 ggplot(aes(y = mal, x = unit), data = unitDf) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
518 geom_point(size = 3) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
519 ylab("Standardized Mahalanobis distance") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
520 geom_vline(xintercept = 0, linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
521 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold")) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
522 geom_hline(yintercept = 2 * mean(unitDf$mal), linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
523 geom_text(aes(label = unit),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
524 data = unitDf[unitDf$mal > 2 * mean(unitDf$mal), ],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
525 hjust = 1, vjust = 0) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
526 ggtitle("Outlying unit") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
527 xlab("unit")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
528 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
529 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
530 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
531
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
532
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
533
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
534
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
535
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
536
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
537 #' Mahalanobis distance (Chi2)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
538 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
539 #' @param diagLs diagnostic list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
540 #' @param plotL aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
541 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
542 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
543 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
544 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
545 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
546 #' @export plot_mahalanobisKhi2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
547 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
548
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
549
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
550 plot_mahalanobisKhi2 <- function(diagLs, plotL = TRUE) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
551 unitDf <- data.frame(unit = names(diagLs$std.mahalanobis.distance),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
552 mal = diagLs$mahalanobis.distance)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
553 p <- qqplotF(x = unitDf$mal,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
554 distribution = "chisq",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
555 df = diagLs$q,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
556 line.estimate = NULL,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
557 conf = 0.95) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
558 xlab("Chi-squared quantiles") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
559 ylab("Mahalanobis distance") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
560 ggtitle("Normality of random effect") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
561 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
562 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
563 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
564 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
565
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
566
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
567
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
568
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
569
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
570
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
571
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
572 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
573 ## Residus conditionels
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
574 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
575
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
576 ## Presence of outlying observations and homoscedacity of residuals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
577
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
578 #' Homoskedacity of conditionalresiduals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
579 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
580 #' @param diagLs diagnostic list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
581 #' @param hlimitN Limit value for outliers (e.g.2 or 3)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
582 #' @param plotL Boolean
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
583 #' @param label_factor Column of observation names used to label outlying values
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
584 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
585 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
586 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
587 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
588 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
589 #' @export plot_conditionalResiduals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
590 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
591
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
592
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
593 plot_conditionalResiduals <- function(diagLs, hlimitN, plotL = TRUE, label_factor = NULL) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
594 df <- cbind.data.frame(diagLs$data,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
595 conditional.prediction = diagLs$conditional.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
596 standardized.conditional.residuals = diagLs$std.conditional.residuals)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
597 # outlier annotation
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
598 df$outliers <- rep("", nrow(df))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
599 outidx <- which(abs(df$standardized.conditional.residuals) > hlimitN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
600 df[outidx, "outliers"] <- (seq_len(nrow(df)))[outidx]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
601 if (length(label_factor) >= 1) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
602 df[outidx, "outliers"] <- paste(df[outidx, "outliers"],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
603 df[outidx, label_factor[1]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
604 sep = "_")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
605 if (length(label_factor) > 1) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
606 for (li in 2:length(label_factor)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
607 df[outidx, "outliers"] <- paste(df[outidx, "outliers"],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
608 df[outidx, label_factor[li]],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
609 sep = ".")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
610 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
611 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
612 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
613 p <- ggplot(data = df,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
614 aes(x = conditional.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
615 y = standardized.conditional.residuals)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
616 geom_point(size = 2) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
617 geom_hline(yintercept = 0, col = "grey") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
618 geom_smooth(aes(x = conditional.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
619 y = standardized.conditional.residuals),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
620 data = df, se = FALSE, col = "blue", method = "loess") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
621 ggtitle("Homoscedasticity of conditional residuals/outlying observations") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
622 xlab("Individual predictions") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
623 ylab("Standardized conditional residuals") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
624 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold")) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
625 geom_hline(yintercept = c(-1, 1) * hlimitN, linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
626 geom_text(aes(label = outliers), hjust = 0, vjust = 0)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
627 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
628 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
629 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
630
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
631
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
632
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
633
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
634 #' Normality of conditionalresiduals
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
635 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
636 #' @param diagLs diagnostic list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
637 #' @param plotL aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
638 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
639 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
640 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
641 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
642 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
643 #' @export plot_condresQQplot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
644 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
645
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
646
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
647 plot_condresQQplot <- function(diagLs, plotL = TRUE) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
648 df <- cbind.data.frame(diagLs$data,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
649 conditional.prediction = diagLs$conditional.prediction,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
650 standardized.conditional.residuals = diagLs$std.conditional.residuals)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
651 p <- qqplotF(x = df$standardized.conditional.residuals,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
652 distribution = "norm",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
653 line.estimate = NULL,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
654 conf = 0.95) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
655 xlab("Standard normal quantiles") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
656 ylab("Standardized conditional residual quantiles") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
657 ggtitle("Normality of conditional error") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
658 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
659 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
660 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
661 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
662
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
663
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
664
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
665
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
666
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
667 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
668 ## Within-units covariance structure
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
669 #######################################################################################################
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
670
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
671
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
672 #' Lesaffre-Veerbeke measure
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
673 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
674 #' @param diagLs diagnostic list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
675 #' @param plotL aa
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
676 #' @return A plot
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
677 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
678 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
679 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
680 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
681 #' @export plot_lesaffreVeerbeke
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
682 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
683
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
684
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
685 plot_lesaffreVeerbeke <- function(diagLs, plotL = TRUE) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
686 unitDf <- data.frame(unit = names(diagLs$std.lesaffreverbeke.measure),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
687 lvm = diagLs$std.lesaffreverbeke.measure)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
688 p <- ggplot(data = unitDf,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
689 aes(x = unit,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
690 y = lvm)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
691 geom_point(size = 2) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
692 theme(legend.position = "none") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
693 xlab("units") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
694 ylab("Standardized Lesaffre-Verbeke measure") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
695 geom_hline(yintercept = 2 * mean(unitDf$lvm), linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
696 geom_text(aes(label = unit),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
697 data = unitDf[unitDf$lvm > 2 * mean(unitDf$lvm), ],
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
698 hjust = 0, vjust = 0) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
699 ggtitle("Within-units covariance matrice") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
700 theme(legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
701 if (plotL) plot(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
702 invisible(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
703 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
704
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
705 ##-------------------------------------------------------------------------------------------------##
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
706 ## Helpers
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
707 ##-------------------------------------------------------------------------------------------------##
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
708
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
709
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
710 ## square root of a matrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
711 ## From Rocha, Singer and Nobre
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
712
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
713 #' square root of a matrix (Rocha)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
714 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
715 #' Description
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
716 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
717 #' @param mat Matrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
718 #' @return A list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
719 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
720 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
721 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
722 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
723 #' @export sqrt.matrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
724
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
725 sqrt.matrix <- function(mat) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
726 mat <- as.matrix(mat) # new line of code
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
727 singular_dec <- svd(mat, LINPACK = F)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
728 U <- singular_dec$u
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
729 V <- singular_dec$v
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
730 D <- diag(singular_dec$d)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
731 sqrtmatrix <- U %*% sqrt(D) %*% t(V)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
732 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
733
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
734
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
735 ## square root of a matrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
736 ## http://www.cs.toronto.edu/~jepson/csc420/notes/introSVD.pdf (page 6)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
737 ## (for matMN a n x n matrix that symetric and non-negative definite)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
738
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
739 #' square root of a matrix (Rocha)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
740 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
741 #' @param mat Matrix
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
742 #' @return A list
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
743 #' @author Natacha Lenuzza
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
744 #' @examples
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
745 #' print("hello !")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
746 #'
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
747 #' @export sqrtmF
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
748
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
749 sqrtmF <- function(matMN) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
750 matMN <- as.matrix(matMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
751 ## check that matMN is symetric: if (!all(t(matMN == matMN))) stop("matMN must be symetric.")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
752 svd_dec <- svd(matMN)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
753 invisible(svd_dec$u %*% sqrt(diag(svd_dec$d)) %*% t(svd_dec$v))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
754 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
755
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
756
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
757 ## qqplotF
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
758 ## adapted from https://gist.github.com/rentrop/d39a8406ad8af2a1066c
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
759
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
760 qqplotF <- function(x,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
761 distribution = "norm", ...,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
762 line.estimate = NULL,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
763 conf = 0.95,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
764 labels = names(x)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
765 q.function <- eval(parse(text = paste0("q", distribution)))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
766 d.function <- eval(parse(text = paste0("d", distribution)))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
767 x <- na.omit(x)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
768 ord <- order(x)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
769 n <- length(x)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
770 P <- ppoints(length(x))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
771 daf <- data.frame(ord.x = x[ord], z = q.function(P, ...))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
772 if (is.null(line.estimate)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
773 Q.x <- quantile(daf$ord.x, c(0.25, 0.75))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
774 Q.z <- q.function(c(0.25, 0.75), ...)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
775 b <- diff(Q.x) / diff(Q.z)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
776 coef <- c(Q.x[1] - b * Q.z[1], b)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
777 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
778 coef <- coef(line.estimate(ord.x ~ z))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
779 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
780 zz <- qnorm(1 - (1 - conf) / 2)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
781 SE <- (coef[2] / d.function(daf$z, ...)) * sqrt(P * (1 - P) / n)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
782 fit.value <- coef[1] + coef[2] * daf$z
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
783 daf$upper <- fit.value + zz * SE
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
784 daf$lower <- fit.value - zz * SE
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
785 if (!is.null(labels)) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
786 daf$label <- ifelse(daf$ord.x > daf$upper | daf$ord.x < daf$lower, labels[ord], "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
787 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
788 p <- ggplot(daf, aes(x = z, y = ord.x)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
789 geom_point() +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
790 geom_abline(intercept = coef[1], slope = coef[2], col = "red") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
791 geom_line(aes(x = z, y = lower), daf, col = "red", linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
792 geom_line(aes(x = z, y = upper), daf, col = "red", linetype = "dashed") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
793 xlab("") + ylab("")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
794 if (!is.null(labels)) p <- p + geom_text(aes(label = label))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
795 return(p)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
796 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
797
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
798
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
799 ## histogramm
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
800 histF <- function(x, sd_x = NULL, breaks = "scott") {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
801 if (is.null(sd_x))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
802 sd_x <- sd(x)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
803 ## Bandwith estimation (default is Scott)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
804 if (!breaks %in% c("sqrt", "sturges", "rice", "scott", "fd"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
805 breaks <- "scott"
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
806 if (breaks %in% c("sqrt", "sturges", "rice")) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
807 k <- switch(breaks,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
808 sqrt = sqrt(length(x)),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
809 sturges = floor(log2(x)) + 1,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
810 rice = floor(2 * length(x) ^ (1 / 3))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
811 )
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
812 bw <- diff(range(x)) / k
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
813 }else{
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
814 bw <- switch(breaks,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
815 scott = 3.5 * sd_x / length(x) ^ (1 / 3),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
816 fd = diff(range(x)) / (2 * IQR(x) / length(x) ^ (1 / 3))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
817 )
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
818 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
819
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
820
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
821 daf <- data.frame(x = x)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
822 ## graph
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
823 return(ggplot(data = daf, aes(x)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
824 geom_histogram(aes(y = ..density..),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
825 col = "black", fill = "grey", binwidth = bw) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
826 geom_density(size = 1.2,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
827 col = "blue",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
828 linetype = "blank",
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
829 fill = rgb(0, 0, 1, 0.1)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
830 stat_function(fun = dnorm,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
831 args = list(mean = 0, sd = sd_x),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
832 col = "blue", size = 1.2) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
833 theme(legend.position = "none") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
834 xlab(""))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
835 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
836
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
837
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
838 plot.res.Lmixed <- function(mfl, df, title = "", pvalCutof = 0.05) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
839
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
840 ## define subscript of the different columns depending if we have only time (ncol(df)=3) or not
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
841 if (ncol(df) > 3) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
842 varidx <- 4
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
843 ffidx <- 1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
844 timidx <- 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
845 individx <- 3
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
846 } else {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
847 varidx <- 3
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
848 ffidx <- 1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
849 timidx <- 1
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
850 individx <- 2
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
851 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
852 nameVar <- colnames(df)[varidx]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
853 fflab <- colnames(df)[ffidx]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
854 ## Individual time-course
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
855 rawPlot <-
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
856 ggplot(data = df, aes(x = df[[timidx]], y = df[[varidx]], colour = df[[ffidx]], group = df[[individx]])) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
857 geom_point() +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
858 geom_line() + ggtitle("Individual time-courses (raw data)") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
859 ylab(nameVar) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
860 xlab(label = colnames(df)[2]) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
861 theme(legend.title = element_blank(), legend.position = "none", plot.title = element_text(size = rel(1.2), face = "bold"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
862 ## Boxplot of fixed factor
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
863 bPlot <-
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
864 ggplot(data = df, aes(y = df[[varidx]], x = df[[ffidx]], color = df[[ffidx]])) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
865 geom_boxplot(outlier.colour = "red", outlier.shape = 8, outlier.size = 4) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
866 ggtitle(paste("Boxplot by ", fflab, sep = "")) + xlab("") + ylab("") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
867 theme(legend.title = element_blank(), plot.title = element_text(size = rel(1.2), face = "bold"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
868 ## Post-hoc estimates
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
869 ddlsm1 <- mfl
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
870 ddlsm1$name <- rownames(ddlsm1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
871 ddlsm1$Significance <- rep("NS", nrow(ddlsm1))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
872 ## modif JF pour tenir compte du seuil de pvalues defini par le user
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
873 options("scipen" = 100, "digits" = 5)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
874 pvalCutof <- as.numeric(pvalCutof)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
875 bs <- 0.05; bm <- 0.01; bi <- 0.005
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
876 if (pvalCutof > bm) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
877 bs <- pvalCutof
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
878 } else
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
879 if (pvalCutof < bm & pvalCutof > bi) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
880 bm <- pvalCutof; bs <- pvalCutof
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
881 } else
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
882 if (pvalCutof < bi) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
883 bi <- pvalCutof; bm <- pvalCutof; bs <- pvalCutof
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
884 }
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
885 lbs <- paste("p-value < ", bs, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
886 lbm <- paste("p-value < ", bm, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
887 lbi <- paste("p-value < ", bi, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
888 cols <- paste("p-value < ", bs, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
889 colm <- paste("p-value < ", bm, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
890 coli <- paste("p-value < ", bi, sep = "")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
891 valcol <- c("grey", "yellow", "orange", "red")
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
892 names(valcol) <- c("NS", lbs, lbm, lbi)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
893 ddlsm1$Significance[which(ddlsm1$p.value <= bs)] <- lbs
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
894 ddlsm1$Significance[which(ddlsm1$p.value < bs & ddlsm1$p.value >= bm)] <- lbm
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
895 ddlsm1$Significance[which(ddlsm1$p.value < bi)] <- lbi
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
896 ddlsm1$levels <- rownames(ddlsm1)
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
897 ddlsm1$term <- sapply(rownames(ddlsm1), function(namC) {
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
898 strsplit(namC, split = " ", fixed = TRUE)[[1]][1]
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
899 })
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
900
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
901 phPlot <-
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
902 ggplot(ddlsm1, aes(x = levels, y = Estimate)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
903 facet_grid(facets = ~term, ddlsm1, scales = "free", space = "free") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
904 geom_bar(aes(fill = Significance), stat = "identity") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
905 theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
906 scale_fill_manual(
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
907 values = valcol) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
908 geom_errorbar(aes(ymin = Lower.CI, ymax = Upper.CI), width = 0.25) +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
909 ggtitle("Post-hoc estimates ") + xlab("") +
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
910 theme(plot.title = element_text(size = rel(1.2), face = "bold"))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
911
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
912 ## Final plotting
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
913 grid.arrange(arrangeGrob(rawPlot, bPlot, ncol = 2),
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
914 phPlot, nrow = 2,
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
915 top = textGrob(title, gp = gpar(fontsize = 32, font = 4))
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
916 )
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
917
a4d89d47646f planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 8d2ca678d973501b60479a8dc3f212eecd56eab8
workflow4metabolomics
parents:
diff changeset
918 }