R,在glmer中使用tbl_regression时得到错误信息'x' must be an array of at least two dimensions
R, Getting the error message 'x' must be an array of at least two dimensions when using tbl_regression with glmer
当我 运行 以下代码时收到错误消息 Error in colSums(tcm * y * w) : 'x' must be an array of at least two dimensions
:
glmer(outcome ~ predictor + (1|id),
data = df,
family = binomial) %>%
tbl_regression()
对于上下文,我正在查看结果(患者对会面的满意度,1 = 满意,0 = 不满意)是否会根据医生是否完成研讨会而改变。使用 GLMER 而不是 GLM 的原因是因为每个医生都有多个患者。因此,这是一个重复的测量。
重现错误消息:
outcome <- c(1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,0,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,NA ,1,1,1,1,1,1,1,1,1,NA,1,NA,NA,1,1,1,NA,0,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1)
predictor <- c("91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After ", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After ", "91 Days After",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days Before")
id <- c(46, 109, 82, 98, 98, 104, 98, 82, 27, 27, 25, 104, 44, 77, 102,44, 25, 104, 82, 66, 25, 66, 66, 66, 66, 111, 25, 111, 111, 46, 111, 46, 25, 25, 32, 25, 25, 25, 46, 25, 46, 25, 111, 32, 104, 111, 32, 111, 109,51, 32, 36, 4, 104, 32, 44, 34, 34, 19, 102, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 43, 43, 43, 43, 43, 43,43, 68, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,53, 53, 97, 97, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 29, 29, 29, 29,29, 29, 29, 13, 13, 13, 13, 13, 13, 13, 13, 13, 34, 34, 34, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 76, 17, 17, 14, 14, 93, 85, 85, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 88, 88, 88, 88, 88, 88, 51, 51, 51, 51, 51, 51, 51, 92,92, 92, 45, 45, 45, 90, 90, 90, 90, 90, 58, 58, 58, 58, 58, 58, 58, 58, 83, 4, 4, 39, 81, 94, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,64, 64)
ex_data <- cbind(id, predictor, outcome) %>%
as.data.frame() %>%
mutate(id = factor(id),
predictor = factor(predictor),
outcome = factor(outcome))
glmer(outcome ~ predictor + (1|id),
data = ex_data,
family = binomial) %>%
tbl_regression()
tl;dr gtsummary()
不知道如何处理作为因素的反应(base-R,并且通过扩展 glmer
,几乎是病态的灵活地接受二项式回归的响应值的方式,但通常最好使用数值)。
public 服务 post gtsummary issues list 的一个问题。
避免 cbind()
,因为那样会自动将所有向量强制转换为同一类型。
library(tidyverse)
library(gtsummary)
ex_data <- tibble(id, predictor, outcome) %>%
mutate(across(c(id, predictor), factor)
g1 <- glmer(outcome ~ predictor + (1|id),
data = ex_data,
family = binomial)
tbl_regression(g1)
保存 glmer
拟合而不是将其直接输送到 tbl_regression()
可能更有意义,因为您可能想用它做其他事情(诊断图、coefficient/dot-whisker 图、预测、模型比较...)
tbl_regression()
依赖 broom.helpers
包来准备和改进 tidy()
返回的小标题。您可以使用 broom.helpers::tidy_plus_plus()
查看 broom.helpers
所做的不同增强。
您提到的错误已在 broom.helpers
的当前开发版本中识别并修复。比照。 https://github.com/larmarange/broom.helpers/issues/116
outcome <- c(1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,0,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,NA ,1,1,1,1,1,1,1,1,1,NA,1,NA,NA,1,1,1,NA,0,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1)
predictor <- c("91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After", "91 Days After",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days Before")
id <- c(46, 109, 82, 98, 98, 104, 98, 82, 27, 27, 25, 104, 44, 77, 102,44, 25, 104, 82, 66, 25, 66, 66, 66, 66, 111, 25, 111, 111, 46, 111, 46, 25, 25, 32, 25, 25, 25, 46, 25, 46, 25, 111, 32, 104, 111, 32, 111, 109,51, 32, 36, 4, 104, 32, 44, 34, 34, 19, 102, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 43, 43, 43, 43, 43, 43,43, 68, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,53, 53, 97, 97, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 29, 29, 29, 29,29, 29, 29, 13, 13, 13, 13, 13, 13, 13, 13, 13, 34, 34, 34, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 76, 17, 17, 14, 14, 93, 85, 85, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 88, 88, 88, 88, 88, 88, 51, 51, 51, 51, 51, 51, 51, 92,92, 92, 45, 45, 45, 90, 90, 90, 90, 90, 58, 58, 58, 58, 58, 58, 58, 58, 83, 4, 4, 39, 81, 94, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,64, 64)
library(tidyverse)
library(broom.mixed)
ex_data <- cbind(id, predictor, outcome) %>%
as.data.frame() %>%
dplyr::mutate(id = factor(id),
predictor = factor(predictor),
outcome = factor(outcome))
lme4::glmer(outcome ~ predictor + (1|id),
data = ex_data,
family = binomial) %>%
broom.helpers::tidy_plus_plus(exponentiate = TRUE, intercept = TRUE) %>%
knitr::kable()
term
original_term
variable
var_label
var_class
var_type
var_nlevels
contrasts
contrasts_type
reference_row
label
n_obs
n_event
effect
group
estimate
std.error
statistic
p.value
conf.low
conf.high
(Intercept)
(Intercept)
(Intercept)
(Intercept)
NA
intercept
NA
NA
NA
NA
(Intercept)
270
264
fixed
NA
2.056839e+04
5.618032e+04
3.6360619
0.0002768
97.3273899
4.346757e+06
predictor91 Days After
NA
predictor
predictor
factor
dichotomous
2
contr.treatment
treatment
TRUE
91 Days After
137
134
NA
NA
1.000000e+00
NA
NA
NA
NA
NA
predictor91 Days Before
predictor91 Days Before
predictor
predictor
factor
dichotomous
2
contr.treatment
treatment
FALSE
91 Days Before
133
130
fixed
NA
6.825077e-01
7.266704e-01
-0.3587669
0.7197695
0.0846892
5.500312e+00
id.sd__(Intercept)
id.sd__(Intercept)
id.sd__(Intercept)
id.sd__(Intercept)
NA
ran_pars
NA
NA
NA
NA
id.sd__(Intercept)
NA
NA
ran_pars
id
8.898623e+00
NA
NA
NA
NA
NA
由 reprex package (v2.0.0)
于 2021-06-24 创建
当我 运行 以下代码时收到错误消息 Error in colSums(tcm * y * w) : 'x' must be an array of at least two dimensions
:
glmer(outcome ~ predictor + (1|id),
data = df,
family = binomial) %>%
tbl_regression()
对于上下文,我正在查看结果(患者对会面的满意度,1 = 满意,0 = 不满意)是否会根据医生是否完成研讨会而改变。使用 GLMER 而不是 GLM 的原因是因为每个医生都有多个患者。因此,这是一个重复的测量。
重现错误消息:
outcome <- c(1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,0,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,NA ,1,1,1,1,1,1,1,1,1,NA,1,NA,NA,1,1,1,NA,0,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1)
predictor <- c("91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After ", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After ", "91 Days After",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After ", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After ", "91 Days After",
"91 Days Before")
id <- c(46, 109, 82, 98, 98, 104, 98, 82, 27, 27, 25, 104, 44, 77, 102,44, 25, 104, 82, 66, 25, 66, 66, 66, 66, 111, 25, 111, 111, 46, 111, 46, 25, 25, 32, 25, 25, 25, 46, 25, 46, 25, 111, 32, 104, 111, 32, 111, 109,51, 32, 36, 4, 104, 32, 44, 34, 34, 19, 102, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 43, 43, 43, 43, 43, 43,43, 68, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,53, 53, 97, 97, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 29, 29, 29, 29,29, 29, 29, 13, 13, 13, 13, 13, 13, 13, 13, 13, 34, 34, 34, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 76, 17, 17, 14, 14, 93, 85, 85, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 88, 88, 88, 88, 88, 88, 51, 51, 51, 51, 51, 51, 51, 92,92, 92, 45, 45, 45, 90, 90, 90, 90, 90, 58, 58, 58, 58, 58, 58, 58, 58, 83, 4, 4, 39, 81, 94, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,64, 64)
ex_data <- cbind(id, predictor, outcome) %>%
as.data.frame() %>%
mutate(id = factor(id),
predictor = factor(predictor),
outcome = factor(outcome))
glmer(outcome ~ predictor + (1|id),
data = ex_data,
family = binomial) %>%
tbl_regression()
tl;dr gtsummary()
不知道如何处理作为因素的反应(base-R,并且通过扩展 glmer
,几乎是病态的灵活地接受二项式回归的响应值的方式,但通常最好使用数值)。
public 服务 post gtsummary issues list 的一个问题。
避免 cbind()
,因为那样会自动将所有向量强制转换为同一类型。
library(tidyverse)
library(gtsummary)
ex_data <- tibble(id, predictor, outcome) %>%
mutate(across(c(id, predictor), factor)
g1 <- glmer(outcome ~ predictor + (1|id),
data = ex_data,
family = binomial)
tbl_regression(g1)
保存 glmer
拟合而不是将其直接输送到 tbl_regression()
可能更有意义,因为您可能想用它做其他事情(诊断图、coefficient/dot-whisker 图、预测、模型比较...)
tbl_regression()
依赖 broom.helpers
包来准备和改进 tidy()
返回的小标题。您可以使用 broom.helpers::tidy_plus_plus()
查看 broom.helpers
所做的不同增强。
您提到的错误已在 broom.helpers
的当前开发版本中识别并修复。比照。 https://github.com/larmarange/broom.helpers/issues/116
outcome <- c(1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,0,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,NA,1,1,1,NA ,1,1,1,1,1,1,1,1,1,NA,1,NA,NA,1,1,1,NA,0,1,1,1,1,NA,1,1,1,1,1,1,1,1,1,1,1,1)
predictor <- c("91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days After", "91 Days After", "91 Days After",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days Before", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days After",
"91 Days After", "91 Days After", "91 Days Before", "91 Days Before", "91 Days Before", "91 Days Before",
"91 Days Before", "91 Days After", "91 Days Before", "91 Days Before", "91 Days After", "91 Days Before",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After", "91 Days After",
"91 Days Before")
id <- c(46, 109, 82, 98, 98, 104, 98, 82, 27, 27, 25, 104, 44, 77, 102,44, 25, 104, 82, 66, 25, 66, 66, 66, 66, 111, 25, 111, 111, 46, 111, 46, 25, 25, 32, 25, 25, 25, 46, 25, 46, 25, 111, 32, 104, 111, 32, 111, 109,51, 32, 36, 4, 104, 32, 44, 34, 34, 19, 102, 65, 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 43, 43, 43, 43, 43, 43,43, 68, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,53, 53, 97, 97, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 29, 29, 29, 29,29, 29, 29, 13, 13, 13, 13, 13, 13, 13, 13, 13, 34, 34, 34, 24, 24, 24, 24, 24, 32, 32, 32, 32, 32, 76, 17, 17, 14, 14, 93, 85, 85, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 88, 88, 88, 88, 88, 88, 51, 51, 51, 51, 51, 51, 51, 92,92, 92, 45, 45, 45, 90, 90, 90, 90, 90, 58, 58, 58, 58, 58, 58, 58, 58, 83, 4, 4, 39, 81, 94, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,64, 64)
library(tidyverse)
library(broom.mixed)
ex_data <- cbind(id, predictor, outcome) %>%
as.data.frame() %>%
dplyr::mutate(id = factor(id),
predictor = factor(predictor),
outcome = factor(outcome))
lme4::glmer(outcome ~ predictor + (1|id),
data = ex_data,
family = binomial) %>%
broom.helpers::tidy_plus_plus(exponentiate = TRUE, intercept = TRUE) %>%
knitr::kable()
term | original_term | variable | var_label | var_class | var_type | var_nlevels | contrasts | contrasts_type | reference_row | label | n_obs | n_event | effect | group | estimate | std.error | statistic | p.value | conf.low | conf.high |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
(Intercept) | (Intercept) | (Intercept) | (Intercept) | NA | intercept | NA | NA | NA | NA | (Intercept) | 270 | 264 | fixed | NA | 2.056839e+04 | 5.618032e+04 | 3.6360619 | 0.0002768 | 97.3273899 | 4.346757e+06 |
predictor91 Days After | NA | predictor | predictor | factor | dichotomous | 2 | contr.treatment | treatment | TRUE | 91 Days After | 137 | 134 | NA | NA | 1.000000e+00 | NA | NA | NA | NA | NA |
predictor91 Days Before | predictor91 Days Before | predictor | predictor | factor | dichotomous | 2 | contr.treatment | treatment | FALSE | 91 Days Before | 133 | 130 | fixed | NA | 6.825077e-01 | 7.266704e-01 | -0.3587669 | 0.7197695 | 0.0846892 | 5.500312e+00 |
id.sd__(Intercept) | id.sd__(Intercept) | id.sd__(Intercept) | id.sd__(Intercept) | NA | ran_pars | NA | NA | NA | NA | id.sd__(Intercept) | NA | NA | ran_pars | id | 8.898623e+00 | NA | NA | NA | NA | NA |
由 reprex package (v2.0.0)
于 2021-06-24 创建