Home  /  Products  /  Stata 18  /  GOF plots for survival models

<- See Stata 18's new features

Highlights

  • Parametric and semiparametric survival models

  • Right-censored and interval-censored data

  • Three estimators for the cumulative hazard function

  • By-group and stratified models

Stata 18 provides the new estat gofplot command to produce goodness-of-fit (GOF) plots for survival models. You can use it after four survival models: right-censored Cox (stcox), interval-censored Cox (stintcox), right-censored parametric (streg), and interval-censored parametric (stintreg). Check model fit after stratified models or separately for each by-group.

GOF plots provide visual checks for how well the model fits the data. In survival analysis, these checks are based on so-called Cox–Snell residuals and the assumption that, if a model is correct, these residuals should have a standard exponential distribution. Visually, this assumption is assessed by plotting the residuals against their estimated cumulative hazard—the closer the plotted values are to the 45° line, the better the fit (Cox and Snell 1968).

Let's see it work

-> GOF plots for right-censored data

-> GOF plots for interval-censored data

We use the dataset on 103 patients admitted to the Stanford Heart Transplantation Program (Crowley and Hu 1977). The dataset includes the year the patient was accepted into the program (year), the patient's age (age), whether the patient had other heart surgery previously (surgery), and whether the patient received a transplant (posttran). We wish to analyze time until death and check whether our model fits the data well. We fit a Cox model first by typing

. stcox age posttran surgery year, nolog 

        Failure _d: died
  Analysis time _t: t1
       ID variable: id

Cox regression with Breslow method for ties

No. of subjects =      103                              Number of obs =    172
No. of failures =       75
Time at risk    = 31,938.1
                                                        LR chi2(4)    =  17.56
Log likelihood = -289.53378                             Prob > chi2   = 0.0015

_t Haz. ratio Std. err. z P>|z| [95% conf. interval]
age 1.030224 .0143201 2.14 0.032 1.002536 1.058677
posttran .9787243 .3032597 -0.07 0.945 .5332291 1.796416
surgery .3738278 .163204 -2.25 0.024 .1588759 .8796
year .8873107 .059808 -1.77 0.076 .7775022 1.012628

We then use estat gofplot to visually explore the model's GOF.

. estat gofplot

Comparing the blue line with the black reference line, we conclude that our Cox model fits the data well.

For right-censored data, instead of the default Nelson–Aalen estimator (Nelson 1972; Aalen 1978), we can use option km to use the alternative minus log of the Kaplan–Meier estimator (Kaplan and Meier 1958).

Let's now fit a stratified Cox model, which assumes that the baseline hazard functions are different between patients from different groups (pgroup) but the coefficients are equal across those groups.

. stcox age posttran surg year, strata(pgroup) nolog

        Failure _d: died
  Analysis time _t: t1
       ID variable: id

Stratified Cox regression with Breslow method for ties
Strata variable: pgroup

No. of subjects =      103                              Number of obs =    172
No. of failures =       75
Time at risk    = 31,938.1
                                                        LR chi2(4)    =  20.67
Log likelihood = -213.35033                             Prob > chi2   = 0.0004

_t Haz. ratio Std. err. z P>|z| [95% conf. interval]
age 1.027406 .0150188 1.85 0.064 .9983874 1.057268
posttran 1.075476 .3354669 0.23 0.816 .583567 1.982034
surgery .2222415 .1218386 -2.74 0.006 .0758882 .6508429
year .5523966 .1132688 -2.89 0.004 .3695832 .825638

After our stratified model, we use option stratify with estat gofplot to produce a separate plot for each stratum of pgroup.

. estat gofplot, stratify

The model fits data well in all strata. The red line for pgroup = 2 deviates from the reference line toward the end. This is not uncommon to see in practice because fewer observations are available for estimation toward the end of the study.

To aid visual inspection of the plot, we can also add option separate to produce separate graphs for each stratum.

. estat gofplot, stratify separate
GOF plots for interval-censored data

We use the dataset of a study for early breast cancer patients (Finkelstein and Wolfe 1985) that compares the cosmetic effects of two cancer treatments (treat) on breast retraction. Because patients were observed at random follow-up times, the exact time of breast retraction was not observed and was known only to fall in the interval between visits (variables ltime and rtime). First, we fit an interval-censored Weibull model of time to breast retraction on treatment using stintreg:

. stintreg i.treat, interval(ltime rtime) distribution(weibull) nolog

Weibull PH regression                               Number of obs     =     94
                                                           Uncensored =      0
                                                        Left-censored =      5
                                                       Right-censored =     38
                                                       Interval-cens. =     51

                                                    LR chi2(1)        =  10.93
Log likelihood = -143.19228                         Prob > chi2       = 0.0009

Haz. ratio Std. err. z P>|z| [95% conf. interval]
treat
Radio+Chemo 2.498526 .7069467 3.24 0.001 1.434961 4.350383
_cons .0018503 .0013452 -8.66 0.000 .000445 .007693
/ln_p .4785786 .1198972 3.99 0.000 .2435844 .7135729
p 1.613779 .1934876 1.275814 2.041271
l/p .6196635 .0742959 .4898907 .7838134
Note: _cons estimates baseline hazard.

We then use estat gofplot to produce the GOF plot.

. estat gofplot

With interval-censored data, Cox–Snell-like residuals are defined and used for plotting (Farrington 2000). If a model fits the data well, these residuals should approximate the censored standard exponential distribution. Also, the nonparametric Turnbull estimator (Turnbull 1976) is used to estimate the cumulative hazard.

The jagged line stays close to the reference line in the above graph, which indicates that the Weibull model fits the data well.

Suppose that we now want to fit an exponential model and check its model fit. We type

. quietly stintreg i.treat, interval(ltime rtime) distribution(exponential)
. estat gofplot

Comparing this GOF plot with the one above, we can see that the Weibull model fits our data better than the exponential model.

References

Aalen, O. O. 1978. Nonparametric inference for a family of counting processes. Annals of Statistics 6: 701–726. https://doi.org/10.1214/aos/1176344247.

Cox, D. R., and E. J. Snell. 1968. A general definition of residuals (with discussion). Journal of the Royal Statistical Society, Series B 30: 248–275.

Crowley, J., and M. Hu. 1977. Covariance analysis of heart transplant survival data. Journal of the American Statistical Association 72: 27–36.

Farrington, C. P. 2000. Residuals for proportional hazards models with interval-censored survival data. Biometrics 56: 473–482.

Finkelstein, D. M., and R. A. Wolfe. 1985. A semiparametric model for regression analysis of interval-censored failure time data. Biometrics 41: 933–945.

Kaplan, E. L., and P. Meier. 1958. Nonparametric estimation from incomplete observations. Journal of the American Statistical Association 53: 457–481.

Nelson, W. 1972. Theory and applications of hazard plotting for censored failure data. Technometrics 14: 945–966.

Turnbull, B. W. 1976. The empirical distribution function with arbitrarily grouped, censored and truncated data. Journal of the Royal Statistical Society, Series B 38: 290–295.

Tell me more

Learn more about other new features in survival analysis.

Read more in the Stata Survival Analysis Reference Manual; see [ST] estat gofplot.

View all the new features in Stata 18.

Made for data science.

Get started today.