Abstract
Competing risks occur in survival analysis when an individual is at risk of more than one type of event and the occurrence of one event precludes the occurrence of any other event. A measure of interest with competing risks data is the cause-specific cumulative incidence function (CIF) which gives the absolute (or crude) risk of having the event by time t, accounting for the fact that it is impossible to have the event if a competing event is experienced first. The user written command, stcompet, calculates non-parametric estimates of the cause-specific CIF and the official Stata command, stcrreg, fits the Fine and Gray model for competing risks data. Geskus (2011) has recently shown that some of the key measures in competing risks can be estimated in standard software by restructuring the data and incorporating weights. This has a number of advantages as any tools developed for standard survival analysis can then be used for the analysis of competing risks data. This paper describes the stcrprep command that restructures the data and calculates the appropriate weights. After using stcrprep a number of standard Stata survival analysis commands can then be used for the analysis of competing risks. For example, sts graph, failure will give a plot of the cause-specific CIF and stcox will fit the Fine and Gray proportional subhazards model. Using stcrprep together with stcox is computationally much more efficient than using stcrreg. In addition, the use of stcrprep opens up new opportunities for competing risk models. This is illustrated by fitting flexible parametric survival models to the expanded data to directly model the cause-specific CIF.
Keywords: st0001, Survival Analysis, Competing Risks, Time-Dependent Effects
1. Introduction
Competing risks occur in survival analysis when a subject is at risk of more than one type of event. A classic example is when there is consideration of different causes of death. If a subject dies of one particular cause they are no longer at risk of death from any other cause. Interest may lie in the cause-specific hazard rate which can be estimated using standard survival techniques by treating any competing events as censored observations at the time of of occurrence of the competing event. An alternative measure is the cause specific cumulative incidence function (CIF) which gives an estimate of absolute or crude risk of death accounting for the possibility that individuals may die of other causes(Putter et al. 2007).
A non-parametric estimate of the cause-specific CIF (Kalbfleisch and Prentice 1980) can be estimated within Stata using the user written command stcompet available from SSC (Coviello and Boggess 2004). Regression models of the cause-specific CIF are usually based around the subdistribution hazard, which is the hazard function corresponding to the cause-specific CIF. The approach of Fine and Gray (1999) is implemented within Stata via the stcrreg command. This uses a weighting procedure where individuals with a competing event remain at risk, with a weight that depends on the censoring distribution for the study population as a whole.
Geskus (2011) has recently proposed an alternative way to estimate the cause-specific CIF that uses weighted versions of standard estimators. A corresponding R command, crprep, which is part of the mstate package, has been developed that restructures the data and calculates the appropriate weights (de Wreede et al. 2011). This paper describes a Stata command, stcrprep, that has similar functionality to crprep with some further extensions to allow parametric models for the cause-specific CIF to be fitted. After using stcrprep, the cause-specific CIF can be plotted using sts graph and a Fine and Gray model can be fitted using stcox. An advantages of this approach are that some of the methods developed for the Cox model can be used for models on the subdistribution hazard scale. For example, testing and visualization of the proportional subdistribution hazards assumption can use Schoenfeld residuals using estat phtest.
Parametric models have a number of advantages over using Cox models when modelling cause specific hazard functions, if the parametric form is appropriate. Flexible parametric survival models use restricted cubic splines to estimate the underling hazard and survival functions which enables virtually any shaped hazard to be captured (Royston and Parmar 2002). These models are implemented in Stata using the stpm2 command available from SSC (Lambert and Royston 2009; Royston and Lambert 2011). This paper will show that by restructuring the data and calculation of appropriate weights these models can be used to directly estimate and model cumulative incidence functions.
This remainder of this is laid out as follows. Section 2 describes some competing risks theory and the Fine and Gray model for the cause-specific CIF. Section 3 describes the syntax of the stcrprep command. Section 4 gives some examples of using stcrprep for non-parametric estimation of the cause-specific CIF and fitting the Fine and Gray model. Section 5 describes how the approach can be extended to parametric models with section 6 giving some examples. Finally, section 7 discusses the approach and briefly describes some possible extensions.
2. Methods
In competing risks a patient is at risk from K different causes. The cause-specific hazard function, hk (t), for cause k is defined as,
When the competing events are deaths from different causes these can be thought of the mortality rate for cause k conditional on survival to time t. To be at risk at time t, an individual cannot have died of the cause of interest or any of the competing causes of death.
It is possible to transform the cause-specific hazard function to a survival function, Sk(t) as follows,
(1) |
If the competing events are assumed to be independent (conditional on covariates), then 1 – Sk(t) can be interpreted as the probability of having event k by time t in the hypothetical world where it is not possible have any of the competing events. However, in many situations the assumption of independence will not be reasonable and the estimates obtained through equation 1 are not interpretable as probabilities. Even if independence is reasonable, it may be of more interest to calculate probabilities in the real world rather than in this hypothetical world. In such situations it is of more interest to estimate the cause-specific cumulative incidence function.
The cause-specific cumulative incidence function, Fk(t) is defined as
(2) |
This gives the probability of having event k as a function of time, accounting for the fact that subjects have a chance of having one of the competing events first. It depends on the underlying hazard rates for all K causes. When estimating cause-specific CIFs the competing events do not have to be independent.
A non-parametric estimate of the cause-specific cumulative incidence function for cause k can be obtained as follows(Kalbfleisch and Prentice 1980),
(3) |
where Ŝ(tj–1) is the Kaplan-Meier estimate of the all cause survival function at time tj–1, dkj is the number of deaths due to cause k at time tj with nj being the number at risk.
A mathematically equivalent estimate of the CIF is the product limit estimate,
(4) |
where is the observed number at risk, nj, at time tj, augmented by a weighted sum of individuals who had a competing event. The weights for each individual for a competing event are obtained through estimation of the censoring distribution, Sc(t). The weight for individual i at time tj is,
(5) |
giving Note that the weight for those that experience a competing event is the probability of not being censored by time tj given that they had a competing event at time tl. The censoring distribution, Sc(t), is usually calculated using the Kaplan-Meier method. The weights are time-dependent and need to be calculated at each event time subsequent to the competing event.
2.1. Models for the cumulative incidence function
Although models that estimate the cause-specific hazards for each of the competing causes can be used to estimate cause-specific cumulative incidence function using equation 2, they provide no direct estimate of covariate effects on the cause-specific cumulative incidence function. An alternative approach was proposed by Fine and Gray (1999) who proposed a model for the subhazard function where the subhazard is defined as
The subhazard rate has quite an awkward interpretation since it is the event rate at time t for those who have not had the event of interest, but may have had a competing event. If the events are different causes of death then it is the event rate where people who have died from competing causes are still considered at risk of the event of interest.
An advantage of the subhazard function is that it is possible to derive the cause-specific CIF for cause k by the usual transformation from hazard to survival function,
(6) |
Fine and Gray defined the proportional subhazards model as
(7) |
This is of the same form as a Cox proportional hazards model, but where the hazard function has been replaced by the subhazard function. The β coefficients give log subhazard ratios. The Fine and Gray model is similar to the Cox model in that the baseline subhazard is not directly estimated. Estimation of parameters for a proportional subhazards model is more complex than the Cox model since those that experience competing events are kept in the risk set, but have time-dependent weights after their event time incorporated into the partial-likelihood with the weights being a function of the censoring distribution(Fine and Gray 1999). The weights are needed since they account for the fact that the probability that these observations could have been censored increases with follow-up time. Estimation is by maximizing the weighted partial likelihood,
(8) |
where di is the event indicator and Ri is the set of observations, j, that are at risk at time ti. Note that equation 8 is the same as the partial likelihood for the Cox model with the addition of the weights, wij. These weights are calculated internally when using the stcrreg command to fit the Fine and Gray model. When the stcrprep command is used the data is expanded and the relevant weights are calculated. These weights are the same as those given in equation 5, so that the model can be estimated using stcox.
3. Syntax
stcrprep [if] [in], events(varname) [byg(varlist) byh(varlist) censvalue(#) epsilon(#) keep(varlist) noshorten trans(numlist) wtstpm2 censcov(varlist) censdf(#) censtvc(varlist) censtvcdf(#)]
stcrprep is an st command and the data must be stset before using it. All events must be defined in the failure option of stset. The id option of stset is compulsory. The censoring distribution is estimated using the Kaplan-Meier method unless the wtstpm2 option is used.
3.1. Options
events(varname) specifies the variable that defines the different events. By default censored observations have the value 0. This can be changed using the censvalue() option.
byg(varlist) calculate censoring weights separately by varlist.
byh(varlist) calculate left truncation weights separately by varlist.
censvalue(#) The value that denotes a censored observation in the variable given in the events() option. By default this is zero.
epsilon(#) value added to survival time when calculating probability of censoring to ensure that events occur before censoring. Default value is 0.000001.
keep(varlist) names of variables to keep in expanded dataset. This is generally a list of the variables that you want to include in the analysis.
noshorten Do not collapse over rows with equal weights.
trans(numlist) lists the transitions of interest, i.e. the events contained in the events() option that you want to have as an event of interest in the analysis. By default all events are included. If only one event is of interest and the data is large then use this option to only create a data set for the specific event of interest.
The following options fits a parametric model using stpm2 for the censoring distribution.
wtstpm2 requests that the censoring distribution is estimated by fitting a flexible parametric survival model using stpm2.
censcov(varlist) lists covariates to include in the model for the censoring distribution.
censdf(#) gives the degrees of freedom used for the baseline when using stpm2 to obtain the censoring distribution. The default is 5 df.
censtvc(varlist) gives any variables to be included as time-dependent effects when using stpm2 to estimate the censoring distribution.
censtvcdf(#) gives the degrees of freedom used for any time-dependent effects when using stpm2 to obtain the censoring distribution. The default is 3 df.
4. Examples 1
4.1. European Blood and Marrow Transplantation Data
In order to demonstrate the methods we use data for 1977 patients from the European Blood and Marrow Transplantation (EBMT) registry who received an allogeneic bone marrow transplantation. Time is measured in days from transplantation to either relapse or death. There is only one covariate of interest, the EBMT risk score, which has been categorized into 3 groups (low, medium and high risk). The data is available as part of the mstate R packagede Wreede et al. (2011).
The estimated cause-specific cumulative incidence functions for relapse and for death by risk group have been estimated using stcompet and are shown in Figure 1. The more severe the risk group the higher the probability of both relapse and death.
Figure 1.
Non-parametric estimates of the cause-specific CIF for relapse and death using stcompet
4.2. Using stcrreg
The Fine and Gray model, implemented in stcrreg, will be first applied so that subsequent model results can be compared. The output below shows the model where relapse is the outcome of interest
. stset time, failure(status==1) scale(365.25) id(patid) noshow
id: patid
failure event: status == 1
obs. time interval: (time[_n-1], time]
exit on or before: failure
t for analysis: time/365.25
1977 | total observations | |||
0 | exclusions | |||
1977 | observations remaining, representing | |||
1977 | subjects | |||
456 | failures in single-failure-per-subject data | |||
3796.057 | total analysis time at risk and under observation | |||
at risk from | t | = | 0 | |
earliest observed entry | t | = | 0 | |
last observed exit | t | = | 8.454483 |
. stcrreg i.score, compete(status==2) nolog noshow
Competing-risks regression No. of obs = 1,977
No. of subjects = 1,977
Failure event : status == 1 No. failed = 456
Competing event: status == 2 No. competing = 685
No. censored = 836
Wald chi2(2) = 9.87
Log pseudolikelihood = -3333.3217 Prob > chi2 = 0.0072
(Std. Err. adjusted for 1,977 clusters in patid) | ||||||
_t | SHR |
Robust Std. Err. |
z | P>|z| | [95% Conf. Interval] | |
score | ||||||
Medium risk | 1.271221 | .1554323 | 1.96 | 0.050 | 1.000333 | 1.615465 |
High risk | 1.769853 | .3238535 | 3.12 | 0.002 | 1.236465 | 2.533337 |
The subhazard ratios (with low risk as the reference group) are estimated to be 1.27 (95% confidence interval, 1.00 to 1.62) and 1.77 (1.24 to 2.53) for the medium and high risk groups respectively. The fact that these subhazard ratios are greater than 1 is to be expected given the non-parametric estimates of the cause-specific CIF having higher values for the higher risk groups (Figure 1). The corresponding estimated subhazard ratios for death are 1.77 (1.42 to 2.21) and 2.67 (1.97 to 3.62); (output not shown).
4.3. Using stcrprep
The data will now be expanded using stcrprep and the appropriate weights calculated so that ‘standard’ survival methods can be used to estimate and model the cause-specific CIF.
The data first needs to be stset with all events defined as failures.
. stset time, failure(status==1,2) scale(365.25) id(patid)
id: patid
failure event: status == 1 2
obs. time interval: (time[_n-1], time]
exit on or before: failure
t for analysis: time/365.25
1977 | total observations | |||
0 | exclusions | |||
1977 | observations remaining, representing | |||
1977 | subjects | |||
1141 | failures in single-failure-per-subject data | |||
3796.057 | total analysis time at risk and under observation | |||
at risk from | t | = | 0 | |
earliest observed entry | t | = | 0 | |
last observed exit | t | = | 8.454483 |
The data for subject 17 (patid==17) will be compared before and after using stcrprep. This subject died after 2.29 years and in the original data set has just has one row of data as follows.
. list patid status _t0 _t _d if patid==17, noobs
patid | status | _t0 | _t | _d |
17 | died | 0 | 2.2888433 | 1 |
stcrprep is now run to expand the data.
. stcrprep, events(status) keep(score) trans(1 2) byg(score)
The events() option requires the variable defining all possible events and the censored value. The trans() option gives the transitions of the events of interest; here we are interested in the transitions to both relapse(status=1) and death (status=2); this is actually the default, but is shown here for clarity. The keep() option is used to list variables to retain in the expanded data; usually any covariates that will be later analyzed are included here. The byg() option requests the censoring distribution to be estimated separately for the given groups. Since we are first going to obtain a separate non-parametric estimate of the cause-specific CIF in each group, the byg() option will estimate the censoring distribution separately in each group. After using stcrprep the number of rows has increased from 1977 to 70262.
The expanded data for subject 17 is shown below.
. list failcode patid status tstart tstop weight_c weight_t status if patid==17, ///
> sepby(failcode) noobs //linesize(78)
failcode | patid | status | tstart | tstop | weight_c | weight_t | status |
relapse | 17 | died | 0.00000 | 2.28884 | 1.00000 | 1 | died |
relapse | 17 | died | 2.28884 | 2.31622 | 0.99000 | 1 | died |
relapse | 17 | died | 2.31622 | 2.32717 | 0.98497 | 1 | died |
relapse | 17 | died | 2.32717 | 2.36003 | 0.97992 | 1 | died |
relapse | 17 | died | 2.36003 | 2.55441 | 0.91392 | 1 | died |
relapse | 17 | died | 2.55441 | 2.65845 | 0.89843 | 1 | died |
relapse | 17 | died | 2.65845 | 2.89938 | 0.85142 | 1 | died |
relapse | 17 | died | 2.89938 | 3.02806 | 0.80937 | 1 | died |
relapse | 17 | died | 3.02806 | 3.18960 | 0.76176 | 1 | died |
relapse | 17 | died | 3.18960 | 3.26626 | 0.74578 | 1 | died |
relapse | 17 | died | 3.26626 | 3.62765 | 0.63847 | 1 | died |
relapse | 17 | died | 3.62765 | 3.89870 | 0.59519 | 1 | died |
relapse | 17 | died | 3.89870 | 3.97536 | 0.57881 | 1 | died |
relapse | 17 | died | 3.97536 | 4.10951 | 0.55124 | 1 | died |
relapse | 17 | died | 4.10951 | 4.39425 | 0.51163 | 1 | died |
relapse | 17 | died | 4.39425 | 4.50103 | 0.47714 | 1 | died |
relapse | 17 | died | 4.50103 | 4.69815 | 0.45968 | 1 | died |
relapse | 17 | died | 4.69815 | 5.08419 | 0.37101 | 1 | died |
relapse | 17 | died | 5.08419 | 5.22656 | 0.32235 | 1 | died |
relapse | 17 | died | 5.22656 | 5.33607 | 0.30995 | 1 | died |
relapse | 17 | died | 5.33607 | 5.97673 | 0.22772 | 1 | died |
relapse | 17 | died | 5.97673 | 6.27515 | 0.20170 | 1 | died |
died | 17 | died | 0.00000 | 2.28884 | 1.00000 | 1 | died |
The rows have been divided based on the failure of the newly created variable failcode. This variable will be used to fit different models depending on the event of interest. The variables patid and status are the same as in the non expanded data. The variables tstart and tstop give the times an individual starts and stops being at risk. They change within an individual when their weight, defined by variable weight_c, changes value. The weight_t gives the weights when there is left trunction. As there is no left truncation in this data, it takes the value 1 for all subjects at all times.
When failcode==1 this corresponds to when a relapse is the event of interest. As the subject with patid==17 died after 2.29 years (i.e. had a competing event), they are initially at risk until this time and they should receive a weight of 1 in the analysis. After their death they are still kept in the risk set, but their weight decreases. The decrease is based on the conditional probability of being censored which is estimated using a non-parametric (Kaplan-Meier) estimate of the censoring distribution. The weights only change at times when there is a failure for the event of interest and the value of censoring distribution has changed.
When failcode==2 this corresponds to when death is the event of interest. Since this patient experienced the event of interest, they only require one row of data.
4.4. Plotting the cause-specific CIF using sts graph
We can use sts graph to give a plot of the cause-specific CIF. We first need to stset the data utilizing the information on the weights contained in variable weights_c by specifiying iweights.
. gen event = status == failcode
. stset tstop [iw=weight_c], failure(event) enter(tstart) noshow
failure event: event != 0 & event < .
obs. time interval: (0, tstop]
enter on or after: time tstart
exit on or before: failure
weight: [iweight=weight_c]
70262 | total observations | |||
0 | exclusions | |||
70262 | observations remaining, representing | |||
1141 | failures in single-record/single-failure data | |||
13820.402 | total analysis time at risk and under observation | |||
at risk from | t | = | 0 | |
earliest observed entry | t | = | 0 | |
last observed exit | t | = | 8.454483 |
We first create the variable, event. This is defined as 1 if the event of interest occurs and zero otherwise. As we have split time data, we need to give information on the start time (tstart) and stop time (tstop) of each row of data.
We use sts graph in the usual way, but use the failure option as we are interested in the probability of relapse as opposed to the probability of not having a relapse (which includes the probability of death). For example, the cause-specific CIF for relapse can be plotted as follows,
. sts graph if failcode==1, by(score) failure ///
> ytitle("Probability of Relapse") ///
> xtitle("Years since transplanation") ///
> ylabel(0(0.1)0.5, angle(h) format(%3.1f)) ///
> legend(order(1 "Low Risk" 2 "Medium Risk" 3 "High Risk") ///
> cols(1) ring(0) pos(5)) ///
> scheme(sj) name(cif_relapse, replace)
The corresponding graph can be seen in Figure 2.
Figure 2.
Estimated CIFs after using stcrprep
This graph is the same as the graph in the left hand panel of Figure 1 with the exception that the lines are extended to the maximum censoring time in each group. Alternatively, sts gen can be used to generate the cause-specific CIF and this can be plotted with appropriate if statements to control the maximum follow-up time for each line.
4.5. Testing for differences in the CIF using sts test
Gray (1988) developed a modified log rank test for testing differences between cause-specific CIFs. A similar, but slightly different approach can be performed by applying a weighted log-rank test with weights defined in equation 5. This can be performed using sts test. Further work is required in evaluating the performance of this test under a range of different assumptions, but some simulation studies showing that it appears to have good statistical properties Mertsching (2013).
. sts test score if failcode==1
Log-rank test for equality of survivor functions
score |
Events observed |
Events expected |
Low risk | 79 | 99.64 |
Medium risk | 328 | 324.33 |
High risk | 49 | 32.04 |
Total | 456 | 456.00 |
chi2(2) = 13.37
Pr>chi2 = 0.0012
There is strong evidence of a difference in the probability of relapse between the groups.
4.6. Proportional subhazards model using stcox
When we previously used stcrprep the weights were calculated separately in each risk group as we were interested in calculating the cause-specific CIF separately for each of these groups. The original data is now reloaded and stcrprep is run again, but this time the censoring distribution used to generate the weights is calculated for the cohort as a whole, i.e. the byg() option is not used. This is because we want to fit the same model as that fitted by stcrreg, which does not calculate weights separately by subgroup.
. stset time, failure(status==1,2) scale(365.25) id(patid) noshow
id: patid
failure event: status == 1 2
obs. time interval: (time[_n-1], time]
exit on or before: failure
t for analysis: time/365.25
1977 | total observations | ||
0 | exclusions | ||
1977 | observations remaining, representing | ||
1977 | subjects | ||
1141 | failures in single-failure-per-subject data | ||
3796.057 | total analysis time at risk and under observation | ||
at risk from t | = | 0 | |
earliest observed entry t | = | 0 | |
last observed exit t | = | 8.454483 |
. stcrprep, events(status) keep(score) trans(1 2)
After defining the event indicator and using stset, a proportional subhazards model for relapse can be fitted as follows,
. gen event = status == failcode
. stset tstop [iw=weight_c], failure(event) enter(tstart) noshow
failure event: event != 0 & event < .
obs. time interval: (0, tstop]
enter on or after: time tstart
exit on or before: failure
weight: [iweight=weight_c]
127730 | total observations | ||
0 | exclusions | ||
127730 | observations remaining, representing | ||
1141 | failures in single-record/single-failure data | ||
14418.735 | total analysis time at risk and under observation | ||
at risk from t | = | 0 | |
earliest observed entry t | = | 0 | |
last observed exit t | = | 8.454483 |
. stcox i.score if failcode == 1, nolog
Cox regression -- Breslow method for ties
No. of subjects = 72,880 Number of obs = 72,880
No. of failures = 456
Time at risk = 6026.27434
LR chi2(2) = 9.63
Log likelihood = -3333.3112 Prob > chi2 = 0.0081
_t | Haz. Ratio | Std. Err. | z | P>|z| | [95% Conf. Interval] | |
score | ||||||
Medium risk | 1.271235 | .1593392 | 1.91 | 0.056 | .9943389 | 1.625238 |
High risk | 1.769899 | .3219273 | 3.14 | 0.002 | 1.239148 | 2.52798 |
The output gives the subhazard ratios for the medium and the high risk groups. The parameter estimates are the same as those produced by stcrreg in section 4.2 to 4 decimal places. The standard errors are slightly different. This is because a clustered sandwich estimator has not been used since Geskus showed that the sandwich estimator was asymptotically unbiased, but less efficient than using the standard errors derived using the observed information matrix (Geskus 2011). If one uses pweights rather than iweights with using stset and the vce(cluster patid) option for the stcox command, then the standard errors are the same as stcrreg to 4 decimal places.
4.7. Time gains for large datasets
Fitting Fine and Gray models for large data sets is computationally intensive due to each subject with a competing event having time-dependent weights. One of the advantages of the approach using stcrprep is that after the data is expanded and the weights applied, it can be much quicker to fit the models. As an example, the EBMT data was increased in size by a factor of 10 (i.e. N = 19,770), small random numbers were added to the event times to ensure there were no ties. Fitting the same model as above using stcrreg took just under 47 minutes on an Intel I7 @ 2.00GHz running Stata 13 MP2 on 64 bit Windows 7. Running stcrprep took just over 15 minutes and fitting the model using stcox took 1.5 seconds. The key point here is that stcrprep only needs to be run once and thus the process of model building and comparison becomes much quicker.
4.8. Testing the proportional subhazards assumption
One of the advantages of fitting proportional subhazards models after using stcrprep is that some of the standard tools developed for the Cox model can be used. For example, we can test the assumptions of proportional subhazards using the test developed using Schoenfeld residuals.
. estat phtest, detail km
Test of proportional-hazards assumption
Time: Kaplan-Meier
rho | chi2 | df | Prob>chi2 | |
1b.score | . | . | 1 | . |
2.score | -0.16806 | 12.81 | 1 | 0.0003 |
3.score | -0.18701 | 15.80 | 1 | 0.0001 |
global test | 18.52 | 2 | 0.0001 |
It can be seen that there is strong evidence of non-proportional subhazards for both the medium and high risk groups. This is confirmed by inspection of the Schoenfeld residual plots produced using the estat phtest command with the plot() option. The graph for the medium risk group is shown in Figure 3.
Figure 3.
Assessing the proportional subhazards assumption using Schoenfeld residuals
See section 6.2 for how non-proportional subhazards can be modeled parametrically.
4.9. Estimation within one model
If interest lies in the cause-specific CIF for both events then two separate models can be fitted. Alternatively, the same parameters can be estimated from just fitting one model, stratified by event type. The code for this is as follows.
. stcox ibn.failcode#i(2 3).score, strata(failcode) nolog
Stratified Cox regr. -- Breslow method for ties
No. of subjects = 100,732 Number of obs = 100,732
No. of failures = 1,141
Time at risk = 11077.05194
LR chi2(4) = 55.30
Log likelihood = -8337.8823 Prob > chi2 = 0.0000
_t | Haz. Ratio | Std. Err. | z | P>|z| | [95% Conf. Interval] | |
failcode# score |
||||||
1 2 | 1.271235 | .1593392 | 1.91 | 0.056 | .9943389 | 1.625238 |
1 3 | 1.769899 | .3219273 | 3.14 | 0.002 | 1.239148 | 2.52798 |
2 2 | 1.768168 | .2002336 | 5.03 | 0.000 | 1.41622 | 2.207581 |
2 3 | 2.671037 | .4085735 | 6.42 | 0.000 | 1.97914 | 3.604819 |
Stratified by failcode |
In this case the estimates are identical to fitting two separate models. The reasons for modeling in this way is that in more complex models the effect of some covariates can be forced to be the same for the different event types. This may be beneficial when one of the events is rare.
4.10. Fitting cause-specific hazards models
It is possible to fit a cause-specific hazards model after using stcrprep rather than reloading the original data by restricting the analysis to the first row of data for each individual. For example, cause-specific Cox proportional hazards models can be fitted for relapse as follows.
. bysort failcode patid (tstop): gen firstrow = _n == 1
. stcox i.score if failcode == 1 & firstrow, nolog
Cox regression -- Breslow method for ties
No. of subjects = 1,977 Number of obs = 1,977
No. of failures = 456
Time at risk = 3796.057495
LR chi2(2) = 33.00
Log likelihood = -3161.9912 Prob > chi2 = 0.0000
_t | Haz. Ratio | Std. Err. | z | P>|z| | [95% Conf. Interval] | ||
score | |||||||
2 | 1.539886 | .193302 | 3.44 | 0.001 | 1.20403 | 1.969428 | |
3 | 2.959512 | .5413436 | 5.93 | 0.000 | 2.06786 | 4.235638 |
Stacked cause-specific hazards models similar to section 4.9 can also be fitted by stratifying by failcode
5. Parametric Models
There are a number of situations where fitting a parametric model for the cause-specific CIF can be beneficial. Here we show that the the general ideas of Geskus regarding data expansion and weighting can also be applied to parametric models. Previous parametric models for the cause-specific CIF have required the CIF for all of the K causes to be modeled simultaneously and have used more standard survival distributions such as the Weibull and Gompertz distributions (Jeong and Fine 2006, 2007). Here we extend the ideas of the non-parametric models allow modelling of a cause-specific CIF by incorporating the censoring weights. For the non-parametric estimates and the semi-parametric Fine and Gray model, the censoring distribution has to be evaluated at the event times of the event of interest. When fitting a parametric model for the CIF using weighted maximum likelihood, the censoring distribution is a continuous function of time. The contribution of the ith subject to the log-likelhood is defined as follows,
(9) |
where is the subhazard function and the cumulative subhazard function of the event of interest. To implement in practice the integral in equation (9) can be approximated by splitting the time-scale after a competing event into a finite number of intervals and assuming that the weight is constant within each interval. The number of intervals per subject, Nij, will vary as the length of follow-up will depend on the time of their competing event. The likelihood becomes,
(10) |
where ti denotes the time to an event or censoring with binary event indicators, d1i and d2i, for the primary (event 1) and competing (event 2) events, tij gives the jth follow-up time after individual i has had a competing event. The weights, wij, give the conditional probability of censoring at the jth follow-up time for individual i. It is possible to use the Kaplan-Meier estimate, but instead a flexible parametric survival model is used. This enables evaluation of the censoring distribution relatively simple as there is analytic expression for the conditional censoring distribution. For further details of the parametric approach see Lambert et al. (2016 (submitted).
The advantage of this approach is that after restructuring the data by creating extra rows for those with a competing event and calculating the weights we can use standard parametric survival models to estimate the cause-specific CIF as long as the software allows weighted likelihood estimates and delayed entry. In the following section we use flexible parametric survival models using the stpm2 command.
6. Examples 2
6.1. Parametric proportional subhazards model
In the following code the use of the wtstpm2 option when using stcrprep requests that the censoring distribution be estimated parametrically using a flexible parametric survival model with the censdf(4) option requesting 4 degrees of freedom (5 knots) to estimate the survival function of the censoring distribution. The every(0.25) option means that the weights for those with a competing event will be estimated every 0.25 years after their competing event.
. stset time, failure(status==1,2) scale(365.25) id(patid) noshow
id: patid
failure event: status == 1 2
obs. time interval: (time[_n-1], time]
exit on or before: failure
t for analysis: time/365.25
1977 | total observations | |||
0 | exclusions | |||
1977 | observations remaining, representing | |||
1977 | subjects | |||
1141 | failures in single-failure-per-subject data | |||
3796.057 | total analysis time at risk and under observation | |||
at risk from | t | = | 0 | |
earliest observed entry | t | = | 0 | |
last observed exit | t | = | 8.454483 | |
. stcrprep, events(status) keep(score) trans(1 2) wtstpm2 censdf(4) every(0.25) |
After using stset in the same way as in section 4.6 a parametric model can be fitted to model the cause-specific CIF for relapse. Here a flexible parametric survival model is fitted using the stpm2 command. This means that the underlying subhazard function is estimated using a restricted cubic spline function. Other parametric models, such as those incorporated into streg, could also be used.
. stpm2 i.score if failcode == 1, df(4) scale(hazard) nolog eform
note: delayed entry models are being fitted
Log likelihood = -1678.9025 Number of obs = 23,673
exp(b) | Std. Err. | z | P>|z| | [95% Conf. Interval] | ||
xb | ||||||
score | ||||||
2 | 1.270361 | .1592233 | 1.91 | 0.056 | .9936652 | 1.624105 |
3 | 1.769961 | .3219309 | 3.14 | 0.002 | 1.239203 | 2.528048 |
_rcs1 | 1.427308 | .02829 | 17.95 | 0.000 | 1.372923 | 1.483846 |
_rcs2 | 1.124042 | .0158208 | 8.31 | 0.000 | 1.093458 | 1.155482 |
_rcs3 | 1.038305 | .0135277 | 2.89 | 0.004 | 1.012127 | 1.06516 |
_rcs4 | .9690918 | .0078049 | -3.90 | 0.000 | .9539146 | .9845105 |
_cons | .2090643 | .0235494 | -13.89 | 0.000 | .1676481 | .260712 |
The subhazard ratios are very similar to those obtained when using a weighted Cox model in section 4.6, as are the associated standard errors. Note that 5 additional parameters have been estimated that give a parametric form for the cause-specific CIF. Predictions of the cause-specific CIF can be obtained using the failure option of the predict command for stpm2.
. range temptime 0 7.2 200
(39,027 missing values generated)
. predict CIF1, failure at(score 1) timevar(temptime) ci
. predict CIF2, failure at(score 2) timevar(temptime) ci
. predict CIF3, failure at(score 3) timevar(temptime) ci
As the number of observations is now fairly large, the timevar() option of the predict command has been used. First a new variable is created using range, to create a variable, temptime, with 200 observations equally spaced between between 0 and 7.2. Using timevar() in conjunction with the at() option enables plotting predictions for 200 observations rather than the 39,227 values of _t, which would be the default. The ci option requests that confidence intervals be calculated with the names newvarname _lci and newvarname _uci. The baseline cause-specific CIF (score = 1) with a 95% confidence interval is plotted in the left panel of Figure 4 with the cause-specific CIF’s for all three groups plotted in the right hand panel.
Figure 4.
Prediction of cause-specific CIFs for relapse after using stpm2. Panel (a) shows the baseline cause-specific CIF with a 95% confidence interval and panel (b) shows the cause-specific CIFs for the three risk groups.
Various other predictions are available, for example the following code calculates the difference in cause-specific CIFs for relapse between the high and the low risk groups with a 95% confidence interval.
. predict CIF_diff, sdiff1(score 1) sdiff2(score 3) timevar(temptime) ci
These predictions are plotted in Figure 5. This gives and estimate of the difference in absolute risk of relapse between the two risk groups accounting for the competing event of death. The reciprocal of the difference in CIFs estimates the Number Needed to Treat (NNT) accounting for competing risks (?).
Figure 5.
Prediction of difference in cause-specific CIFs for relapse between high and low risk groups after using stpm2.
6.2. Non-proportional subhazards
One of the advantages of the flexible parametric survival approach is the ability to model non-proportional hazards. These advantages carry over to the models fitted after using stcrprep to allow for non-proportional subhazards. Time-dependent effects are fitted by adding interactions between the covariate of interest and some restricted cubic splines to the model. For more details of fitting time-dependent effects for these types of models, see Lambert and Royston (2009) and Royston and Lambert (2011). The time-dependent effects can be fitted through use of the tvc() and dftvc() options. Below is the code to fit a non-proportional subhazards model for relapse (proportional subhazards for death was a reasonable assumption).
. qui tab score, gen(score)
. stpm2 score2 score3 if failcode == 1, df(4) scale(hazard) nolog ///
> tvc(score2 score3) dftvc(1)
note: delayed entry models are being fitted
Log likelihood = -1669.8042 Number of obs = 23,673
Coef. | Std. Err. | z | P>|z| | [95% Conf. Interval] | ||
xb | ||||||
score2 | .228696 | .1254022 | 1.82 | 0.068 | -.0170877 | .4744797 |
score3 | .5271293 | .1827853 | 2.88 | 0.004 | .1688766 | .885382 |
_rcs1 | .5427155 | .0601134 | 9.03 | 0.000 | .4248953 | .6605356 |
_rcs2 | .1243894 | .0141427 | 8.80 | 0.000 | .0966702 | .1521086 |
_rcs3 | .0414002 | .0131365 | 3.15 | 0.002 | .0156531 | .0671473 |
_rcs4 | -.0286467 | .0081218 | -3.53 | 0.000 | -.0445651 | -.0127283 |
_rcs_score21 | -.2132078 | .0640181 | -3.33 | 0.001 | -.338681 | -.0877347 |
_rcs_score31 | -.2983195 | .0758822 | -3.93 | 0.000 | -.447046 | -.149593 |
_cons | -1.562087 | .1126074 | -13.87 | 0.000 | -1.782793 | -1.34138 |
The tvc() option of stpm2 does not allow factor variables to be used, so dummy variables have been created using the tab command. The dftvc(1) option requests that the time dependent effects are a simple function of log(time). Using more degrees of freedom would model the time-dependence using restricted cubic splines in the same way as for the baseline, but 1 df is sufficient here. After fitting the model, predictions of the cause-specific CIF can be obtained in the same way as above.
. predict CIF1_tvc, failure zeros timevar(temptime) ci
. predict CIF2_tvc, failure at(score2 1) zeros timevar(temptime) ci
. predict CIF3_tvc, failure at(score3 1) zeros timevar(temptime) ci
Note the use of the zeros option which forces all covariates to be zero except those listed in the at() option. The predictions can be plotted as before. The predictions from both the proportional subhazards and non-proportional subhazards model are shown in Figure 6 with the empirical cause-specific CIF shown for comparison (obtained using stcompet). The predicted values from the non-proportional subhazards model give a much closer fit to the empirical cause-specific CIFs.
Figure 6.
Comprison of (a) proportional and (b) non-proportional) pansubhazards model for relapse. The dashed lines are the empirical estimates of the cause-specific CIFs obtained using stcompet.
6.3. Models on other scales
The models fitted using stpm2 above use the scale(hazard) option which requests that models be fitted on the log cumulative subhazard scale. When modeling cause-specific hazards other options when using stpm2 include proportional odds models (scale(odds)), probit models (scale(normal)) and the Aranda-Ordaz family of link function (scale(theta)). For more details of these models see Royston and Lambert (2011). It is possible to use all these link functions for modelling of the cause-specific CIF. This is illustrated using a proportional odds model. This idea of using a logit link of the cause-specific CIF is similar to ideas published by Fine (1999), who used semiparametric transformations models, and by Klein and Andersen (2005) who used generalized estimating equations applied to pseudovalues to model the cause-specific CIF. The later is implemented via the Stata command stpci(Parner and Andersen 2010).
The use of a logit link gives a proportional odds model for the CIF and makes the assumption that the odds an event due to cause k occurring up to time t (for any t) are proportional across covariate patterns. The model is as follows,
An example of fitting a proportional odds model for the cause-specific CIF for relapse using stpm2 with scale(odds) is shown below,
. stpm2 i.score, scale(odds) df(4) nolog eform
note: delayed entry models are being fitted
Log likelihood = -4032.1604 Number of obs = 39,227
exp(b) | Std. Err. | z | P>|z| | [95% Conf. Interval] | ||
xb | ||||||
score | ||||||
2 | 1.657222 | .1566403 | 5.34 | 0.000 | 1.376972 | 1.994509 |
3 | 2.674231 | .3717455 | 7.08 | 0.000 | 2.036447 | 3.511759 |
_rcs1 | 1.371692 | .0155809 | 27.82 | 0.000 | 1.341491 | 1.402572 |
_rcs2 | 1.174037 | .0109122 | 17.26 | 0.000 | 1.152843 | 1.19562 |
_rcs3 | 1.031093 | .0079927 | 3.95 | 0.000 | 1.015546 | 1.046878 |
_rcs4 | .9829622 | .0047848 | -3.53 | 0.000 | .9736288 | .9923851 |
_cons | .2555708 | .0218471 | -15.96 | 0.000 | .2161462 | .3021865 |
The odds of recurrence up to time t is 2.67 higher in the high risk group when compared to the low risk group. This is a proportion odds model so the odds ratio is assumed to apply for any t. This assumption could be relaxed through use of the tvc and dftvc options in the same way as in section 6.2.
A new link function has been added to stpm2 using scale(log) which uses a log link function, i.e. log(1 – S(t)). When used to model the CIF, the parameter estimates will be log relative risks of the cause-specific CIF, which has the advantage of a simple interpretation. This link function has previously been applied when using the direct binomial approach to model the cause-specific CIF (Gerds et al. 2012). The link function should be used with a degree of caution since it does not constrain the CIF to be below 1. However, for many data sets this will not lead to a problem in estimation.
The following code uses a log link function (scale(log)),
. stpm2 i.score, scale(log) df(4) nolog eform
note: delayed entry models are being fitted
Log likelihood = -4038.4053 Number of obs = 39,227
exp(b) | Std. Err. | z | P>|z| | [95% Conf. Interval] | ||
xb | ||||||
score | ||||||
2 | 1.421112 | .1060141 | 4.71 | 0.000 | 1.227804 | 1.644854 |
3 | 1.870384 | .1798566 | 6.51 | 0.000 | 1.549098 | 2.258305 |
_rcs1 | 1.284626 | .0111808 | 28.78 | 0.000 | 1.262898 | 1.306728 |
_rcs2 | 1.169755 | .0094023 | 19.51 | 0.000 | 1.151471 | 1.188329 |
_rcs3 | 1.018619 | .0071389 | 2.63 | 0.008 | 1.004722 | 1.032707 |
_rcs4 | .9817383 | .0040202 | -4.50 | 0.000 | .9738903 | .9896494 |
_cons | .2067648 | .0142718 | -22.84 | 0.000 | .1806021 | .2367175 |
The relative risk is 1.87 when comparing the high and low risk groups, i.e. the probability of relapse is 87% higher in the high risk group when compared to the low risk group. As for the proportional odds model, it assumed that this relative effect is the same throughout time, i.e. the 87% increase is assumed to apply to the cumulative probability of an event for any t. We now relax this assumption through use of the tvc() and dftvc() options.
. stpm2 score2 score3, scale(log) df(4) nolog ///
> tvc(score2 score3) dftvc(1)
note: delayed entry models are being fitted
Log likelihood = -4027.9917 Number of obs = 39,227
Coef. | Std. Err. | z | P>|z| | [95% Conf. Interval] | ||
xb | ||||||
score2 | .3558905 | .0732233 | 4.86 | 0.000 | .2123755 | .4994055 |
score3 | .6257657 | .096561 | 6.48 | 0.000 | .4365097 | .8150217 |
_rcs1 | .336392 | .0270512 | 12.44 | 0.000 | .2833726 | .3894114 |
_rcs2 | .1591962 | .0084767 | 18.78 | 0.000 | .1425821 | .1758103 |
_rcs3 | .0192598 | .0072978 | 2.64 | 0.008 | .0049564 | .0335632 |
_rcs4 | -.0174127 | .0040958 | -4.25 | 0.000 | -.0254403 | -.0093851 |
_rcs_score21 | -.0932552 | .0287435 | -3.24 | 0.001 | -.1495914 | -.0369191 |
_rcs_score31 | -.1515066 | .033426 | -4.53 | 0.000 | -.2170203 | -.0859929 |
_cons | -1.58155 | .0675385 | -23.42 | 0.000 | -1.713923 | -1.449177 |
. partpred rr if score3==1 & failcode==1, ///
> for(score3 _rcs_score3*) ci(rr_lci rr_uci) eform
(36,492 missing values generated)
note: confidence intervals calculated using Z critical values
The time-dependent relative risk is plotted in Figure 7.
Figure 7.
Relative absolute risk predicted from flexible parametric survival model with log link function.
Given that this is a ratio of a cumulative probability, the time-dependent relative risk is unlikely to change rapidly as t increases.
It is still possible to estimate difference in cause-specific CIFs from models on other scales using sdiff1() and sdiff2() in the same way as in section 6.1, as well as obtain the time-dependent subhazard ratios using hrnumerator and hrdenominator and the subhazard differences using hdiff1 and hdiff2.
7. Conclusion
I have described the use of stcrprep to restructure survival data so that standard survival analysis tools and be used to estimate and model competing risks data. The command has similar functionality to crprep in R, but has some additional options that are useful for fitting parametric survival models and also in larger data sets.
One important advantage of using stcrprep followed by stcox, rather than stcrreg, to fit a a Fine and Gray model is that it is faster. This is the case for fitting a single model, but the big advantage comes from fitting a number of models to the same dataset, for example during a model selection process, as the data expansion and generation of the weights only needs to be done once. A second advantage is that some of the standard tools used in theory developed for the Cox model can be used for the competing risks model, for example the use of Schoenfeld residuals to assess the proportional hazards assumption.
It is also possible to model the censoring distribution and thus allow the weights to depend on covariates. When the weights are based on Kaplan-Meier estimates this is through the byg() option and when modelling the censoring distribution this is through the censcov(), censtvc() and censtvcdf() options. When using stcrreg it is not possible to allow the censoring distribution to depend on covariates. The issue of modelling the censoring distribution is unresolved and often a common censoring distribution is assumed. Gerds et al. (2012) and Scheike et al. (2008) have advocated modelling the censoring distribution, but further research is required to understand in what situations it is important to do this. If one jointly models the cause-specific CIF of all causes under consideration then it is not necessary to model the censoring distribution Jeong and Fine (2007).
The stcrprep command allows a parametric model for the cause-specific CIF to be fitted. When using the flexible parametric modelling framework using stpm2 this enables a flexible parametric version of the Fine and Gray model with the ability to directly obtain predictions of the cause-specific CIF both in and out of sample. These models also allow the the proportional subhazards assumption to be relaxed by fitting interactions with time or alternatively to model on alternative scales by using different link functions.
In this article I have not covered situations where there is left truncation/delayed entry. With left truncation subjects with a competing event need to be upweighted to represent those that could potentially enter the study after the competing event. Geskus used weights based on the distribution of entry times(Geskus 2011). Currently this is implemented when using a Kaplan-Meier based estimate of the distribution of entry times, but not for parametric models. This will hopefully be updated in a future release.
About the authors
Paul Lambert is a Professor of Biostatistics at the University of Leicester, UK. He also works part-time at the Department of Medical Epidemiology and Biostatistics, Karolinska Institutet, Stockholm, Sweden. His main interest is in the development and application of methods in population based cancer research.
References
- Coviello V, Boggess M. Cumulative incidence estimation in the presence of competing risks. The Stata Journal. 2004;4:103–112. [Google Scholar]
- de Wreede L, Fiocco M, Putter H. mstate: An R package for the analysis of competing risks and multi-state models. Journal of Statistical Software. 2011;38 [Google Scholar]
- Fine JP. Analysing competing risks data with transformation models. Journal of the Royal Statistical Society (B) 1999;61:817–830. [Google Scholar]
- Fine JP, Gray RJ. A proportional hazards model for the subdistribution of a competing risk. Journal of the American Statistical Association. 1999;446:496–509. [Google Scholar]
- Gerds TA, Scheike TH, Andersen PK. Absolute risk regression for competing risks: interpretation, link functions, and prediction. Stat Med. 2012;31(29):3921–3930. doi: 10.1002/sim.5459. [DOI] [PMC free article] [PubMed] [Google Scholar]
- Geskus RB. Cause-specific cumulative incidence estimation and the Fine and Gray model under both left truncation and right censoring. Biometrics. 2011;67(1):39–49. doi: 10.1111/j.1541-0420.2010.01420.x. [DOI] [PubMed] [Google Scholar]
- Gray R. A class of K-sample tests for comparing the cumulative incidence of a competing risk. The Annals of Statistics. 1988;16:1141–1154. [Google Scholar]
- Jeong J-H, Fine JP. Direct parametric inference for the cumulative incidence function. Applied Statistics. 2006;55:187–200. [Google Scholar]
- Jeong J-H, Fine JP. Parametric regression on cumulative incidence function. Biostatistics. 2007;8(2):184–196. doi: 10.1093/biostatistics/kxj040. [DOI] [PubMed] [Google Scholar]
- Kalbfleisch JD, Prentice RL. The Statistical Analysis of Failure Time Data. New York: John Wiley and Sons; 1980. [Google Scholar]
- Klein JP, Andersen PK. Regression modeling of competing risks data based on pseudovalues of the cumulative incidence function. Biometrics. 2005;61(1):223–229. doi: 10.1111/j.0006-341X.2005.031209.x. [DOI] [PubMed] [Google Scholar]
- Lambert P, Wilkes SR, Crowther M. Flexible parametric modelling of the cause-specific cumulative incidence function. Statistics in Medicine. 2016 doi: 10.1002/sim.7208. (submitted) [DOI] [PubMed] [Google Scholar]
- Lambert PC, Royston P. Further development of flexible parametric models for survival analysis. The Stata Journal. 2009;9:265–290. [Google Scholar]
- Mertsching J. A comparison of different approaches to nonparametric inference for subdistribution. Masters thesis in mathematics. Master’s thesis, University of Amsterdam; 2013. https://esc.fnwi.uva.nl/thesis/centraal/files/f191267511.pdf. [Google Scholar]
- Parner ET, Andersen PK. Regression analysis of censored data using pseudo-observations. The Stata Journal. 2010;10:408–422. [Google Scholar]
- Putter H, Fiocco M, Geskus RB. Tutorial in biostatistics: competing risks and multi-state models. Stat Med. 2007;26(11):2389–2430. doi: 10.1002/sim.2712. [DOI] [PubMed] [Google Scholar]
- Royston P, Lambert PC. Flexible parametric survival analysis in Stata: Beyond the Cox model. Stata Press; 2011. [Google Scholar]
- Royston P, Parmar MKB. Flexible parametric proportional-hazards and proportional-odds models for censored survival data, with application to prognostic modelling and estimation of treatment effects. Statistics in Medicine. 2002;21(15):2175–2197. doi: 10.1002/sim.1203. [DOI] [PubMed] [Google Scholar]
- Scheike TH, Zhang M-J, Gerds TA. Predicting cmulative incidence probability by direct binomial regression. Biometrika. 2008;95:205–220. [Google Scholar]