Description Usage Arguments Details Value Examples
Fit linear (mixed) model to estimate contribution of multiple sources of variation while simultaneously correcting for all other variables. Report fraction of variance attributable to each variable
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 | fitExtractVarPartModel(
exprObj,
formula,
data,
REML = FALSE,
useWeights = TRUE,
weightsMatrix = NULL,
showWarnings = TRUE,
control = lme4::lmerControl(calc.derivs = FALSE, check.rankX = "stop.deficient"),
quiet = FALSE,
BPPARAM = bpparam(),
...
)
## S4 method for signature 'matrix'
fitExtractVarPartModel(
exprObj,
formula,
data,
REML = FALSE,
useWeights = TRUE,
weightsMatrix = NULL,
showWarnings = TRUE,
control = lme4::lmerControl(calc.derivs = FALSE, check.rankX = "stop.deficient"),
quiet = FALSE,
BPPARAM = bpparam(),
...
)
## S4 method for signature 'data.frame'
fitExtractVarPartModel(
exprObj,
formula,
data,
REML = FALSE,
useWeights = TRUE,
weightsMatrix = NULL,
showWarnings = TRUE,
control = lme4::lmerControl(calc.derivs = FALSE, check.rankX = "stop.deficient"),
quiet = FALSE,
BPPARAM = bpparam(),
...
)
## S4 method for signature 'EList'
fitExtractVarPartModel(
exprObj,
formula,
data,
REML = FALSE,
useWeights = TRUE,
weightsMatrix = NULL,
showWarnings = TRUE,
control = lme4::lmerControl(calc.derivs = FALSE, check.rankX = "stop.deficient"),
quiet = FALSE,
BPPARAM = bpparam(),
...
)
## S4 method for signature 'ExpressionSet'
fitExtractVarPartModel(
exprObj,
formula,
data,
REML = FALSE,
useWeights = TRUE,
weightsMatrix = NULL,
showWarnings = TRUE,
control = lme4::lmerControl(calc.derivs = FALSE, check.rankX = "stop.deficient"),
quiet = FALSE,
BPPARAM = bpparam(),
...
)
## S4 method for signature 'sparseMatrix'
fitExtractVarPartModel(
exprObj,
formula,
data,
REML = FALSE,
useWeights = TRUE,
weightsMatrix = NULL,
showWarnings = TRUE,
control = lme4::lmerControl(calc.derivs = FALSE, check.rankX = "stop.deficient"),
quiet = FALSE,
BPPARAM = bpparam(),
...
)
|
exprObj |
matrix of expression data (g genes x n samples), or |
formula |
specifies variables for the linear (mixed) model. Must only specify covariates, since the rows of exprObj are automatically used a a response. e.g.: |
data |
|
REML |
use restricted maximum likelihood to fit linear mixed model. default is FALSE. See Details. |
useWeights |
if TRUE, analysis uses heteroskedastic error estimates from |
weightsMatrix |
matrix the same dimension as exprObj with observation-level weights from |
showWarnings |
show warnings about model fit (default TRUE) |
control |
control settings for |
quiet |
suppress message, default FALSE |
BPPARAM |
parameters for parallel evaluation |
... |
Additional arguments for |
A linear (mixed) model is fit for each gene in exprObj, using formula to specify variables in the regression. If categorical variables are modeled as random effects (as is recommended), then a linear mixed model us used. For example if formula is ~ a + b + (1|c)
, then the model is
fit <- lmer( exprObj[j,] ~ a + b + (1|c), data=data)
If there are no random effects, so formula is ~ a + b + c, a 'standard' linear model is used:
fit <- lm( exprObj[j,] ~ a + b + c, data=data)
In both cases, useWeights=TRUE
causes weightsMatrix[j,]
to be included as weights in the regression model.
Note: Fitting the model for 20,000 genes can be computationally intensive. To accelerate computation, models can be fit in parallel using BiocParallel
to run in parallel. Parallel processing must be enabled before calling this function. See below.
The regression model is fit for each gene separately. Samples with missing values in either gene expression or metadata are omitted by the underlying call to lm
/lmer
.
REML=FALSE
uses maximum likelihood to estimate variance fractions. This approach produced unbiased estimates, while REML=TRUE
can show substantial bias. See Vignette "3) Theory and practice of random effects and REML"
list() of where each entry is a model fit produced by lmer()
or lm()
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 | # load library
# library(variancePartition)
# Intialize parallel backend with 4 cores
library(BiocParallel)
register(SnowParam(4))
# load simulated data:
# geneExpr: matrix of gene expression values
# info: information/metadata about each sample
data(varPartData)
# Specify variables to consider
# Age is continuous so we model it as a fixed effect
# Individual and Tissue are both categorical, so we model them as random effects
form <- ~ Age + (1|Individual) + (1|Tissue)
# Step 1: fit linear mixed model on gene expression
# If categorical variables are specified, a linear mixed model is used
# If all variables are modeled as continuous, a linear model is used
# each entry in results is a regression model fit on a single gene
# Step 2: extract variance fractions from each model fit
# for each gene, returns fraction of variation attributable to each variable
# Interpretation: the variance explained by each variable
# after correction for all other variables
varPart <- fitExtractVarPartModel( geneExpr, form, info )
# violin plot of contribution of each variable to total variance
plotVarPart( sortCols( varPart ) )
# Note: fitExtractVarPartModel also accepts ExpressionSet
data(sample.ExpressionSet, package="Biobase")
# ExpressionSet example
form <- ~ (1|sex) + (1|type) + score
info2 <- pData(sample.ExpressionSet)
varPart2 <- fitExtractVarPartModel( sample.ExpressionSet, form, info2 )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.