我正在尝试使用 Rstudio 将单变量 cox 比例回归一次应用于多个协变量,以便结果将显示为数据框,并在协变量旁边带有适当的标题,但我收到一条错误消息。
这是我尝试过的...
covariates <- c("ageatstartofart", "sex", "current_viral_load", "educationallevel", "marital_status", "job_status", "first_cd4")
uni_multi_covar <- sapply(covariates,
function(x) as.formula(paste('Surv(time, status)~', x)))
uni_multi_models <- lapply( uni_multi_covar, function(x){coxph(x, data = cox.reg)})
# Combine various covariates
univarite_results <- lapply(uni_multi_models,
`function(x){
x <- summary(x)
p.value<-signif(x$wald["pvalue"], digits=2)
wald.test<-signif(x$wald["test"], digits=2)
beta<-signif(x$coef[1], digits=2);#coeficient beta
HR <-signif(x$coef[2], digits=2);#exp(beta)
HR.confint.lower <- signif(x$conf.int[,"lower .95"], 2)
HR.confint.upper <- signif(x$conf.int[,"upper .95"],2)
HR <- paste0(HR, " (",
HR.confint.lower, "-", HR.confint.upper, ")")
res_result<-c(beta, HR, wald.test, p.value)
names(res_result)<-c("beta", "HR (95% CI for HR)", "wald.test",
"p.value")
return(res_result)
#return(exp(cbind(coef(x),confint(x))))
})`
res_result <- t(as.data.frame(univarite_results, check.names = FALSE))
as.data.frame(res_result)
为了清楚起见,我希望有这样的事情
beta HR (95% CI for HR) wald.test p.value
ageatstartofart 0.019 1 (1-1) 4.1 0.042
sex -0.53 0.59 (0.42-0.82) 10 0.0015
current_viral_load -0.016 0.98 (0.97-1) 7.9 0.005
educationallevel 0.48 1.6 (1.3-2) 18 2.7e-05
marital_status 0.347
first_cd4 0.0013 1 (0.99-1) 0.05 0.83
有人可以帮帮我吗!