我正在使用tbl_uvregression
逻辑回归,但一些分类解释变量有缺失值。缺失值类别被选为参考类别。如何实现该函数,以便我只对每个变量使用完整的案例?
下面的示例数据
structure(list(time = structure(c(5, 42, 23, 3, 26, 1, 7, 28, 5, 2, 1, 3, 23, 3, 11, 4, 2, 36, 2, 4, 53, 4, 5, 64, 14, 4, 5, 3, 31, 10, 26, 39, 4, 24, 4, 4, 6, 21, 15, 5, 3, 9, 3, 29, 63, 2, 1, 1, 16, 9, 3, 24, 1, 9, 23, 1, 6, 4, 6, 22, 57, 18, 11, 5, 9, 40, 3, 9, 1, 5, 6, 4, 12, 13, 19, 3, 6, 9, 1, 3, 29, 5, 4, 47, 33, 31, 1, 10, 18, 3, 9, 7, 42, 5, 16, 52, 1, 5, 1, 3, 5, 5, 9, 8, 17, 4, 21, 1, 22, 12, 3, 19, 10, 1, 10, 10, 1, 9, 1, 13, 8, 14, 2, 1, 32, 9, 17, 1, 5, 1, 6, 7, 7, 28, 5, 8, 33, 2, 1, 4, 1, 31, 1, 1, 45, 5, 4, 11, 1, 8, 1, 21, 8, 14, 1, 1, 3, 1, 12, 4, 6, 1, 2, 1, 2, 1, 1, 21, 2, 1, 3, 8, 12, 7, 1, 6, 9, 12, 3, 1, 6, 1, 8, 3, 21, 3), format.stata = "%10.0g"), OutcomeDischarge0Death1 = structure(c(0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,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"factor")), row.names = c(NA, -186L), class = c("tbl_df", "tbl", "data.frame"))
surv$HTN <- forcats::fct_relevel(neil$HTN, "N")
tbl_uvregression(
neil[c("time", "OutcomeDischarge0Death1", "HTN")],
method = coxph,
y = Surv(time, OutcomeDischarge0Death1),
exponentiate = TRUE,
pvalue_fun = function(x) style_pvalue(x, digits = 2)
)%>%