extract_varcomp.Rd
Extracts the estimated variance components from a fitted linear mixed effects model (lmeStruct object) or generalized least squares model (glsStruct object).
extract_varcomp(mod, separate_variances, vector)
Fitted model of class lmeStruct or glsStruct.
Logical indicating whether to return the separate
level-1 variance components for each stratum if using varIdent
function to allow for different variances per stratum. Default is
FALSE
.
Logical indicating whether to return the variance components as
a numeric vector. Default is FALSE
.
If vector = FALSE
, an object of class varcomp
consisting of a
list of estimated variance components. Models that do not include
correlation structure parameters or variance structure parameters will have
empty lists for those components. If vector = TRUE
, a numeric vector
of estimated variance components.
If separate_variances = TRUE
and if weights =
varIdent(form = ~ 1 | Stratum)
is specified in the model fitting, separate
level-1 variance estimates will be returned for each stratum. If
separate_variances = TRUE
but if the weighting structure is not
specified with varIdent
, or if separate_variances = FALSE
,
then no separate level-1 variance estimates will be returned.
library(nlme)
data(Bryant2016)
Bryant2016_RML <- lme(fixed = outcome ~ treatment,
random = ~ 1 | school/case,
correlation = corAR1(0, ~ session | school/case),
weights = varIdent(form = ~ 1 | treatment),
data = Bryant2016)
extract_varcomp(Bryant2016_RML, separate_variances = FALSE)
#> $Tau
#> $Tau$school
#> school.var((Intercept))
#> 165.9984
#>
#> $Tau$case
#> case.var((Intercept))
#> 2.171361e-05
#>
#>
#> $cor_params
#> [1] 0.9745914
#>
#> $var_params
#> [1] 1.250291
#>
#> $sigma_sq
#> [1] 663.8412
#>
#> attr(,"class")
#> [1] "varcomp"
extract_varcomp(Bryant2016_RML, separate_variances = TRUE)
#> $Tau
#> $Tau$school
#> school.var((Intercept))
#> 165.9984
#>
#> $Tau$case
#> case.var((Intercept))
#> 2.171361e-05
#>
#>
#> $cor_params
#> [1] 0.9745914
#>
#> $sigma_sq
#> baseline treatment
#> 663.8412 1037.7353
#>
#> attr(,"class")
#> [1] "varcomp"
extract_varcomp(Bryant2016_RML, vector = TRUE)
#> Tau.school.school.var((Intercept)) Tau.case.case.var((Intercept))
#> 1.659984e+02 2.171361e-05
#> cor_params var_params
#> 9.745914e-01 1.250291e+00
#> sigma_sq
#> 6.638412e+02