【发布时间】:2020-05-15 22:27:06
【问题描述】:
library(survival)
justices <- read.csv("http://data.princeton.edu/pop509/justices2.csv")
PREDS = c("age", "year")
m = coxph(Surv(tenure, event == 1) ~ age + year, data = justices)
summary(m)
exp(coef(m)[1])
exp(confint(m,level=(1-0.05/1))[1,])
DVMOD <- function(PREDS, data){
t <- coxph(paste0("Surv(tenure, event == 1) ~ "), PREDS + number + name, data = data)
return((c(PREDS, coef(t)[1], confint(t)[1,])))
}
all_models <- lapply(PREDS,DVMOD, PREDS = PREDS, data=justices)
我希望为 PREDS 中的每个变量运行单独的 coxph 模型,然后存储该变量的名称及其风险比和置信带。
【问题讨论】:
-
PREDS 在哪里定义为 DVMOD 函数之外的变量列表?
-
@Len Greski 我更新了对不起!
-
你研究过 tidymodels 吗?我知道这是运行一堆模型的整洁方法。
标签: r lapply sapply mapply survival