Survival analysis EN - pdmoerland/wiki-biostatistiek-bilingual GitHub Wiki
Deze pagina lezen in het Nederlands.
Author: dr. ir. N van Geloven
Co-author: dr. R.B. Geskus
AuthorshipThis page was translated from the Dutch-language original using AI and has not been fully reviewed. Where the two differ, the Dutch version takes precedence.
-
Kaplan-Meier analysis
- When do I use a Kaplan-Meier analysis?
- How do I test whether Kaplan-Meier survival curves differ from each other?
- My Kaplan-Meier curves cross, can I still use the log-rank test?
- I have many censored patients, can I use the Breslow or Tarone-Ware test instead of the log-rank test?
- Can I plot several separate Kaplan-Meier curves together in 1 graph?
- How can I perform my log-rank analysis over only the first year of follow-up?
- How do I handle patients who, due to death, can no longer experience the event of interest?
- How do I calculate 'events per person-year'?
- Where do I find the Kaplan-Meier analysis in SPSS?
-
Cox regression
- When do I use a Cox proportional hazards model?
- How do I test the proportional hazards assumption within a Cox model?
- My variables do not seem to satisfy the proportional hazards assumption, does that mean I cannot include them in the Cox regression?
- How do I read the output of the analysis of a categorical variable in a Cox model?
- How do I report the results of a categorical variable in a Cox model?
- My Cox regression does not converge, did I use the right analysis?
- Where do I find the Cox proportional hazards model in SPSS?
- Sources regarding competing risks
- Additional sources
Survival analysis is used for data that provide information about the time until a certain event occurs. Here, time refers to the number of years, months or weeks from the start of a patient's follow-up until the occurrence of an event. The event may be death (hence the name survival analysis), but also a relapse, recovery, or another clearly defined endpoint. In general, survival analysis assumes that there is only one type of risk and that an event can occur at most once per individual. For multiple/competing risks or multiple recurrences of an event, more advanced analysis techniques are needed, such as recurrent event analysis or competing risk analysis.
When measuring time-to-event data, censored observations often occur. In this case, you have some information about a patient's 'survival time', but you do not know exactly how long the time-to-event is. An example. Suppose that in a study patients are followed over a period of twelve weeks. Censoring can occur in three ways:
- A patient is followed from the start of the study until the end of the 12-week study period. At that point, the patient has not yet had the event. We now only know that this person's time-to-event is longer than 12 weeks.
- A patient withdraws from the study after 6 weeks, i.e. before the end of the study period. For this person we only know that the time-to-event is longer than 6 weeks. Or a patient enters the study but becomes 'lost to follow-up' after the last contact at 8 weeks. For this patient too, we only know that the event-free period is longer than 8 weeks.
- A patient cannot be followed until the end because they experience a different type of event. For example: we study the time to relapse after surgery, but a patient dies during the study without having had a relapse.
To quantify the time to the occurrence of the event for the entire sample, a Kaplan-Meier analysis is often used. The Kaplan-Meier analysis is a non-parametric approach. This means that no assumption is made regarding the type of distribution (normal, gamma etc.) of the event times. Nevertheless, there are a few assumptions underlying this method:
- The prognosis of patients included early or late in the study is the same.
- Patients who are censored at a given point in time have the same prognosis as patients who remained in the study at that same point in time (and had not yet had an event at that point). This assumption is not met if, for example, individuals with a high probability of an event leave the study shortly before the event occurs.
- The times at which the events occur are known exactly.
- Patients are followed from the start of the period under study. If, for example, follow-up of patients' survival status only starts 10 days after the intervention, then patients who had already died in the first 10 days will not be represented in the study. A Kaplan-Meier analysis then does not give a good estimate of the true survival time. Survival models that account for this phenomenon are called late entry survival models.
The basic idea behind the Kaplan-Meier procedure is to divide up the time scale. At every moment when an event occurs in one or more patients, the probability of this is estimated by dividing the number of events at that moment by the number of people who are still in the study at that moment (i.e. who have not already had an event or been censored). The survival function (or cumulative proportion of 'survivors') combines these estimates over all time points. In this way, the result is minimally affected by patients who are censored partway through. A Kaplan-Meier analysis results in a 'life table' and a 'survival curve'.
The following life table and survival curve show, for example, the expected survival probability of patients who underwent balloon angioplasty. You can see in the second column ("Time") of the life table that patients were censored on day 4 and day 6, and that there were five events on day 0, one event on day 1, two events on day 5, and one event on day 7. On the days on which an event occurred, the cumulative survival was calculated. The survival curve shows the estimated survival function over the first 200 days after the intervention. After 200 days, the probability of survival is estimated at approximately 92%.

We can also estimate and compare the curves separately for two (or more) subgroups in our data. To test whether the Kaplan-Meier curves of 2 (or more) groups differ significantly from each other, the log-rank test is often used. Here, the null hypothesis is that the curves do not differ from each other. The test compares the observed differences between the survival curves with differences that could arise if there were no difference between the groups. In the following example, we conclude, for instance, that the difference between treatment A and treatment B is significant:

In my Kaplan-Meier analyses for comparing a factor, I have curves that cross each other. In statistical texts it is sometimes said that a log-rank test is then not suitable for analyzing a potential difference between curves. Nevertheless, when I perform a log-rank test in SPSS, I sometimes still get a significant p-value. Does the log-rank test (as performed by SPSS) take into account the fact that the curves cross? Or should I actually not be allowed to use log-rank in that case?
The log-rank test does not take the crossing of curves into account. The test looks at the difference between the curves at each (event) time point and sums the differences found (specifically the difference between observed and expected events) over all time points. If, for example, 2 curves cross in the middle, then in the early period one group will have relatively more events, and in the later period the other group. When summing the differences, these two periods will cancel each other out. There is a good chance that the log-rank statistic will then not be significant, even though there may still be interesting differences in the two periods separately. For this reason, the log-rank test is considered less suitable (actually less powerful) when curves cross.
In your case, where you have crossing curves and still a significant log-rank test, the difference in one of the two periods (before or after the point where the hazard changes) will be stronger than in the other period. There is then still a 'net' difference found in one direction. This can be informative, although you need to be careful about how to interpret such a difference. See also this letter to the editor regarding an incorrect interpretation in such a situation.
I would advise you to in any case also report the plot of the survival curves (and not just the log-rank statistic), so that the reader can judge for themselves where the difference is to be expected. Statistical alternatives are the use of tests that give more weight to early or to late periods. For example the Wilcoxon test (called the Breslow test in SPSS); this test weights differences at the beginning of the survival curves more heavily than differences at the end of the curves. This test is suitable, for example, when the effect of a treatment on survival is strongest in the first phase and becomes less effective later, and you want to zoom in on the first phase. Or the Tarone-Ware test. Like the Wilcoxon test, this test gives relatively more weight to differences at early time points (but less pronounced than the Wilcoxon test). You could also consider performing the analysis separately over two time intervals, although it is then very difficult to determine where to draw the boundary. Ideally, you would have specified such alternative analyses in advance.
I have many censored patients, can I use the Breslow or Tarone-Ware test instead of the log-rank test?
The test I currently use is log-rank. I saw that there are also 2 other tests (Breslow and Tarone-Ware). It is not entirely clear to me when you use these, other than the naming which suggests that these tests mainly assess the beginning of the curve. The reason I might want to try a different test is the fact that I see a lot of censoring in the curve. The patients have not all been followed for the same length of time, so the number of patients in follow-up decreases as time passes. Can/may I use the Breslow or Tarone-Ware test in this case?
The Breslow and Tarone-Ware tests indeed 'listen' more to the early period, when more people are still in follow-up, than to the later period. However, the fact that there is a lot of censoring later in the follow-up is not a reason to choose these tests. The log-rank test, too, will be most influenced by the periods where the most people are still in follow-up. The Breslow / Tarone-Ware tests are recommended when, based on a biological hypothesis, the expectation is that the largest differences will occur in the early period (for example with a one-time treatment where the effect fades over time). These are not the standard tests, so their use will need to be clearly justified. I therefore recommend using the 'ordinary' log-rank test here; the later time points with fewer people will automatically carry less weight in the analysis.
For a paper I have 3 Kaplan-Meier curves that all run equally far on the x-axis (all a duration of 27 months). I want to put these 3 curves in 1 plot. Can this be done with SPSS and if so, how?
We figured it out ourselves, as follows: in our case we wanted to put 3 different curves (survival, major amputation and minor amputation) in 1 KM graph. We rearranged the data. 1 variable with time to event, 1 variable with event status (all three events had status 1), and a new distinguishing variable that made clear that the first time-to-event and event itself related to survival, the second time-to-event and event itself to major amputation, and the third time-to-event and event itself to minor amputation. You simply enter the time-to-event and event status, and the new distinguishing variable becomes the 'factor'. In case anyone else ever runs into the same problem, here is the solution.
At an outpatient clinic for HIV-infected children in Malawi, we followed a cohort of children from the moment they started antiretroviral therapy over the period 2004-2008. We are interested in their outcomes and risk factors for mortality and loss to follow-up (LTFU). 1) I am trying to list outcomes after 12 months using analyze_survival_lifetables. This seems to be working. 2) I want to look at predictive factors for death and death at 12 months. For univariate analyses I would like to use: analyze_survival -> kaplanmeier with compare factor log-rank test. With this I perform an analysis for the outcome over the total duration of follow-up. I cannot manage to specifically look at outcomes up to 12 months with this.
If there is a longer follow-up, and you want to focus an analysis only on the period up to 12 months, then it is necessary to censor the information of the individuals at 12 months. If all is well, you now have the following 2 variables in the dataset:
-time to last follow-up or time to occurrence of event (mortality or treatment dropout): FUtime
-event indicator (whether or not the event occurred): FUstatus (1=event, 0=no event)
To focus on only the first 12 months, the following adjustments need to be made:
if FUtime>12 and FUstatus =0 -> FUtime=12 FUstatus=0
if FUtime>12 and FUstatus =1 -> FUtime=12 FUstatus=0
if FUtime=<12 and FUstatus =1 -> variables remain the same
if FUtime=<12 and FUstatus =0 -> variables remain the same
With the new FUtime (which is never greater than 12) and the new status (which now contains slightly fewer events), a Kaplan-Meier analysis can be performed for only the first year.
I conducted an RCT with a follow-up of 1 year with as the main outcome measure: the number of days from randomization to return to work. Now I want to investigate whether the time to return to work differs significantly between the two groups (control group and intervention group). For this I performed a KM survival analysis with a log-rank test. Now it turns out that a number of patients died during the follow-up period and a number of patients are being treated palliatively. These patients can never achieve the positive outcome measure (back to work) again. How do you deal with these patients in the survival analysis? Should I remove these patients from the analysis entirely? Should I treat them as censored? Should I regard these patients as a negative outcome (= not working)? In short, what is the effect of censored data on a survival analysis and log-rank test, and which approach is most appropriate?
The advantages and disadvantages of the various alternatives:
- keeping the deceased/palliative patients in the KM analysis and censoring them at the moment of this event
Advantage: the information from these patients before they died / before they were palliative is included in the analysis / no loss of data Disadvantage: the KM analysis assumes that the prognosis of these patients, after they are censored, is the same as that of patients still remaining in the analysis (assumption of non-informative censoring). The estimates (and comparisons) at later follow-up time points are therefore (disproportionately) largely determined by relatively good patients who may not be representative of the total group.
- excluding the deceased/palliative patients from the KM analysis
Advantage: an approach that is easy to explain, you restrict the study group as if it were an exclusion criterion Disadvantage: this is only a logical approach if at t=0 it is already known that someone belongs to the 'exclusion group'; for these individuals you could argue that the intervention can no longer have any influence on return to work because that (regardless of which treatment) cannot affect this outcome. For individuals who at the start could still go either way and only deteriorate later, it would be a shame/could introduce bias not to use that information.
- treating the deceased/palliative patients in the KM analysis as a negative outcome / Competing risk analysis
Advantage: you could argue that these patients have an ultimate 'bad' outcome and should also be counted as such. You are then essentially saying that they will never achieve the event 'return to work'. Their status is then set to 0, and the follow-up time could (artificially) be set to infinitely long (or at least longer than the longest follow-up). You can also do this formally in a competing risk analysis. Disadvantage: the analysis is less standard / competing risk analysis is not offered as standard in SPSS.
I would like to present my outcomes (admissions related to abdominal adhesions and the occurrence of incisional hernias) as 'events per person-years at risk', in order to correct for the varying follow-up duration. What is the best way to do this? I could create a Kaplan-Meier of time-to-event, but I would also like to present this measure. Should I create a variable in which I divide event yes/no by the time 'at risk'? Or is there a function in SPSS with which I can calculate this more easily?
The outcome 'events per person-years at risk' is simple to calculate by adding up all the events (sum_events), adding up all the time at risk (sum_time), and dividing these two by each other: sum_events/sum_time.
Because SPSS is used to calculating 'per row' rather than per column, these summations are easier to do if you put the data into another package (Excel or R) for a moment.
For the measure 'events per person-years at risk' you probably also want to calculate a confidence interval? You could calculate this using the calculator at www.openepi.com. In the left-hand menu choose person time -> 1 rate. Enter the number of events and the total time. You then get the rate and a confidence interval back. Pay close attention, the rate is given per 10, 100, 1000 person-years (depending on the number of informative decimal places). It is therefore a good idea to compare these numbers with your own calculation (as above).
You will find the Kaplan-Meier analysis in SPSS 28 under Analyze -> Survival -> Kaplan-Meier.
When in a survival analysis only one predictive factor is examined that can take only a few possible values, a Kaplan-Meier analysis may suffice. However, if there are multiple factors that can influence survival, a more extensive model is needed. A commonly used model is the Cox proportional hazards model. With this, just as with other multivariable regression models, you can study multiple predictors simultaneously. An advantage of the Cox model over a Kaplan-Meier analysis is moreover that, in addition to the question "is there an effect", it also answers the question "how large is the effect" of a given predictor. The Cox model expresses the size of an effect using hazard ratios (HR), where an HR of 1 indicates that there is no difference. The hazard is the instantaneous probability of experiencing an event, and a hazard ratio is comparable to a relative risk. For example: "During the 20-year follow-up, 83 women developed lung cancer. There was a moderate association between hormone use and lung cancer (hazard ratio, 1.13; 95% CI, 1.08-1.73)."
The Cox model makes an important assumption: the proportional hazards assumption. This states that the HRs are constant over time. This means that the relative difference in hazard caused by different values of a predictor remains the same over time. In the example above, it is therefore assumed that using or not using hormones has the same effect after 1 year as after 20 years of follow-up: at every point in time, the probability of developing lung cancer with hormone use is estimated to be 1.13 times higher than the same probability without hormone use. In a Cox regression, there are otherwise no specific assumptions about the distribution of the hazard function or predictor variables. They therefore do not need to be normally distributed.
There are several ways to test the PH assumption of a Cox model:
-
Graphically If a variable in the model satisfies the proportional hazards (PH) assumption, then the estimated survival curves, on the so-called log scale, will run parallel for the values of this variable. You can check this by including, in the Cox model, the variable for which you want to examine the PH assumption not as a covariate but as a stratum, and requesting log-minus-log survival plots. The resulting lines should appear to run parallel (and certainly not cross each other) to satisfy the PH assumption for this variable. Such a plot is needed for each variable in the model. In this example syntax you can see what creating a log-minus-log plot looks like in SPSS syntax.
-
Testing (Schoenfeld) residuals A formal test can be performed using Schoenfeld residuals. There is no standard function for this in SPSS. In Stata (function estat phtest) or R (function cox.zph) this can be done directly.
-
Adding a time-dependent variable Anticipating that the PH assumption might not be satisfied, you can also run a time-dependent Cox model that includes a time-dependent variable (for example GENDER*T). If this time-dependent variable contributes significantly to the model, then apparently the PH assumption is not satisfied.
My variables do not seem to satisfy the proportional hazards assumption, does that mean I cannot include them in the Cox regression?
I have been testing the proportional hazards assumption. In the log-log plots, the lines of almost all covariates cross. Does this mean that I am not allowed to include any of these covariates in the analysis?
It is not the case that if the lines cross you may then not include the variable at all. You need to examine each variable individually to see what is going on. Possible options:
-
A variable is not related to the outcome measure. The log-minus-log survival curves are then expected to lie on top of each other. Due to random fluctuation the curves can also 'wobble around each other' and therefore cross multiple times. The conclusion here is that there is no effect (also no proportional effect).
-
A variable is related to the outcome measure, but the curves cross at a certain point. This is more difficult. If the curves cross, then the effect of a variable is not proportional. That is, in one time interval one group is better off and in the other time interval the other group. If the Cox analysis nevertheless indicates a proportional effect of a variable, this means something like: averaged over the whole timeline, one of the 2 groups still comes out better. 'On average' this group does better. This can be a valid conclusion in certain situations, but when only the Cox results (HRs) are shown, this does not tell the whole story. For example, if a group shows a large advantage at the start but does worse than its counterpart towards the end of follow-up, then it is to be expected that in an even longer follow-up period the effect could reverse. This information is good to mention; if a reader sees only the HR, they will think that the group will do better at every point in time. When the variable clearly (and explainably) shows a differential effect over time, it can be wise to estimate 2 HRs, 1 for the early period and 1 for the late period. This can be done by creating a time-dependent covariate.
For a cohort of HIV-infected children, followed from the moment they start antiretroviral medication, I am looking for predictors of death. I am currently working on the Cox regression (so far working on univariate analysis). Below is an example of output for a categorical variable (age categories) with more than 2 categories (reference = children >12 years old, who we expect to have the best prognosis). (1) (2) (3) relate to children aged 0-1 year, 1-5 years and 5-12 years. What does the p-value listed on the line of the reference value mean?
| Variables in the Equation | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| B | S.E. | Wald | df | Sig. | Exp(B) | 95.0% C.I.for Exp(B) | |||
| Lower | Upper | ||||||||
| Age | age | 23.539 | 3 | .000 | |||||
| age(1) | 1.094 | .261 | 17.613 | 1 | .000 | 2.985 | 1.791 | 4.795 | |
| age(2) | .773 | .211 | 13.379 | 1 | .000 | 2.166 | 1.431 | 3.276 | |
| age(3) | .351 | .236 | 2.206 | 1 | .137 | 1.420 | .894 | 2.256 | |
The first row shows the result of the overall test for the variable. This is the test whose null hypothesis is that all 4 categories have the same probability (actually hazard) of death. The test looks at whether there is a difference anywhere among the categories; you can also see that the test has 3 'degrees of freedom'. You can compare it to an ANOVA test when comparing mean values across 4 groups. So the test is not specifically tied to the reference category; SPSS simply finds that a convenient place to put it. In principle you proceed as follows: you first look at whether the overall test is significant. If so, you are then permitted to proceed and look at the differences between the categories themselves.
I performed a Cox regression with a dichotomous outcome measure (development or non-development of arthritis) and the variable is a categorical measure (0-4). Normally I am used to reporting the result for a continuous variable as follows: HR x.x (95% CI x.x to x.x); p=0.xxx. However, I now read that because of the categorical measure you should look at the Wald result; this does give a p-value, but no CI etc. How should I then report this result in a manuscript?
Usually the significance tests for HRs in Cox regression are generated with a Wald statistic. This applies equally to continuous and categorical predictors. What may be the issue here is that when evaluating a categorical predictor, you first need to check whether the 'overall' test is significant, that is, whether the test that looks at whether splitting into the 5 categories (with 4 df) contributes to the model is significant. If that result is positive, you can proceed to zoom in on the different contrasts (HRs) separately and report these in the usual way with 95% CI. The p-values of the individual HRs are usually somewhat less relevant because they are highly dependent on the chosen reference category.
I would like to perform a Cox regression on a patient cohort to determine whether certain variables have independent predictive value. I have a cohort of 86 patients. For the cohort I want to compare 8 variables, 7 binary and one continuous (age). In the cohort there were 6 events. When I try to run the Cox regression model, I get the following warning: 'Since coefficients did not converge no further models will be fitted'. The table then shows a significance of 1 and a hazard ratio of 1 for all variables. What does this mean? And is a Cox regression even the appropriate test for my data then?
I think you are suffering from a severe form of insufficient power. You only have 6 events in the data. For a Cox regression, according to rules of thumb, 10 to 20 events per parameter you want to test are needed. With 6 events, unfortunately, you cannot meaningfully look at the effects of variables using a Cox model. Of course, you can still describe the raw data.
You will find this in SPSS 28 under Analyze -> Survival -> Cox Regression or Cox w/ Time-Dep Cov.
- www.competingrisks.org "Data Analysis with Competing Risks and Intermediate States" by Ronald B. Geskus. Forthcoming July 2015 by Chapman and Hall/CRC, ISBN 9781466570351
- Competing risk analysis using R: an easy guide for clinicians - Technical Report, L Scrucca, A Santucci and F Aversa, Bone Marrow Transplantation (2007) 40, 381-387
- Concurrerende risico's in klinisch onderzoek, Rob C.M. van Kruijsdijk, Marinus J.C. Eijkemans en Frank L.J. Visseren, Ned Tijdschr Geneeskd. 2012;156:A5176
- Verduijn M, Grootendorst DC, Dekker FW, Jager KJ, le Cessie S. The analysis of competing events like cause-specific mortality--beware of the Kaplan-Meier method. Nephrol Dial Transplant. 2011 Jan;26(1):56-61. doi: 10.1093/ndt/gfq661
- Altman DG, Bland JM. Time to event (survival) data. BMJ 1998;317:468-9.
- Bewick V, Cheek L, Ball J. Statistics review 12: Survival analysis. Critical Care 2004, 8:389-394.
- Bland JM, Altman DG. Survival probabilities. The Kaplan-Meier method. BMJ 1998;317:1572.
- Bland JM and Altman DG. The log rank test. BMJ 2004;Vol 328 may 2004.
- An Introduction to Survival Analysis - by Mark Stevenson from EpiCentre, IVABS, Massey University. 31 pages of course material (English) with example syntax in R.
- Singh R and Mukhopadhyay K. Survival analysis in clinical trials: Basics and must know areas. Perspect Clin Res. 2011 Oct-Dec; 2(4): 145–148.
- Hosmer, D. W., and S. Lemeshow. 1999. Applied Survival Analysis. New York: John Wiley and Sons.
- Kleinbaum, D. G. 1996. Survival Analysis: A Self-Learning Text. New York: Springer-Verlag.
- Norusis, M. 2004. SPSS 13.0 Advanced Statistical Procedures Companion. Upper Saddle-River, N.J.: Prentice Hall, Inc..
- R tutorial survival analysis - YouTube video explaining how to perform a survival analysis in R.
- R tutorial Cox analysis - YouTube video explaining how to perform a Cox analysis in R.
Finished reading? You can go to the Overview of all topics, or to Choosing a test for help picking a suitable test or analysis. Want to learn more about biostatistics? Then follow the AMC e-learning Practical Biostatistics. Did you find something on these pages that isn't correct? Does a link not work? Or would you like to contribute to the wiki? Then get in touch with us.
This biostatistics wiki is an initiative of the former statistics helpdesk of Amsterdam UMC, location AMC. Amsterdam UMC staff can request statistical support via intranet.