使用
purrr::map()
运行 lmer()
分析时可以获得结果。但是当我想对 nmle::lme()
执行相同操作时,我收到了错误消息:
Error in `map()`:
ℹ In index: 1.
ℹ With name: p_h.
Caused by error:
! object '.x' not found
这是可用于重现我的分析的玩具数据:
testdata <- structure(list(subject = c("B001", "B001", "B001", "B001", "B001",
"B002", "B002", "B002", "B002", "B002", "B003", "B003", "B003",
"B003", "B003", "B004", "B004", "B004", "B004", "B004", "B005",
"B005", "B005", "B005", "B005"), time_point = structure(c(1L,
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L,
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), levels = c("Wk0", "Wk4", "Wk8",
"Wk12", "Wk16"), class = "factor"), sfa = c(62.895, 84.705, 83.49,
66.64, 72.19, 56.195, 93.945, 92.635, 88.51, 83.505, 92.67, 90.81,
83.37, 90.205, 84.195, 88.065, 53.69, 93.14, 52.57, 95.995, 63.505,
92.59, 80.87, 89.125, 67.305), mufa = c(14.455, 11.71, 12.58,
21.135, 26.175, 13.285, 4.91, 6.08, 6.735, 12.745, 7.325, 7.605,
15.735, 7.985, 12.32, 7.92, 42.045, 4.57, 24.305, 4.505, 18.585,
5.955, 14.815, 8.775, 20.295), pufa = c(22.65, 3.58, 3.935, 12.23,
1.635, 30.525, 1.135, 1.275, 4.76, 3.75, 0, 1.595, 0.885, 1.82,
3.495, 4.01, 4.26, 2.29, 23.125, 0, 17.905, 1.455, 4.305, 2.1,
12.4)), row.names = c(NA, -25L), class = c("tbl_df", "tbl", "data.frame"
))
这个有效
对于
lmer()
library(lme4)
library(nlme)
library(lmerTest)
library(broom.mixed)
testdata |>
select(sfa, mufa, pufa) |>
map(~ lmer(.x ~ time_point + (1| subject), data = testdata))
这不起作用
对于
nlme::lme()
library(lme4)
library(nlme)
library(lmerTest)
library(broom.mixed)
testdata |>
select(sfa, mufa, pufa) |>
map(~ lme(.x ~ time_point, random = ~ 1 | subject,
data = testdata, method = 'ML'))
非常感谢任何帮助。
这可能不太漂亮,但它有效:
list("sfa", "mufa", "pufa") |>
purrr::map(~ reformulate("time_point", response = .)) |>
purrr::map(~ lme(., random = ~ 1 | subject,
data = testdata, method = 'ML'))