admin管理员组文章数量:1337212
I'm revisiting old code that involves multiple imputation using missRanger::missRanger(), multcomp::glht() (to derive the linear combination of effects), mice::pool(), and broom.mixed::tidy(). While it previously worked, it now fails when I try to create a tidy table or otherwise extract results. I've reproduced the error using mtcars below.
# 0. PACKAGES
library(tidyverse)
library(mice)
library(broom.mixed)
library(missRanger)
# 1. DATA
# set 20% of the mtcars dataset missing
mtcars_miss <-
generateNA(mtcars,
p = 0.2,
seed = 2024)
# generate 5 imputations
mtcars_i <-
replicate(9,
missRanger(mtcars_miss,
num.tree = 500,
pmm.k = 3,
verbose = 0,
seed = 2024),
simplify = FALSE)
# 2. ANALYSIS WITHOUT LINEAR COMBINATIONS
mtcars_mod <-
lapply(mtcars_i,
function(x)
glm(mpg ~ hp * wt + am,
data = x))
pool(mtcars_mod)
pool(mtcars_mod) |>
tidy(conf.int = TRUE)
# 3. ANALYSIS WITH LINEAR COMBINATIONS
mtcars_lin <-
lapply(mtcars_i,
function(x)
multcomp::glht(glm(mpg ~ hp * wt + am,
data = x),
linfct = c("hp = 0",
"`hp:wt` = 0",
"hp + `hp:wt` = 0")) |>
summary())
pool(mtcars_lin)
pool(mtcars_lin) |>
tidy(conf.int = TRUE)
This last chunk generates the following error message. As I note above, this is a new error that did not appear when I ran the code in October 2024. I don't know what the cause is because the output of the pool() argument creates mipo for both the standard model and the one with the linear combination of effects.
Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 0, 3
Any ideas as to which package is causing the issue? Or how I can work around this? It is occurring both with glm() and glmmTMB() model functions.
I'm revisiting old code that involves multiple imputation using missRanger::missRanger(), multcomp::glht() (to derive the linear combination of effects), mice::pool(), and broom.mixed::tidy(). While it previously worked, it now fails when I try to create a tidy table or otherwise extract results. I've reproduced the error using mtcars below.
# 0. PACKAGES
library(tidyverse)
library(mice)
library(broom.mixed)
library(missRanger)
# 1. DATA
# set 20% of the mtcars dataset missing
mtcars_miss <-
generateNA(mtcars,
p = 0.2,
seed = 2024)
# generate 5 imputations
mtcars_i <-
replicate(9,
missRanger(mtcars_miss,
num.tree = 500,
pmm.k = 3,
verbose = 0,
seed = 2024),
simplify = FALSE)
# 2. ANALYSIS WITHOUT LINEAR COMBINATIONS
mtcars_mod <-
lapply(mtcars_i,
function(x)
glm(mpg ~ hp * wt + am,
data = x))
pool(mtcars_mod)
pool(mtcars_mod) |>
tidy(conf.int = TRUE)
# 3. ANALYSIS WITH LINEAR COMBINATIONS
mtcars_lin <-
lapply(mtcars_i,
function(x)
multcomp::glht(glm(mpg ~ hp * wt + am,
data = x),
linfct = c("hp = 0",
"`hp:wt` = 0",
"hp + `hp:wt` = 0")) |>
summary())
pool(mtcars_lin)
pool(mtcars_lin) |>
tidy(conf.int = TRUE)
This last chunk generates the following error message. As I note above, this is a new error that did not appear when I ran the code in October 2024. I don't know what the cause is because the output of the pool() argument creates mipo for both the standard model and the one with the linear combination of effects.
Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 0, 3
Any ideas as to which package is causing the issue? Or how I can work around this? It is occurring both with glm() and glmmTMB() model functions.
Share Improve this question edited Feb 15 at 0:31 pppery 3,81425 gold badges37 silver badges50 bronze badges asked Jan 14 at 2:55 Tyler LaneTyler Lane 891 silver badge7 bronze badges1 Answer
Reset to default 0Partial answer to my own question. As suspect, it was a version control issue. I posted my frustration to Bluesky and someone provided a workaround, which is the Groundhog package. Code below
# 0. PACKAGES
knitr::opts_chunk$set(echo = TRUE)
# load ground first
library(groundhog)
# load other packages
groundhog.library(
c("mice", "broom.mixed",
"multcomp", "missRanger"),
"2024-10-15")
library(tidyverse)
# 1. SETUP DATA
# set 20% of the mtcars dataset missing
mtcars_miss <-
generateNA(mtcars,
p = 0.2,
seed = 2024)
# generate 5 imputations
mtcars_i <-
replicate(9,
missRanger(mtcars_miss,
num.tree = 500,
pmm.k = 3,
verbose = 0,
seed = 2024),
simplify = FALSE)
# 2. ANALYSIS WITHOUT LINEAR COMBINATIONS
mtcars_mod <-
lapply(mtcars_i,
function(x)
glm(mpg ~ hp * wt + am,
data = x))
pool(mtcars_mod)
pool(mtcars_mod) |>
tidy()
# 3. ANALYSIS WITHOUT LINEAR COMBINATIONS
mtcars_lin <-
lapply(mtcars_i,
function(x)
multcomp::glht(glm(mpg ~ hp * wt + am,
data = x),
linfct = c("hp = 0",
"`hp:wt` = 0",
"hp + `hp:wt` = 0")))
pool(mtcars_lin)
pool(mtcars_lin) |>
tidy()
The model results aren't great, but the error is gone and all of the packages work well together again!
本文标签: rNew error using multcompglht()missRanger()and micepool()Stack Overflow
版权声明:本文标题:r - New error using multcomp::glht(), missRanger(), and mice::pool() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743376785a2493733.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论