1
1
# ## install
2
2
# library(devtools)
3
3
# install_github("variani/matlm")
4
- # install_github("variani/gls ")
4
+ # install_github("variani/wlm ")
5
5
# install_github("variani/qq")
6
+ #
7
+ # re-install lme4qtl if necessary (e.g. for `varcov` fun. was not exported prev.)
6
8
# install_github("variani/lme4qtl")
7
9
8
10
# ## inc
@@ -13,7 +15,7 @@ library(ggplot2)
13
15
library(lme4qtl )
14
16
# for Step 2: association tests
15
17
library(matlm )
16
- library(gls )
18
+ library(wlm )
17
19
# for Step 3: explore GWAS results
18
20
library(qq )
19
21
@@ -25,11 +27,12 @@ data(dat40, package = "lme4qtl")
25
27
N <- nrow(dat40 ) # the number of ind.
26
28
ids <- dat40 $ ID # individual IDs
27
29
28
- # simulate (null) random genotypes (0/1 with 50% prob.)
30
+ # simulate (null) random genotypes (0/1 with 50% prob.; not linked to `kin2`
29
31
gdat40 <- matrix (rbinom(N * M , 1 , 0.5 ), nrow = N , ncol = M )
30
32
rownames(gdat40 ) <- ids
31
33
colnames(gdat40 ) <- paste0(" snp" , seq(1 , ncol(gdat40 )))
32
34
35
+ # simulate (null) random cont. predictors (linked to `kin2`) by MVN ~ (0, kin2)
33
36
pdat40 <- t(mvrnorm(M , rep(0 , N ), kin2 ))
34
37
rownames(gdat40 ) <- ids
35
38
colnames(gdat40 ) <- paste0(" pred" , seq(1 , ncol(gdat40 )))
@@ -40,6 +43,9 @@ colnames(gdat40) <- paste0("pred", seq(1, ncol(gdat40)))
40
43
# - extract variance-covariance matrix `V`
41
44
# -----------------------------------------------
42
45
mod <- lme4qtl :: relmatLmer(trait1 ~ AGE + (1 | FAMID ) + (1 | ID ), dat40 , relmat = list (ID = kin2 ))
46
+ # in case of convergence problems, one might try/experiment with:
47
+ # - relmatLmer(trait1 ~ AGE + (1|FAMID) + (1|ID), dat40, relmat = list(ID = kin2), calc.derivs = FALSE)
48
+ # - relmatLmer(trait1 ~ AGE + (1|FAMID) + (1|ID), dat40, relmat = list(ID = kin2), calc.derivs = FALSE, control = lmerControl(optimizer = "bobyqa", check.conv.grad = list(action = "warning", tol = 0.005, relTol = NULL)))
43
49
44
50
V <- lme4qtl :: varcov(mod , idvar = " ID" )
45
51
@@ -55,11 +61,11 @@ Matrix::image(V_thr[1:20, 1:20], main = "Estimated V (with artifacts removed)")
55
61
# - perform association test on M predictors
56
62
# - examimed several combinations:
57
63
# - linear models (least squares) vs. generalized least squares that takes V as input
58
- # - binary genotypes (simulated with no structure) vs. cont. predictors (simultaed as ~ MVN(0, kin2))
64
+ # - binary genotypes (simulated with no structure) vs. cont. predictors
59
65
# -------
60
66
# transformation on data (due to structure in V) needs to be computed once
61
67
# (note: EVD (not Cholesky) is required; otherwise, missing data would produce messy results)
62
- decomp <- gls :: decompose_varcov(V , method = " evd" , output = " all" )
68
+ decomp <- wlm :: decompose_varcov(V , method = " evd" , output = " all" )
63
69
W <- decomp $ transform
64
70
65
71
gassoc_lm <- matlm :: matlm(trait1 ~ AGE , dat40 , pred = gdat40 , ids = ids ,
@@ -75,13 +81,17 @@ passoc_gls <- matlm::matlm(trait1 ~ AGE, dat40, pred = pdat40, ids = ids, transf
75
81
# -------
76
82
# Step 3:
77
83
# - QQ plots
78
- # - the first two plots shows that both LS & LMM/WLS approches gives valid results,
84
+ # - the first two plots shows that both LS & LMM/WLS approches give valid results,
79
85
# because binary genotype predictors (gdat40) were simulated without any link to
80
86
# data structure in kin2
81
- # - the last plots shows that LMM/GWAS produced a valid distribution of p-values
87
+ # - the last plots shows that LMM/GWAS produces a valid distribution of p-values,
88
+ # while LS shows an inflated Type I error rate
82
89
# -------
83
- qq : qq_plot(gassoc_lm $ tab $ pval ) + ggtitle(" LS: (null) random binary genotypes (not linked to kin2)" )
84
- qq : qq_plot(gassoc_gls $ tab $ pval ) + ggtitle(" LMM/WLS: (null) random binary genotypes (not linked to kin2)" )
90
+ qq :: qq_plot(gassoc_lm $ tab $ pval ) + ggtitle(" LS: (null) random binary genotypes (not linked to kin2)" )
91
+ qq :: qq_plot(gassoc_gls $ tab $ pval ) + ggtitle(" LMM/WLS: (null) random binary genotypes (not linked to kin2)" )
92
+
93
+ qq :: qq_plot(passoc_lm $ tab $ pval ) + ggtitle(" LS: (null) random cont. predictors (linked to kin2)" )
94
+ qq :: qq_plot(passoc_gls $ tab $ pval ) + ggtitle(" LMM/WLS: (null) random cont. predictors (linked to kin2)" )
95
+
96
+
85
97
86
- qq : qq_plot(passoc_lm $ tab $ pval ) + ggtitle(" LS: (null) random cont. predictors (linked to kin2)" )
87
- qq : qq_plot(passoc_gls $ tab $ pval ) + ggtitle(" LMM/WLS: (null) random cont. predictors (linked to kin2)" )
0 commit comments