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


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.


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.


© Copyright 1996–2023 StataCorp LLC. All rights reserved.

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


. estat gofplot, stratify separate



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:


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.