19

What is the $R^2$ value given in the summary of a coxph model in R? For example,

Rsquare= 0.186   (max possible= 0.991 )

I foolishly included it a manuscript as an $R^2$ value and the reviewer jumped on it saying he wasn't aware of an analogue of the $R^2$ statistic from the classic linear regression being developed for the Cox model and if there was one please provide a reference. Any help would be great!

Macro
  • 40,561
  • 8
  • 143
  • 148
danielsbrewer
  • 2,385
  • 3
  • 20
  • 17
  • 1
    In most situations where the concept of $R^2$ is extended beyond classical linear regression, it is the squared correlation between the observed values and those predicted under the model. Could that possibly be applicable here? – Macro Jun 19 '12 at 12:54
  • 2
    No it is not related to that. – Frank Harrell Jul 17 '13 at 22:39

2 Answers2

16

Using getS3method("summary","coxph") you can look at how it is calculated.

The relevant code lines are the following:

logtest <- -2 * (cox$loglik[1] - cox$loglik[2])
rval$rsq <- c(rsq = 1 - exp(-logtest/cox$n), maxrsq = 1 - 
        exp(2 * cox$loglik[1]/cox$n))

Here cox$loglik is "a vector of length 2 containing the log-likelihood with the initial values and with the final values of the coefficients" (see ?coxph.object) and cox$n is "number of observations used in the fit".

onestop
  • 16,816
  • 2
  • 53
  • 83
Roland
  • 5,758
  • 1
  • 28
  • 60
  • 7
    If I'm not mistaken, that's the Cox & Snell pseudo R-squared. For explanation & comparision of various pseudo R-squareds, see http://www.ats.ucla.edu/stat/mult_pkg/faq/general/psuedo_rsquareds.htm . – onestop Jun 19 '12 at 14:16
4

Dividing by $n$ the number of observations in the summary of coxph is wrong, it should be the number of uncensored events; see O'Quigley et al. (2005) Explained randomness in proportional hazards models Statistics in Medicine p. 479-489.

COOLSerdash
  • 25,317
  • 8
  • 73
  • 123
Ronghui Xu
  • 41
  • 1
  • 4
    Incorrect, you divide by the number of observations, no matter how strange that sounds. To the original question, it is strange that a reviewer would not be aware of something that's been around for 20 years for the Cox model. – Frank Harrell Jul 17 '13 at 22:40
  • Adding to the exchange between Ronghui Xu and @Frank Harrell, not only does it ``sound strange'' dividing by the number of observations, it does not work. To see this, consider beta fixed at some value so that, roughly, E(R2)=0.5, and the same covariate distribution, i.e., everything the same, apart from the fact that Study 1 has twice the rate of censoring as Study 2. Although we should be estimating the same population quantity, the R2 estimates in Study 1 will be roughly half those of Study 2, regardless of sample size. Instead of 0.5 we would be getting around 0.25. –  Jul 18 '13 at 07:47
  • John it would be worth providing a little R simulation to show that. The null log likelihood also changes, doesn't it? - possibly compensating for the effect you described. Whether generalized $R^2$ us deficient in some ways or not it is highly used and there is some theory to support its strange setup. – Frank Harrell Jul 18 '13 at 18:10
  • In answer to Frank's remark, I would agree that this is not straightforward and that Frank's observation concerning the null log-likelihood is correct. I only ever viewed this quantity as an approximation to a consistent estimator of a well-defined population quantity based on information gain. The paper referred to by Ronghui Xu does carry out simulations. These show the impact of censoring, although not absent, to be much weaker when we divide by the number of failures rather than the total number of observations. –  Jul 18 '13 at 19:50
  • Live and learn. I just ran an example and saw significant variation when the censoring distribution was changed and I used $n$ in the index. Thanks for the info John; I'll reference your paper in the second edition of my book. – Frank Harrell Jul 18 '13 at 22:04
  • 1
    John would you and Ronghui tell us which measure you currently recommend? I am seeking a fraction of explained randomness that is very independent of the censoring distribution, is a strong analogy of $R^2$ in linear models, and that has a ready counterpart for logistic regression. I finally read your excellent 2005 paper - nice work. – Frank Harrell Jul 20 '13 at 15:38
  • In reading the 2005 paper carefully I am impressed with the complete censoring-free index $\rho^{2}_{W,A}$ defined in Equation 1.5 of Kent & O'Quigley 1988 _Biometrika_ 75:525. If I understand it, the only problem I can see is that to apply it to models other than the Cox model requires derivation of a variance from a generating distribution, and the formula $\frac{A}{A+1}$ only applies for the Cox model. – Frank Harrell Jul 22 '13 at 15:12
  • @FrankHarrell I sometimes see the Cox & Snell $R^2$ "normalized" by dividing by the max attainable (Nagelkerke 1991, Cragg-Uhler 1970). Is/can this also be done with the modification proposed by RonghuiXu? – Michael Nov 05 '20 at 16:24
  • 1
    Haven't looked at that. But I'm becoming more inclined towards the Kent & O'Quigley style of index as discussed [here](https://fharrell.com/post/addvalue). – Frank Harrell Nov 06 '20 at 12:58