Calculating the mean of a Cox regression using R I have been asked to calculate the mean survival time for each of the two groups (expensive and cheap glasses) based on this output as a review question.
I know that a cox regression is of the form $\lambda(t) = \lambda_0(t) \exp(\beta_1x_1 + \beta_2x_2 + \dots)$. To me this appears to be similar to an exponential distribution, where the mean is $1/\lambda$, so is the mean for this $\dfrac{\lambda_0(t)}{\beta_1x_1 + \dots}$? I have looked extensively online and have not found a clear way to calculate this. This seems like a very simple question, so I must be misunderstanding something fundamental about what Cox regression is actually doing.
My sample solution is here if people can point out where I may have gone wrong?
$\lambda (t)=\lambda_0(t)\exp(-0.9399x_1)$ for the expensive wine $\implies \mu_{\text{expensive}} = \lambda_0(t)\times(-0.9399)$
$\lambda (t) = \lambda_0(t)\exp(x_1)$ for the cheaper wine. $\implies \mu_{\text{expensive}} = \lambda_0(t)$.
Clearly this is wrong as one of the two functions would be negative and survival function can't be negative. Any insight would be greatly appreciated!
Call:
coxph(formula = Surv(parties, event) ~ cost, data = glasses2)
n= 20, number of events= 12
                coef exp(coef) se(coef) z Pr(>|z|)
costexpensive -0.9399 0.3907 0.6606 -1.423 0.155
               exp(coef) exp(-coef) lower .95 upper .95
costexpensive   0.3907     2.56        0.107   1.426

Concordance= 0.627 (se = 0.072 )
Likelihood ratio test= 2.08 on 1 df, p=0.1
Wald test = 2.02 on 1 df, p=0.2
Score (logrank) test = 2.16 on 1 df, p=0.1

 A: I wouldn't suggest trying to make a connection with the exponential distribution, as that line-of-work won't lead anywhere. You'll have to go back to first principles to calculate the mean of the Cox model. The mean of a survival time, $T$, can be calculated using its survival function, $S(t)$:
$$
E[T] = \int_0^{\inf} S(t) dt
$$
What is $S(t)$ for the Cox model? It's the following:
$$S(t) = \exp \left( -\lambda_0(t) \exp(\beta_1x_1 + \beta_2x_2 + \dots) \right) $$
Can we compute the integral now? No, because $\lambda_0(t)$ is not specified (hence the semi-parametric label). Given a dataset, we can infer $\lambda_0(t)$, but it's not going to be smooth, nor analytical (i.e. not simple to integrate).
There's another complication with the mean survival time. If the survival function, $S(t)$, does not reach 0, then the integral above is infinite. And often with the Cox model, we don't observe subjects long enough to see $S(t)$ go to 0. This is solved by using another summary statistic, like the median survival time, or the restricted-mean-survival-time, defined:
$$
RMST(\tau) = \int_0^{\tau} S(t) dt
$$
A: In R you can use the rms package's cph function which is a front-end for survival::coxph.  Then you can apply the rms Mean function to the fit object to create an R function that computes RMST from the fit object.  You can use this created function to transform axes of various graphs including nomograms and partial effect plots, as detailed in RMS course notes.
