Description Usage Arguments Details Value Note References Examples
View source: R/get_variances.R
This function extracts the different variance components of a
mixed model and returns the result as list. Functions like
get_variance_residual(x)
or get_variance_fixed(x)
are shortcuts
for get_variance(x, component = "residual")
etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  get_variance(
x,
component = c("all", "fixed", "random", "residual", "distribution", "dispersion",
"intercept", "slope", "rho01"),
verbose = TRUE,
...
)
get_variance_residual(x, ...)
get_variance_fixed(x, ...)
get_variance_random(x, ...)
get_variance_distribution(x, ...)
get_variance_dispersion(x, ...)
get_variance_intercept(x, ...)
get_variance_slope(x, ...)
get_correlation_slope_intercept(x, ...)

x 
A mixed effects model. 
component 
Character value, indicating the variance component that should
be returned. By default, all variance components are returned. The
distributionspecific ( 
verbose 
Toggle off warnings. 
... 
Currently not used. 
This function returns different variance components from mixed models, which are needed, for instance, to calculate rsquared measures or the intraclasscorrelation coefficient (ICC).
The fixed effects variance, σ^{2}_{f}, is the variance of the matrixmultiplication β∗X (parameter vector by model matrix).
The random effect variance, σ^{2}_{i}, represents the mean random effect variance of the model. Since this variance reflect the "average" random effects variance for mixed models, it is also appropriate for models with more complex random effects structures, like random slopes or nested random effects. Details can be found in Johnson 2014, in particular equation 10. For simple randomintercept models, the random effects variance equals the randomintercept variance.
The distributionspecific variance,
σ^{2}_{d},
depends on the model family. For Gaussian models, it is
σ^{2} (i.e.
sigma(model)^2
). For models with binary outcome, it is
π^2 / 3 for logitlink, 1
for probitlink, and π^2 / 6
for clogloglinks. Models from Gammafamilies use μ^2 (as obtained
from family$variance()
). For all other models, the distributionspecific
variance is based on lognormal approximation, log(1 + var(x) / μ^2)
(see Nakagawa et al. 2017). The expected variance of a zeroinflated
model is computed according to Zuur et al. 2012, p277.
The variance for the additive overdispersion term,
σ^{2}_{e},
represents “the excess variation relative to what is expected
from a certain distribution” (Nakagawa et al. 2017). In (most? many?)
cases, this will be 0
.
The residual variance, σ^{2}_{ε}, is simply σ^{2}_{d} + σ^{2}_{e}.
The random intercept variance, or betweensubject variance
(τ_{00}),
is obtained from VarCorr()
. It indicates how much groups
or subjects differ from each other, while the residual variance
σ^{2}_{ε}
indicates the withinsubject variance.
The random slope variance (τ_{11})
is obtained from VarCorr()
. This measure is only available
for mixed models with random slopes.
The random slopeintercept correlation
(ρ_{01})
is obtained from VarCorr()
. This measure is only available
for mixed models with random intercepts and slopes.
A list with following elements:
var.fixed
, variance attributable to the fixed effects
var.random
, (mean) variance of random effects
var.residual
, residual variance (sum of dispersion and distribution)
var.distribution
, distributionspecific variance
var.dispersion
, variance due to additive dispersion
var.intercept
, the randominterceptvariance, or betweensubjectvariance (τ_{00})
var.slope
, the randomslopevariance (τ_{11})
cor.slope_intercept
, the randomslopeinterceptcorrelation (ρ_{01})
This function supports models of class merMod
(including models
from blme), clmm
, cpglmm
, glmmadmb
, glmmTMB
,
MixMod
, lme
, mixed
, rlmerMod
, stanreg
,
brmsfit
or wbm
. Support for objects of class MixMod
(GLMMadaptiv), lme
(nlme) or brmsfit
(brms)
is experimental and may not work for all models.
Johnson, P. C. D. (2014). Extension of Nakagawa & Schielzeth’s R2 GLMM to random slopes models. Methods in Ecology and Evolution, 5(9), 944–946. doi: 10.1111/2041210X.12225
Nakagawa, S., Johnson, P. C. D., & Schielzeth, H. (2017). The coefficient of determination R2 and intraclass correlation coefficient from generalized linear mixedeffects models revisited and expanded. Journal of The Royal Society Interface, 14(134), 20170213. doi: 10.1098/rsif.2017.0213
Zuur, A. F., Savel'ev, A. A., & Ieno, E. N. (2012). Zero inflated models and generalized linear mixed models with R. Newburgh, United Kingdom: Highland Statistics.
1 2 3 4 5 6 7 8 9 10  ## Not run:
library(lme4)
data(sleepstudy)
m < lmer(Reaction ~ Days + (1 + Days  Subject), data = sleepstudy)
get_variance(m)
get_variance_fixed(m)
get_variance_residual(m)
## End(Not run)

Loading required package: Matrix
$var.fixed
[1] 908.9534
$var.random
[1] 1698.233
$var.residual
[1] 654.9408
$var.distribution
[1] 654.9408
$var.dispersion
[1] 0
$var.intercept
Subject
611.8976
$var.slope
Subject.Days
35.08107
$cor.slope_intercept
Subject
0.06561803
var.fixed
908.9534
var.residual
654.9408
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.