如何在 r 中汇集稳健混合模型的 MI 置信区间?
how to pool MI confidence intervals of robust mixed model in r?
我可以 运行 rlmer
模型与 mice
产生的对象,但是当我尝试合并结果时得到消息 Error: No tidy method for objects of class rlmerMod
。有其他选择吗?
下面是我的数据和模型的可重现示例:
set.seed(1)
library(data.table)
library(robustlmm)
library(mice)
library(miceadds)
dt <- data.table(id = rep(1:10, each=3),
group = rep(1:2, each=15),
time = rep(1:3, 10),
sex = rep(sample(c("F","M"),10,replace=T), each=3),
x = rnorm(30),
y = rnorm(30))
setDT(dt)[id %in% sample(1:10,4) & time == 2, `:=` (x = NA, y = NA)][
id %in% sample(1:10,4) & time == 3, `:=` (x = NA, y = NA)]
# Multiple imputation -------------------------------------------------------------------
pm <- make.predictorMatrix(dt)
pm[,c('x','y')] <- 0
pm[c('x','y'), 'id'] <- -2
imp <- mice(dt, pred = pm, meth = "2l.pmm", seed = 1, m = 2, print = FALSE, maxit = 20)
# Modelling -----------------------------------------------------------------------------
m <- with(imp, rlmer(y ~ 1 + time * group + sex + (1 | id), REML=F))
pool.fit <- pool(m)
> pool.fit <- pool(m)
Error: No tidy method for objects of class rlmerMod
In addition: Warning message:
In get.dfcom(object, dfcom) : Infinite sample size assumed. # I don't get this warning using my real data
谢谢!
编辑:
正如@BenBolker 所说,library(broom.mixed)
得到 pool.fit
到 运行 没有错误。然而,summary(pool.fit,conf.int = TRUE)
returns 估计值,但 NaN
自由度、p 值和置信区间。
library(broom.mixed)
pool.fit <- pool(m)
summary(pool.fit,conf.int = TRUE)
term estimate std.error statistic df p.value 2.5 % 97.5 %
1 (Intercept) -1.31638288 1.2221584 -1.07709683 NaN NaN NaN NaN
2 time 0.02819273 0.4734632 0.05954578 NaN NaN NaN NaN
3 group 1.49581955 0.8776475 1.70435124 NaN NaN NaN NaN
4 sexM -0.61383469 0.7137998 -0.85995356 NaN NaN NaN NaN
5 time:group -0.25690287 0.3005254 -0.85484573 NaN NaN NaN NaN
我不知道是否需要另一个参数(例如,用于定义 df 方法)。
现在,我尝试了 tbl_regression(m)
但它也没有用:
> tbl_regression(m)
pool_and_tidy_mice(): Tidying mice model with
`mice::pool(x) %>% mice::tidy(exponentiate = FALSE, conf.int = TRUE, conf.level = 0.95)`
Error in match.call() : ... used in a situation where it does not exist # how to correct this?
In addition: Warning message:
In get.dfcom(object, dfcom) : Infinite sample size assumed. # again, this warning don't occur with my original data
有什么建议吗?
只需加载 broom.mixed
包,其中包含 rlmerMod
个对象的整理器。 (开发版broom.mixed
有一个get_methods()
功能:
remotes::install_github("bbolker/broom.mixed")
library(broom.mixed)
print(get_methods(), n = Inf)
# A tibble: 22 × 4
class tidy glance augment
<chr> <lgl> <lgl> <lgl>
1 allFit TRUE TRUE FALSE
2 brmsfit TRUE TRUE TRUE
3 gamlss TRUE TRUE FALSE
4 gamm4 TRUE TRUE TRUE
5 glmmadmb TRUE TRUE TRUE
6 glmmTMB TRUE TRUE TRUE
7 gls TRUE TRUE TRUE
8 lme TRUE TRUE TRUE
9 lmList4 TRUE FALSE FALSE
10 mcmc TRUE FALSE FALSE
11 mcmc.list TRUE FALSE FALSE
12 MCMCglmm TRUE FALSE FALSE
13 merMod TRUE TRUE TRUE
14 MixMod TRUE FALSE FALSE
15 ranef.mer FALSE FALSE TRUE
16 rjags TRUE FALSE FALSE
17 rlmerMod TRUE FALSE FALSE
18 stanfit TRUE FALSE FALSE
19 stanreg TRUE TRUE FALSE
20 TMB TRUE FALSE FALSE
21 varComb TRUE FALSE FALSE
22 varFunc TRUE FALSE FALSE
我可以 运行 rlmer
模型与 mice
产生的对象,但是当我尝试合并结果时得到消息 Error: No tidy method for objects of class rlmerMod
。有其他选择吗?
下面是我的数据和模型的可重现示例:
set.seed(1)
library(data.table)
library(robustlmm)
library(mice)
library(miceadds)
dt <- data.table(id = rep(1:10, each=3),
group = rep(1:2, each=15),
time = rep(1:3, 10),
sex = rep(sample(c("F","M"),10,replace=T), each=3),
x = rnorm(30),
y = rnorm(30))
setDT(dt)[id %in% sample(1:10,4) & time == 2, `:=` (x = NA, y = NA)][
id %in% sample(1:10,4) & time == 3, `:=` (x = NA, y = NA)]
# Multiple imputation -------------------------------------------------------------------
pm <- make.predictorMatrix(dt)
pm[,c('x','y')] <- 0
pm[c('x','y'), 'id'] <- -2
imp <- mice(dt, pred = pm, meth = "2l.pmm", seed = 1, m = 2, print = FALSE, maxit = 20)
# Modelling -----------------------------------------------------------------------------
m <- with(imp, rlmer(y ~ 1 + time * group + sex + (1 | id), REML=F))
pool.fit <- pool(m)
> pool.fit <- pool(m)
Error: No tidy method for objects of class rlmerMod
In addition: Warning message:
In get.dfcom(object, dfcom) : Infinite sample size assumed. # I don't get this warning using my real data
谢谢!
编辑:
正如@BenBolker 所说,library(broom.mixed)
得到 pool.fit
到 运行 没有错误。然而,summary(pool.fit,conf.int = TRUE)
returns 估计值,但 NaN
自由度、p 值和置信区间。
library(broom.mixed)
pool.fit <- pool(m)
summary(pool.fit,conf.int = TRUE)
term estimate std.error statistic df p.value 2.5 % 97.5 %
1 (Intercept) -1.31638288 1.2221584 -1.07709683 NaN NaN NaN NaN
2 time 0.02819273 0.4734632 0.05954578 NaN NaN NaN NaN
3 group 1.49581955 0.8776475 1.70435124 NaN NaN NaN NaN
4 sexM -0.61383469 0.7137998 -0.85995356 NaN NaN NaN NaN
5 time:group -0.25690287 0.3005254 -0.85484573 NaN NaN NaN NaN
我不知道是否需要另一个参数(例如,用于定义 df 方法)。
现在,我尝试了 tbl_regression(m)
但它也没有用:
> tbl_regression(m)
pool_and_tidy_mice(): Tidying mice model with
`mice::pool(x) %>% mice::tidy(exponentiate = FALSE, conf.int = TRUE, conf.level = 0.95)`
Error in match.call() : ... used in a situation where it does not exist # how to correct this?
In addition: Warning message:
In get.dfcom(object, dfcom) : Infinite sample size assumed. # again, this warning don't occur with my original data
有什么建议吗?
只需加载 broom.mixed
包,其中包含 rlmerMod
个对象的整理器。 (开发版broom.mixed
有一个get_methods()
功能:
remotes::install_github("bbolker/broom.mixed")
library(broom.mixed)
print(get_methods(), n = Inf)
# A tibble: 22 × 4
class tidy glance augment
<chr> <lgl> <lgl> <lgl>
1 allFit TRUE TRUE FALSE
2 brmsfit TRUE TRUE TRUE
3 gamlss TRUE TRUE FALSE
4 gamm4 TRUE TRUE TRUE
5 glmmadmb TRUE TRUE TRUE
6 glmmTMB TRUE TRUE TRUE
7 gls TRUE TRUE TRUE
8 lme TRUE TRUE TRUE
9 lmList4 TRUE FALSE FALSE
10 mcmc TRUE FALSE FALSE
11 mcmc.list TRUE FALSE FALSE
12 MCMCglmm TRUE FALSE FALSE
13 merMod TRUE TRUE TRUE
14 MixMod TRUE FALSE FALSE
15 ranef.mer FALSE FALSE TRUE
16 rjags TRUE FALSE FALSE
17 rlmerMod TRUE FALSE FALSE
18 stanfit TRUE FALSE FALSE
19 stanreg TRUE TRUE FALSE
20 TMB TRUE FALSE FALSE
21 varComb TRUE FALSE FALSE
22 varFunc TRUE FALSE FALSE