vcov_vc: Asymptotic Covariance Matrix for Random Effects

Description Usage Arguments Details Value See Also Examples

View source: R/vcov_vc.R

Description

Return the asymptotic covariance matrix of random effect standard deviations (or variances) for a fitted model object, using the Hessian evaluated at the (restricted) maximum likelihood estimates.

Usage

1
vcov_vc(x, sd_cor = TRUE, print_names = TRUE)

Arguments

x

A fitted merMod object from lmer.

sd_cor

Logical indicating whether to return asymptotic covariance matrix on SD scale (if TRUE) or on variance scale (if FALSE).

print_names

Logical, whether to print the names for the covariance matrix.

Details

Although it's easy to obtain the Hessian for θ, the relative Cholesky factor, in lme4, there is no easy way to obtain the Hessian for the variance components. This function uses devfun_mer() to obtain the Hessian (H) of variance components (or standard deviations, SD), and then obtain the asymptotic covariance matrix as -2 H^{-1}.

Value

A (q + 1) * (q + 1) symmetric matrix of the covariance matrix of (τ, σ) (if sd_cor = TRUE) or (τ^2, σ^2) (if sd_cor = FALSE), where q is the the number of estimated random-effects components (excluding σ). For example, for a model with random slope, τ = (intercept SD, intercept-slope correlation, slope SD).

See Also

vcov.merMod for covariance matrix of fixed effects, confint.merMod for confidence intervals of all parameter estimates, and devfun_mer for the underlying function to produce the deviance function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(lme4)
data(Orthodont, package = "nlme")
fm1 <- lmer(distance ~ age + (age | Subject), data = Orthodont)
vc <- VarCorr(fm1)
# Standard deviation only
print(vc, comp = c("Std.Dev"))
# Asymptotic variance-covariance matrix of (tau, sigma):
vcov_vc(fm1, sd_cor = TRUE)

## Not run: 
#' # Compare with (parametric) bootstrap results :
get_sdcor <- function(x) {
  as.data.frame(lme4::VarCorr(x), order = "lower.tri")[ , "sdcor"]
}
boo <- bootstrap_mer(fm1, get_sdcor, type = "parametric", nsim = 200L)
# There might be failures in some resamples
cov(boo$t, use = "complete.obs")

## End(Not run)

marklhc/bootmlm documentation built on April 20, 2018, 2:35 a.m.