Skip to content

xtable for Cox model output

3 messages · Ravi Varadhan, Jun Yan, Frank E Harrell Jr

#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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:

            
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 02 Oct 2002 13:44:23 -0400
Ravi Varadhan <rvaradha at jhsph.edu> wrote:

            
library(Design)   # uses library(survival) and library(Hmisc)
f <- cph(Surv(dtime,event) ~ ...., surv=TRUE) # modification of coxph
w <- latex(f)   # creates f.tex for LaTeX representation of model fit

latex.cph will represent regression splines (from rcs(x,knots)) and interactions in good algebraic form.

Frank Harrell
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._