R:如何从 nlmer 输出中提取随机效应
R: how to extract random effects from nlmer output
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]
但没有成功。
stddev
是一个属性
suppressWarnings(as.vector(attr(summary(nm1)$varcor$Tree, "stddev")))
#[1] 31.64632
如果我们检查
的 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"
它是以'Tree'为单个元素的list
。所以我们通过 $Tree
或 [[1]]
或 [["Tree"]]
提取 'Tree' 然后提取属性 'stddev'
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]
但没有成功。
stddev
是一个属性
suppressWarnings(as.vector(attr(summary(nm1)$varcor$Tree, "stddev")))
#[1] 31.64632
如果我们检查
的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"
它是以'Tree'为单个元素的list
。所以我们通过 $Tree
或 [[1]]
或 [["Tree"]]
提取 'Tree' 然后提取属性 'stddev'