0

I am trying to use Rstudio to apply the univariate cox proportional regression to multiple covariates at once so that the results will be displayed as data frame with approriate headings along side the covariates but I am getting an error message.

This is what I have tried...

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)

I expected to have some thing like this... for clarity

                   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

Can someone help me out please!

Mark
  • 7,785
  • 2
  • 14
  • 34

0 Answers0