MegaLMM is a package for fitting multi-trait linear mixed models (MvLMMs) with multiple random effects based on the paper available here:
Please treat this as a Beta version and let me know of issues running the functions.
devtools::install_github('deruncie/MegaLMM')
Note: the package requires OpenMP which causes problems on a Mac. I was able to get everything to run by following these instructions: https://mac.r-project.org/openmp/ including the addition to ~/.R/Makevars
. Installing on Unix-like machines and maybe Windows should cause fewer problems.
Please see the vignette MultiEnvironmentTrial.Rmd
for an introduction to using MegaLMM. This will apply MegaLMM to the analysis of a very incomplete multi-environment trial, and go through many of the key functions in the package
You can simply download the .Rmd file above and run it yourself. If you would like to build the vignette, do:
devtools::install_github('deruncie/MegaLMM', build_opts = c("--no-resave-data", "--no-manual"),force = TRUE,build_vignettes = TRUE)
vignette(topic = 'MultiEnvironmentTrial',package='MegaLMM')
MegaLMM implements multivariate linear mixed models of the form:
= XB + Z_1 U_1 + Z_2 U_2 + ... + E Y
where Y
is a n x t
matrix of observations for n
individuals and t
traits, X
is a design matrix for b
fixed effects (including an intercept), Z_1
through Z_m
are design matrices for m
random effects, and E
is a n x t
matrix of residual errors. The random effects are U_1
through U_m
are mutually independent of eachother and the residuals, but columns of each U_1
matrix can be correlated, and each column vector marginally follows a multivariate normal distribution with a known covariance matrix K_m
.
MvLMMs like this are notoriously difficult to fit. We address this by re-paramterizing the MvLMM as a mixed effect factor model:
= F Lambda + X B_r + Z_1 U_r1 + Z_2 U_r2 + ... + E_r
Y = X B_f + Z_1 U_f1 + Z_2 U_f2 + ... + E_f F
where F
is a n x k
matrix of latent factor traits and Lambda
is a k x t
matrix of factor loadings. This is the model actually fit by MegaLMM. For full details, please see the accompanying paper.
Figure 1 from Runcie et al 2021.
The unique aspects of MegaLMM relative to other factor models are:
Y
after accounting for the factors are not assumed to be iid, but are modeled with independent (across traits) LMMs accounting for both fixed and random effects.