[R] xtable for Cox model output

Jun Yan jyan at stat.wisc.edu
Thu Oct 3 00:47:56 CEST 2002


This is because there is no method of xtable for class "coxph". However,
you may always apply xtable on data.frame or matrix. The following
function creates a matrix tmp (as in summary.coxph) and apply xtable on
it.

xtable.coxph <- 
function (x, caption = NULL, label = NULL, align = NULL, vsep = NULL, 
    digits = NULL, display = NULL) 
{
    cox <- x
    beta <- cox$coef
    se <- sqrt(diag(cox$var))
    if (is.null(cox$naive.var)) {
      tmp <- cbind(beta, exp(beta), se, beta/se, 1 - pchisq((beta/se)^2,
1))
      dimnames(tmp) <- list(names(beta), c("coef", "exp(coef)", 
                                           "se(coef)", "z", "p"))
    }
    else {
      tmp <- cbind(beta, exp(beta), nse, se, beta/se, signif(1 -
pchisq((beta/se)^2, 1), digits - 1))
      dimnames(tmp) <- list(names(beta), c("coef", "exp(coef)", 
                                           "se(coef)", "robust se", "z",
"p"))
    }
    xtable(tmp, caption = NULL, label = NULL, align = NULL, vsep = NULL, 
           digits = NULL, display = NULL)
}



On Wed, 2 Oct 2002, Ravi Varadhan wrote:

> Hi:
> 
> I am using R 1.5.0 on Windows.  I was not able to get the xtable 
> function in the "xtable" library to recognize a Cox model object 
> from "survival" library. I was wondering whether there is another way 
> to do this.
> 
> thanks,
> Ravi.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list