Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Obtaining median, mean survival with CIs after -stcox- (and/or adjusted -sts graph-)

 From Phil Clayton To statalist@hsphsun2.harvard.edu Subject Re: st: Obtaining median, mean survival with CIs after -stcox- (and/or adjusted -sts graph-) Date Sun, 6 May 2012 18:37:24 +1000

```Andrew,

The adjusted survival curves after a Cox regression can be calculated from the combination of the baseline survivor function and the linear prediction for any given combination of covariates. These can both be produced by -predict- after -stcox-.

The adjusted survival at time t is the baseline survival at time t, raised to the power of the exponent of the linear prediction (the exponent of the linear prediction is the hazard ratio for that combination of covariates).

Once you have an adjusted survival curve it's straightforward to extract the median as the shortest time at which S(t)<=0.5.

This example shows how to calculate the adjusted survival curve, and predicted median survival, for a specific set of covariates - in this case patient age 50, with or without a drug:

------------ begin example 1 ------------
* load dataset (patient survival in drug trial)
webuse drugtr, clear

* Cox regression on drug and age
stcox drug age

* baseline survivor function
predict double surv, basesurv
keep _t surv

* adjusted survival for patient aged 50, not on drug
gen age=50
gen drug=0
predict double xb_age50_drug0, xb

* adjusted survival for patient aged 50, on drug
replace drug=1
predict double xb_age50_drug1, xb

line surv_adj* _t, sort c(J J)

* median survival for patient aged 50, not on drug
display "Median survival in patient aged 50, not on drug, is `=r(min)'"

* median survival for patient aged 50, on drug
display "Median survival in patient aged 50, on drug, is `=r(min)'"
------------ end example 1 ------------

Notes:
- you can't calculate the median survival for the patient on the drug because the adjusted survival curve never gets down to 0.5
- I am not sure how to calculate the 95% CI of the predicted median survival time - presumably you would need to take into account the uncertainty in both the baseline survivor function and the linear prediction. The latter can be obtained through -predict ..., stdp-

This next example shows one way to calculate the median adjusted survival for each individual patient with their particular combination of covariates. This method is inefficient because it uses -cross- to calculate the adjusted survival for each patient at each time point. I'm sure there's a more efficient way, probably involving Mata, but for small datasets this works well. There is also an unnecessary use of a second temporary dataset, but I think it makes the method clearer.

------------ begin example 2 ------------
* load dataset (patient survival in drug trial)
webuse drugtr, clear

* Cox regression on drug and age
stcox drug age

* linear prediction for each patient
predict double xb, xb

* create a dataset containing baseline survivor function
preserve
predict double surv, basesurv
keep _t surv
sort _t
drop if surv==surv[_n-1] // we only need the steps
tempfile survivor
save `survivor'
restore

* create a datset containing the predicted median survival for each patient
gen id=_n
preserve
keep id xb
cross using `survivor'
bysort id (_t): keep if _n==1
rename _t medsurv
keep id medsurv
tempfile medsurv
save `medsurv'
restore

* now merge median survival into main dataset
merge 1:1 id using `medsurv'
------------ end example 2 ------------

As expected, the median survival is missing for patients whose adjusted survival curve never hits 0.5. It's also worth running -scatter medsurv xb- to see the relationship between the linear predictor and the median survival.

I have never tried it but I assume that calculating mean survival would involve a similar process - generating an adjusted survival curve and then calculating the area under that curve. It would be more complicated than median survival because of censoring (see for example the manual entry for -stci-).

Phil

On 06/05/2012, at 12:40 PM, graupel75@gmail.com wrote:

> Dear statalisters-
>
> Although this terrain has been discussed before, eg
>
> http://www.stata.com/statalist/archive/2009-08/msg01601.html
> http://www.stata.com/statalist/archive/2003-01/msg00736.html
>
> there was limited response. I would like obtain the predicted median
> and mean survival times, adjusted for covariates, from -stcox- or from
> -sts graph- (which displays adjustment for covariates), but I cannot
> access either set of estimates.
>
> While -streg- has -predict median time- and -predict mean time-
> options, -stcox- does not, and these estimates don't include 95% CIs.
> I cannot think of any inherent methodological reason for this, but
> perhaps there is one?
>
> cheers!
> Andrew Lover
> ______________________________________________
> Epidemiologist
> Centre for Infectious Disease Epidemiology Research (CIDER)
> Saw Swee Hock School of Public Health
> National University of Singapore
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```