R/getHRandCIfromCoxph.R

Defines functions getHRandCIfromCoxph

Documented in getHRandCIfromCoxph

##' Extract hazard ratio and confidence intervals from a coxph object
##'
##' Convenience function to extract hazard ratio and confidence intervals from a coxph object,
##' as generated by a call to coxph(), comparing survival times between two groups
##'
##' @param coxphData coxph object; coxphData <- coxph(Surv(TTE, Cens) ~ group, data=df)
##'
##' @author Dorothee Nickles
##' @export
##' @import survival
##'
getHRandCIfromCoxph <- function(coxphData) {

  stopifnot(is(coxphData, "coxph"))

  tmp <- cbind(
    summary(coxphData)$coef[,
                            c("Pr(>|z|)", "exp(coef)"),
                            drop=FALSE],
    summary(coxphData)$conf[,
                            c("lower .95", "upper .95"),
                            drop=FALSE]
  )
  colnames(tmp) <- c("P","HR","CI_low_0.95","CI_up_0.95")
  tmp[,2:4]<-round(tmp[,2:4],digits=4)
  return(tmp)
}
##########################################################
IOBR/IOBR documentation built on May 5, 2024, 2:34 p.m.