R glmmTMB是否返回glmmADMB等随机效应方差分量的标准误差?
注:以下分析仅适用于可复制对象,不作为分析R glmmTMB是否返回glmmADMB等随机效应方差分量的标准误差?,r,R,注:以下分析仅适用于可复制对象,不作为分析质量中的细菌数据的合法方法 library(glmmADMB) library(glmmTMB) data(bacteria,package="MASS") bacteria$present <- as.numeric(bacteria$y)-1 bacteria$early <- factor(as.numeric(bacteria$week > 3) + 1) bfit2 <- glmmadmb(present ~ trt
质量中的细菌
数据的合法方法
library(glmmADMB)
library(glmmTMB)
data(bacteria,package="MASS")
bacteria$present <- as.numeric(bacteria$y)-1
bacteria$early <- factor(as.numeric(bacteria$week > 3) + 1)
bfit2 <- glmmadmb(present ~ trt ,
random = ~ (1 | ID) + (1 | early),
family = "binomial", data = bacteria)
bfit2$S
bfit2$sd_S
bfit3 <- glmmTMB(present ~ trt + (1 | ID) + (1 | early),
family = "binomial", data = bacteria)
summary(bfit3)$varcor
confint(bfit3)
如我们所见,sqrt(1.4047)=1.18513
和sqrt(0.51465)=0.71733
表明bfit2$S
给出了方差的估计值,summary(bfit3)$varcor
给出了标准偏差的估计值
第二次更新:
经过一些挖掘,我意识到bfit3$sdr
返回log-sd标度上的方差分量以及标准误差。因此,一种想法是避免confint
,通过计算对数sd标度上的95%CI,然后转换为所需标度,然后将CI宽度除以2*1.96,来反算SEs
## to get the standard errors from glmmTMB:
bfit3$sdr
## note that theta is just log(sd)
exp(summary(bfit3$sdr, "fixed")[4,1])
exp(summary(bfit3$sdr, "fixed")[5,1])
## calculate the (wald) lower and upper on the log(sd) scale:
low.log.sd.id <- summary(bfit3$sdr, "fixed")[4,1] - 1.96*summary(bfit3$sdr, "fixed")[4,2]
low.log.sd.early <- summary(bfit3$sdr, "fixed")[5,1] - 1.96*summary(bfit3$sdr, "fixed")[5,2]
upp.log.sd.id <- summary(bfit3$sdr, "fixed")[4,1] + 1.96*summary(bfit3$sdr, "fixed")[4,2]
upp.log.sd.early <- summary(bfit3$sdr, "fixed")[5,1] + 1.96*summary(bfit3$sdr, "fixed")[5,2]
## convert to variance scale by taking exp and then squaring
low.var.id <- exp(low.log.sd.id)^2
upp.var.id <- exp(upp.log.sd.id)^2
low.var.early <- exp(low.log.sd.early)^2
upp.var.early <- exp(upp.log.sd.early)^2
## back calculate SEs
(upp.var.id - low.var.id) / (2*1.96)
(upp.var.early - low.var.early) / (2*1.96)
## see how they compare to the confint answers for sd:
sqrt(c(low.var.id, upp.var.id))
sqrt(c(low.var.early, upp.var.early))
##要从glmmTMB获取标准错误:
bfit3美元特别提款权
##注意,θ只是对数(sd)
exp(汇总(bfit3$sdr,“固定”)[4,1])
exp(汇总(bfit3$sdr,“固定”)[5,1])
##计算对数(sd)刻度上的(瓦尔德)下限和上限:
low.log.sd.id low.var.id upp.var.id low.var.early upp.var.early#
>(upp.var.id-low.var.id)/(2*1.96)
[1] 1.24857
>(高风险早期-低风险早期)/(2*1.96)
[1] 1.354657
>##查看它们与sd的确认答案的比较:
>sqrt(c(低变量id,高变量id))
[1] 0.611891 2.295388
>sqrt(c(低风险早期,高风险早期))
[1] 0.2222637 2.3150935
上面的最后两行与confint(bfit3)输出的最后两行非常匹配。现在我想我只是想知道为什么glmmADMB的SEs为0.94743和0.61533,而glmmTMB的反算SEs分别为1.24857和1.354657…(?)对象是一个列表。标准偏差存储为属性:
str( summary(bfit3)$varcor )
List of 2
$ cond:List of 2
..$ ID : num [1, 1] 1.4
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr "(Intercept)"
.. .. ..$ : chr "(Intercept)"
.. ..- attr(*, "stddev")= Named num 1.19
.. .. ..- attr(*, "names")= chr "(Intercept)"
.. ..- attr(*, "correlation")= num [1, 1] 1
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr "(Intercept)"
.. .. .. ..$ : chr "(Intercept)"
.. ..- attr(*, "blockCode")= Named num 1
.. .. ..- attr(*, "names")= chr "us"
..$ early: num [1, 1] 0.515
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr "(Intercept)"
.. .. ..$ : chr "(Intercept)"
.. ..- attr(*, "stddev")= Named num 0.717
.. .. ..- attr(*, "names")= chr "(Intercept)"
.. ..- attr(*, "correlation")= num [1, 1] 1
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr "(Intercept)"
.. .. .. ..$ : chr "(Intercept)"
.. ..- attr(*, "blockCode")= Named num 1
.. .. ..- attr(*, "names")= chr "us"
..- attr(*, "sc")= num 1
..- attr(*, "useSc")= logi FALSE
$ zi : NULL
- attr(*, "sc")= logi FALSE
- attr(*, "class")= chr "VarCorr.glmmTMB"
这将在该对象的$cond
元素上循环:
sapply( summary(bfit3)$varcor$cond, function(x) attr( x, "stddev") )
ID.(Intercept) early.(Intercept)
1.1851276 0.7173293
对您的分析不是100%确定,但以下是我要检查的内容(包括深入挖掘glmmADMB
的本质,以及使用glmmTMB
的一些稍微模糊的方面):
- 运行
glmmADMB
,并深入ADMB.std
输出文件以检查结果:
N-PAR估计SD
4 tmpL 1.6985e-01 3.3727e-01
5 tmpL-3.2901e-01 5.9780e-01
...
62 S 1.4045 9.474e-01
63 S 5.178e-01 6.191e-01
这些行分别是内部参数(tmpL
:对数标准偏差)和转换参数(方差)
重新进行转换并检查:
tmpL <- c(0.16985,-0.32901)
cbind(admb.raw=exp(2*tmpL),
admb=unlist(bfit2$S),
tmb =unlist(VarCorr(bfit3)))
## admb.raw admb tmb
## ID 1.4045262 1.40450 1.4045274
## early 0.5178757 0.51788 0.5145613
tmpL此答案提供了标准偏差,在问题中已显示为summary(bfit3)$varcor
——我正在寻找这些估计值的标准误差。我认为这里可能存在一些术语混淆。术语“估计的标准误差”是参数估计的标准偏差(在“参数空间”)。当以原始数据比例一起查看时,“标准误差”和“标准偏差”因sqrt(df)的一个因素而不同。我们可以尝试在@BenBolker页面上搜索,以获得关于此问题和我使用术语的专家独立意见。好主意!我在glmmTMB github页面上发布了一个问题,他们引起了我的注意confint()
,我相应地更新了我的问题。我想我很乐意得到预期的SEs——现在我的问题已经发展到为什么glmmADMB和glmmTMB之间的SEs不同了。
sapply( summary(bfit3)$varcor$cond, function(x) attr( x, "stddev") )
ID.(Intercept) early.(Intercept)
1.1851276 0.7173293
tmpL <- c(0.16985,-0.32901)
cbind(admb.raw=exp(2*tmpL),
admb=unlist(bfit2$S),
tmb =unlist(VarCorr(bfit3)))
## admb.raw admb tmb
## ID 1.4045262 1.40450 1.4045274
## early 0.5178757 0.51788 0.5145613
## sd of log-sd from glmmTMB
tmb_sd <- sqrt(diag(vcov(bfit3,full=TRUE)))[4:5]
tmb_logsd <- bfit3$sdr$par.fixed[4:5]
tmpL_sd <- c(0.33727,0.5978)
cbind(admb.raw=tmpL_sd*2*exp(2*tmpL),
admb=unlist(bfit2$sd_S),
tmb=tmb_sd*2*exp(2*tmb_logsd))
## admb.raw admb tmb
## ID 0.9474091 0.94741 0.9474132
## early 0.6191722 0.61918 0.6152003