glmmSeq | R Documentation |
Fits many generalised linear mixed effects models (GLMM) with negative binomial distribution for analysis of overdispersed count data with random effects. Designed for longitudinal analysis of RNA-Sequencing count data.
glmmSeq( modelFormula, countdata, metadata, id = NULL, dispersion = NA, sizeFactors = NULL, reduced = NULL, modelData = NULL, designMatrix = NULL, method = c("lme4", "glmmTMB"), control = NULL, family = nbinom2, cores = 1, removeSingles = FALSE, zeroCount = 0.125, verbose = TRUE, returnList = FALSE, progress = FALSE, ... )
modelFormula |
the model formula. This must be of the form |
countdata |
the sequencing count data matrix with genes in rows and samples in columns |
metadata |
a dataframe of sample information with variables in columns and samples in rows |
id |
Optional. Used to specify the column in metadata which contains the sample IDs to be used in repeated samples for random effects. If not specified, the function defaults to using the variable after the "|" in the random effects term in the formula. |
dispersion |
a numeric vector of gene dispersion. Not required for
|
sizeFactors |
size factors (default = NULL). If provided the |
reduced |
Optional reduced model formula. If this is chosen, a likelihood ratio test is used to calculate p-values instead of the default Wald type 2 Chi-squared test. |
modelData |
Optional dataframe. Default is generated by call to
|
designMatrix |
custom design matrix, used only for prediction |
method |
Specifies which package to use for fitting GLMM models. Either "lme4" or "glmmTMB" depending on whether to use lme4::glmer or glmmTMB::glmmTMB to fit GLMM models. |
control |
the |
family |
Only used with |
cores |
number of cores to use. Default = 1. |
removeSingles |
whether to remove individuals without repeated measures (default = FALSE) |
zeroCount |
numerical value to offset zeroes for the purpose of log (default = 0.125) |
verbose |
Logical whether to display messaging (default = TRUE) |
returnList |
Logical whether to return results as a list or |
progress |
Logical whether to display a progress bar |
... |
Other parameters to pass to
|
This function is a wrapper for lme4::glmer()
. By default, p-values for each
model term are computed using Wald type 2 Chi-squared test as per
car::Anova()
. The underlying code for this has been optimised for speed.
However, if a reduced model formula is specified by setting reduced
, then a
likelihood ratio test is performed instead using stats::anova. This will
double computation time since two GLMM have to be fitted.
Parallelisation is provided using parallel::mclapply on Unix/Mac or parallel::parLapply on PC.
Setting method = "glmmTMB"
enables an alternative method of fitting GLMM
using the glmmTMB
package. This gives access to a variety of alternative
GLM family functions. Note, glmmTMB
negative binomial models are
substantially slower to fit than glmer
models with known dispersion due to
the extra time taken by glmmTMB
to optimise the dispersion parameter.
The id
argument is usually optional. By default the id
column in the
metadata is determined as the term after the bar in the random effects term
of the model. Note that id
is not passed to glmer
or glmmTMB
. It is
only really used to remove singletons from the countdata
matrix and
metadata
dataframe. The id
is also stored in the output from glmmSeq
and used by plotting function modelPlot()
. However, due to its flexible
nature, in theory glmmSeq
should allow for more than one random effect
term, although this has not been tested formally. In this case, it is
probably prudent to specify a value for id
.
Returns an S4 class GlmmSeq
object with results for gene-wise
general linear mixed models. A list of results is returned if returnList
is TRUE
which is useful for debugging. If all genes return errors from
glmer
, then an error message is shown and a character vector containing
error messages for all genes is returned.
lme4::glmer lme4::glmerControl glmmTMB::glmmTMB glmmTMB::nbinom2 glmmTMB::glmmTMBControl car::Anova
data(PEAC_minimal_load) disp <- apply(tpm, 1, function(x) { (var(x, na.rm = TRUE)-mean(x, na.rm = TRUE))/(mean(x, na.rm = TRUE)**2) }) MS4A1glmm <- glmmSeq(~ Timepoint * EULAR_6m + (1 | PATID), countdata = tpm[1:2, ], metadata = metadata, dispersion = disp, verbose = FALSE) names(attributes(MS4A1glmm))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.