来自lmer输出的方差的标准误差 [英] Standard Error of variance component from the output of lmer

查看:185
本文介绍了来自lmer输出的方差的标准误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从lmer的输出中提取方差分量的standard error.

I need to extract the standard error of variance component from the output of lmer .

library(lme4)
model <- lmer(Reaction ~ Days + (1|Subject), sleepstudy)

以下内容产生方差分量的估计值:

The following produces estimates of variance component :

s2 <- VarCorr(model)$Subject[1]

是方差的标准误.我想要标准错误.我怎么有?

It is NOT the standard error of the variance. And I want the standard error . How can I have it ?

也许我无法让您理解方差成分的标准误差"的含义.所以我正在编辑我的帖子.

Perhaps I am unable to make you understand what I meant by "standard error of the variance component". So I am editing my post .

该书

In Chapter 12 , Experiments with Random Factors , of the book Design and Analysis of Experiments , by Douglas C. Montgomery , at the end of the chapter , Example 12-2 is done by SAS . In Example 12-2 , the model is a two-factor factorial random effect model .The output is given in Table 12-17

我正在尝试通过lmer将模型拟合到R中.

I am trying to fit the model in R by lmer .

library(lme4)
fit <- lmer(y~(1|operator)+(1|part),data=dat)

用于提取Estimate的R代码,在表12-17中用4标注:

R codes for extracting the Estimate , annotated by 4 in the table 12-17 :

est_ope=VarCorr(fit)$operator[1]
est_part = VarCorr(fit)$part[1]
sig = summary(fit)$sigma
est_res = sig^2

现在,我想从lmer输出中提取表12-17中用5注释的Std Errors结果.

Now I want to extract the results of Std Errors , annotated by 5 in the table 12-17 from lmer output .

非常感谢!

推荐答案

我认为您正在寻找方差估计的Wald标准误差.请注意,这些(如Doug Bates经常指出的那样),Wald标准误通常是非常差的方差不确定性估计,因为似然曲线在方差标度上通常不是二次方.我假设您知道自己在做什么,并且可以很好地利用这些数字...

I think you are looking for the Wald standard error of the variance estimates. Please note that these (as often pointed out by Doug Bates) the Wald standard errors are often very poor estimates of the uncertainty of variances, because the likelihood profiles are often far from quadratic on the variance scale ... I'm assuming you know what you're doing and have some good use for these numbers ...

library("lme4")
model <- lmer(Reaction ~ Days + (1|Subject), sleepstudy, REML=FALSE)

(目前,对于REML估算,要执行此操作要困难很多……)

(At present it's quite a bit harder to do this for the REML estimates ...)

根据标准偏差和相关性而不是根据Cholesky因子提取参数化的偏差函数(请注意,这是一个内部函数,因此不能保证它将来会以相同的方式工作...)

Extract deviance function parameterized in terms of standard deviation and correlation rather than in terms of Cholesky factors (note this an internal function, so there's not a guarantee that it will keep working in the same way in the future ...)

 dd.ML <- lme4:::devfun2(model,useSc=TRUE,signames=FALSE)

将参数提取为原始比例的标准偏差:

Extract parameters as standard deviations on original scale:

 vv <- as.data.frame(VarCorr(model)) ## need ML estimates!
 pars <- vv[,"sdcor"]
 ## will need to be careful about order if using this for
 ## a random-slopes model ...

现在计算二阶导数(Hessian)矩阵:

Now compute the second-derivative (Hessian) matrix:

library("numDeriv")
hh1 <- hessian(dd.ML,pars)
vv2 <- 2*solve(hh1)  ## 2* converts from log-likelihood to deviance scale
sqrt(diag(vv2))  ## get standard errors

这些是标准差的标准误差:将它们加倍以获得方差的标准误差(当转换值时,其标准误差将根据转换的导数进行缩放).

These are the standard errors of the standard deviations: double them to get the standard errors of the variances (when you transform a value, its standard errors scale according to the derivative of the transformation).

我认为应该这样做,但是您可能要仔细检查一下...

I think this should do it, but you might want to double-check it ...

这篇关于来自lmer输出的方差的标准误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆