-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathREADME.Rmd
177 lines (129 loc) · 5.34 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.width = 8, fig.height = 8,
cache.path = "man/cache/README-",
out.width = "50%"
)
```
# lme4qtl
<!-- badges: start -->
[![travis-ci build status](https://travis-ci.org/variani/lme4qtl.svg?branch=master)](https://travis-ci.org/variani/lme4qtl)
<!-- badges: end -->
`lme4qtl` extends the [lme4](https://github.com/lme4/lme4) R package for quantitative trait locus (qtl) mapping. It is all about the covariance structure of random effects. `lme4qtl` supports user-defined matrices for that,
e.g. kinship or IBDs.
See slides [bit.ly/1UiTZvQ](http://bit.ly/1UiTZvQ) introducing the `lme4qtl` R package or read our [article](http://dx.doi.org/10.1186/s12859-018-2057-x) / [preprint](http://www.biorxiv.org/content/early/2017/08/31/139816).
| Package | Continuous response |
|----------|---------------------|
| stats | `lm(myTrait ~ myCovariate, myData)` |
| lme4 | `lmer(myTrait ~ myCovariate + (1|myID), myData)` |
| lme4qtl | `relmatLmer(myTrait ~ myCovariate + (1|myID), myData, relmat = list(myID = myMatrix))` |
| Package | Binary response |
|----------|---------------------|
| stats | `glm(myStatus ~ 1, myData, family = binomial)` |
| lme4 | `glmer(myStatus ~ (1|myID), myData, family = binomial)` |
| lme4qtl | `relmatGlmer(myStatus ~ (1|myID), myData, relmat = list(myID = myMatrix), family = binomial)` |
Note that rownames/colnames of `myMatrix` have to be values of `myID` variable, so matching between relationship matrix and grouping variable is possible. The order [doesn't matter](https://github.com/variani/lme4qtl/issues/3#issuecomment-346905978).
## Installation
You can install the development version from [GitHub](https://github.com/variani/lme4qtl) with:
``` r
# install.packages("devtools")
devtools::install_github("variani/lme4qtl")
```
The official release on [CRAN](https://CRAN.R-project.org) is [pending](https://github.com/variani/lme4qtl/issues/9).
## Citation
To cite the `lme4qtl` package in publications use:
```
Ziyatdinov et al., lme4qtl: linear mixed models with flexible
covariance structure for genetic studies of related individuals,
BMC Bioinformatics (2018)
```
## Contact
You are welcome to submit suggestions and bug-reports at https://github.com/variani/lme4qtl/issues.
## Related projects
- fastGWA/GCTA tool for large-scale association studies (e.g. UKB) and based on sparse GRM; [bioarxiv](https://www.biorxiv.org/content/10.1101/598110v1)
- [GENESIS](https://bioconductor.org/packages/release/bioc/html/GENESIS.html) Bioconductor R package
## Example
```{r ex_inc}
library(lme4)
library(lattice)
```
```{r ex_inc2, eval = FALSE}
library(lme4qtl)
```
```{r ex_inc3, echo = FALSE, message = F}
load_all()
```
```{r pkg_ver}
packageVersion("lme4qtl")
```
Load simulated data, phenotypes `dat40` and the kinship matrix `kin2`.
```{r ex_data}
data(dat40, package = "lme4qtl")
dim(dat40)
dim(kin2)
head(dat40)
kin2[1:5, 1:5] # nuclear family with 2 parents and 3 kids
```
Fit a model for continuous trait with two random effects,
family-grouping `(1|FAM)` and additive genetic `(1|ID)`.
```{r ex_fit1}
m1 <- relmatLmer(trait1 ~ AGE + SEX + (1|FAMID) + (1|ID), dat40, relmat = list(ID = kin2))
m1
```
Get a point estimate of heritability (h2), the proportion of variance explained by `(1|ID)`.
```{r ex_h2}
lme4::VarCorr(m1)
lme4qtl::VarProp(m1)
```
Profile the variance components (h2) to get the 95% confidence intervals.
The method functions `profile` and `confint` are implemented in lme4.
Note that a different model `m2` is used,
because profiling is prone to errors/warnings if model fit is poor.
```{r ex_prof, cache = T}
m2 <- relmatLmer(trait2 ~ (1|ID), dat40, relmat = list(ID = kin2))
VarProp(m2)
prof <- profile(m2)
prof_prop <- lme4qtl::varpropProf(prof) # convert to proportions
confint(prof_prop)
```
```{r plot_prof, fig.width = 8, fig.height = 4}
densityplot(prof)
densityplot(prof_prop)
```
```{r plot_prof_splom}
try(splom(prof))
prof_clean <- na.omit(prof) # caution: NAs are indicators of poor fits
splom(prof_clean)
```
Fit a model with genetic and residual variances that differ by gender (sex-specificity model).
The formula syntax with `dummy` (see `?lme4::dummy`) is applied to the residual variance `(1|RID)`
to cancel the residual correlation.
```{r gxe, cache = T}
dat40 <- within(dat40, RID <- ID) # replicate ID
m4 <- relmatLmer(trait2 ~ SEX + (0 + SEX|ID) + (0 + dummy(SEX)|RID), dat40, relmat = list(ID = kin2))
VarCorr(m4)
```
An example of parameter constraints that make the genetic variance between genders equal.
```{r gex_eq, cache = T}
m4_vareq <- relmatLmer(trait2 ~ SEX + (0 + SEX|ID) + (0 + dummy(SEX)|RID), dat40, relmat = list(ID = kin2),
vcControl = list(vareq = list(id = c(1, 2, 3))))
VarCorr(m4_vareq)
```
Another example of parameter constraint that implies the genetic correlation between genders equal to 1.
```{r gxe_rho1, cache = T}
m4_rhog1 <- relmatLmer(trait2 ~ SEX + (0 + SEX|ID) + (0 + dummy(SEX)|RID), dat40, relmat = list(ID = kin2),
vcControl = list(rho1 = list(id = 3)))
VarCorr(m4_rhog1)
```
Fit a model for binary trait.
```{r ex_fit3, cache = T}
m3 <- relmatGlmer(trait1bin ~ (1|ID), dat40, relmat = list(ID = kin2), family = binomial(probit))
m3
```