R:如何从nlmer输出中提取随机效应

时间:2018-02-19 03:25:54

标签: r lme4 mixed-models

library(lme4)
startvec <- c(Asym = 200, xmid = 725, scal = 350)
(nm1 <- nlmer(circumference ~ SSlogis(age, Asym, xmid, scal) ~ Asym|Tree,
              Orange, start = startvec))
> summary(nm1)$varcor
 Groups   Name Std.Dev.
 Tree     Asym 31.646  
 Residual       7.843 

我试图提取Asym随机效应的标准差(例如31.646)。但我已经尝试summary(nm1)$varcor$Std.Dev.summary(nm1)$varcor[1, 3]但没有运气。

1 个答案:

答案 0 :(得分:0)

stddev是属性

suppressWarnings(as.vector(attr(summary(nm1)$varcor$Tree, "stddev")))
#[1] 31.64632

如果我们检查<{p}}的str

str(summary(nm1)$varcor)
#List of 1
# $ Tree: num [1, 1] 1001
#  ..- attr(*, "dimnames")=List of 2
#  .. ..$ : chr "Asym"
#  .. ..$ : chr "Asym"
#  ..- attr(*, "stddev")= Named num 31.6
#  .. ..- attr(*, "names")= chr "Asym"
#  ..- attr(*, "correlation")= num [1, 1] 1
#  .. ..- attr(*, "dimnames")=List of 2
#  .. .. ..$ : chr "Asym"
#  .. .. ..$ : chr "Asym"
# - attr(*, "sc")= num 7.84
# - attr(*, "useSc")= logi TRUE
# - attr(*, "class")= chr "VarCorr.merMod"

它是list,其中'Tree'作为单个元素。因此,我们通过执行$Tree[[1]][["Tree"]]提取“树”,然后提取属性“stddev”