#' Cox Regression Table Results
#'
#' Generate Hazard Ratio Table
#' @param data Input data (data.frame)
#' @param survfma A formula object of coxph function,
#' @param option Type of table structure (option = "1" or option = "2")
#' @return Table Results of Hazard Ratio with P-values
#' @details Hazard Ratio is calculated by Cox Regression.
#' @examples
#' @export
#' coxtab function
coxtab <- function(data,survfma,option){
cox.mod <- coxph(survfma,data)
sum.cox <- summary(cox.mod)
if (option == "1"){
tab <- matrix(NA,dim(sum.cox$coefficients)[1],2)
colnames(tab) <- c("HR (95% CI)","P-value")
rownames(tab) <- rownames(sum.cox$coefficients)
for (i in 1:dim(sum.cox$coefficients)[1]){
tab[i,1] <- paste0(format(sum.cox$coefficients[i,2],nsmall=2,digits=2)," (",
format(sum.cox$conf.int[i,3],nsmall=2,digits=2),", ",
format(sum.cox$conf.int[i,4],nsmall=2,digits=2),")")
tab[i,2] <- format(sum.cox$coefficients[i,5],nsmall=2,digits=2)
}
}
if (option == "2"){
tab <- matrix(NA,dim(sum.cox$coefficients)[1],3)
colnames(tab) <- c("HR","95% CI" ,"P-value")
rownames(tab) <- rownames(sum.cox$coefficients)
for (i in 1:dim(sum.cox$coefficients)[1]){
tab[i,1] <- format(sum.cox$coefficients[i,2],nsmall=2,digits=2)
tab[i,2] <- paste0("(",format(sum.cox$conf.int[i,3],nsmall=2,digits=2),", ",
format(sum.cox$conf.int[i,4],nsmall=2,digits=2),")")
tab[i,3] <- format(sum.cox$coefficients[i,5],nsmall=2,digits=2)
}
}
return(tab)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.