Extract standard deviation of random effect components with glmer

I use glmer, and I want to extract the standard deviation of the dispersion components of random effects (interception and tilt).

I tried using:

VarCorr(model) 

which returns two standard deviation values ​​(plus correlation), but I just want to extract the Intercept and Slope SD values.

I tried using:

 VarrCorr(model)[1] 

to retrieve a random SD interception that lets me know that:

 attr(,"stddev") (Intercept) year 0.075 0.011 

but I don’t know how to extract them as separate elements.

+3
source share
1 answer

There are two ways to do this.

 ## make up a model library(lme4) (gm <- glmer(incidence ~ period + (size | herd), family = poisson, data = cbpp)) 

Approach 1

The current version of lme4 allows lme4 to force a VarCorr object to a data frame:

 as.data.frame(VarCorr(gm)) 

You can then select rows 1: 2 and column 5 to extract the standard deviations of the random intercept and tilt.

Approach 2

If you want to extract values ​​in the old fashioned way, you can use attributes :

 attributes(VarCorr(gm)$herd)$stddev (Intercept) size 1.18970662 0.08826278 

If you want to get rid of names (i.e. (intercept) , size ), you can use as.numeric or unname .

+6
source

Source: https://habr.com/ru/post/1209390/


All Articles