Extracting standard deviation of random effects components using glmer

不问归期 提交于 2019-12-06 07:26:51

问题


I am using glmer and I wish to extract the standard deviation of the variance components of the random effects (intercept and slope).

I have tried using:

VarCorr(model)

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

I tried using:

VarrCorr(model)[1]

to extract the random intercept SD, which lets me know that:

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

but I don't know how to extract these as individual elements.


回答1:


There are 2 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 you to coerce a VarCorr object to a data frame:

as.data.frame(VarCorr(gm))

Then you can select rows 1:2 and column 5 to extract standard deviations of random intercept and slope.

Approach 2

If you want to extract the values in a 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 the names (i.e., (intercept), size), then you can use as.numeric or unname.



来源:https://stackoverflow.com/questions/25084924/extracting-standard-deviation-of-random-effects-components-using-glmer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!