Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

VarCorr

Extract Variance and Correlation Components


Description

This function calculates the estimated variances, standard deviations, and correlations between the random-effects terms in a mixed-effects model, of class merMod (linear, generalized or nonlinear). The within-group error variance and standard deviation are also calculated.

Usage

## S3 method for class 'merMod'
VarCorr(x, sigma=1, ...)


## S3 method for class 'VarCorr.merMod'
as.data.frame(x, row.names = NULL,
              optional = FALSE, order = c("cov.last", "lower.tri"), ...)
## S3 method for class 'VarCorr.merMod'
print(x, digits = max(3, getOption("digits") - 2),
      comp = "Std.Dev.", formatter = format, ...)

Arguments

x

for VarCorr: a fitted model object, usually an object inheriting from class merMod. For as.data.frame, a VarCorr.merMod object returned from VarCorr.

sigma

an optional numeric value used as a multiplier for the standard deviations.

digits

an optional integer value specifying the number of digits

order

arrange data frame with variances/standard deviations first and covariances/correlations last for each random effects term ("cov.last"), or in the order of the lower triangle of the variance-covariance matrix ("lower.tri")?

row.names, optional

Ignored: necessary for the as.data.frame method.

...

Ignored for the as.data.frame method; passed to other print() methods for the print() method.

comp

a character vector, specifying the components to be printed; simply passed to formatVC().

formatter

a function for formatting the numbers; simply passed to formatVC().

Details

The print method for VarCorr.merMod objects has optional arguments digits (specify digits of precision for printing) and comp: the latter is a character vector with any combination of "Variance" and "Std.Dev.", to specify whether variances, standard deviations, or both should be printed.

Value

An object of class VarCorr.merMod. The internal structure of the object is a list of matrices, one for each random effects grouping term. For each grouping term, the standard deviations and correlation matrices for each grouping term are stored as attributes "stddev" and "correlation", respectively, of the variance-covariance matrix, and the residual standard deviation is stored as attribute "sc" (for glmer fits, this attribute stores the scale parameter of the model).

The as.data.frame method produces a combined data frame with one row for each variance or covariance parameter (and a row for the residual error term where applicable) and the following columns:

grp

grouping factor

var1

first variable

var2

second variable (NA for variance parameters)

vcov

variances or covariances

sdcor

standard deviations or correlations

Author(s)

This is modeled after VarCorr from package nlme, by Jose Pinheiro and Douglas Bates.

See Also

Examples

data(Orthodont, package="nlme")
fm1 <- lmer(distance ~ age + (age|Subject), data = Orthodont)
(vc <- VarCorr(fm1))  ## default print method: standard dev and corr
## both variance and std.dev.
print(vc,comp=c("Variance","Std.Dev."),digits=2)
## variance only
print(vc,comp=c("Variance"))
as.data.frame(vc)
as.data.frame(vc,order="lower.tri")

lme4

Linear Mixed-Effects Models using 'Eigen' and S4

v1.1-26
GPL (>= 2)
Authors
Douglas Bates [aut] (<https://orcid.org/0000-0001-8316-9503>), Martin Maechler [aut] (<https://orcid.org/0000-0002-8685-9910>), Ben Bolker [aut, cre] (<https://orcid.org/0000-0002-2127-0443>), Steven Walker [aut] (<https://orcid.org/0000-0002-4394-9078>), Rune Haubo Bojesen Christensen [ctb] (<https://orcid.org/0000-0002-4494-3399>), Henrik Singmann [ctb] (<https://orcid.org/0000-0002-4842-3657>), Bin Dai [ctb], Fabian Scheipl [ctb] (<https://orcid.org/0000-0001-8172-3603>), Gabor Grothendieck [ctb], Peter Green [ctb] (<https://orcid.org/0000-0002-0238-9852>), John Fox [ctb], Alexander Bauer [ctb], Pavel N. Krivitsky [ctb, cph] (<https://orcid.org/0000-0002-9101-3362>, shared copyright on simulate.formula)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.