NAG FL Interface
g12aaf (kaplanmeier)

1 Purpose

g12aaf computes the Kaplan–Meier, (or product-limit), estimates of survival probabilities for a sample of failure times.

2 Specification

Fortran Interface
Subroutine g12aaf ( n, t, ic, freq, ifreq, nd, tp, p, psig, iwk, ifail)
Integer, Intent (In) :: n, ic(n), ifreq(*)
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: nd, iwk(n)
Real (Kind=nag_wp), Intent (In) :: t(n)
Real (Kind=nag_wp), Intent (Out) :: tp(n), p(n), psig(n)
Character (1), Intent (In) :: freq
C Header Interface
#include <nag.h>
void  g12aaf_ (const Integer *n, const double t[], const Integer ic[], const char *freq, const Integer ifreq[], Integer *nd, double tp[], double p[], double psig[], Integer iwk[], Integer *ifail, const Charlen length_freq)
The routine may be called by the names g12aaf or nagf_surviv_kaplanmeier.

3 Description

A survivor function, St, is the probability of surviving to at least time t with St=1-Ft, where Ft is the cumulative distribution function of the failure times. The Kaplan–Meier or product limit estimator provides an estimate of St, S^t, from sample of failure times which may be progressively right-censored.
Let ti, i=1,2,,nd, be the ordered distinct failure times for the sample of observed failure/censored times, and let the number of observations in the sample that have not failed by time ti be ni. If a failure and a loss (censored observation) occur at the same time ti, then the failure is treated as if it had occurred slightly before time ti and the loss as if it had occurred slightly after ti.
The Kaplan–Meier estimate of the survival probabilities is a step function which in the interval ti to ti+1 is given by
S^t=j=1i nj-djnj ,  
where dj is the number of failures occurring at time tj.
g12aaf computes the Kaplan–Meier estimates and the corresponding estimates of the variances, var^S^t, using Greenwood's formula,
var^S^t=S^ t 2j=1idjnjnj-dj .  

4 References

Gross A J and Clark V A (1975) Survival Distributions: Reliability Applications in the Biomedical Sciences Wiley
Kalbfleisch J D and Prentice R L (1980) The Statistical Analysis of Failure Time Data Wiley

5 Arguments

1: n Integer Input
On entry: the number of failure and censored times given in t.
Constraint: n2.
2: tn Real (Kind=nag_wp) array Input
On entry: the failure and censored times; these need not be ordered.
3: icn Integer array Input
On entry: ici contains the censoring code of the ith observation, for i=1,2,,n.
ici=0
The ith observation is a failure time.
ici=1
The ith observation is right-censored.
Constraint: ici=0 or 1, for i=1,2,,n.
4: freq Character(1) Input
On entry: indicates whether frequencies are provided for each time point.
freq='F'
Frequencies are provided for each failure and censored time.
freq='S'
The failure and censored times are considered as single observations, i.e., a frequency of 1 is assumed.
Constraint: freq='F' or 'S'.
5: ifreq* Integer array Input
Note: the dimension of the array ifreq must be at least n if freq='F' and at least 1 if freq='S'.
On entry: if freq='F', ifreqi must contain the frequency of the ith observation.
If ifreq='S', a frequency of 1 is assumed and ifreq is not referenced.
Constraint: if freq='F', ifreqi0, for i=1,2,,n.
6: nd Integer Output
On exit: the number of distinct failure times, nd.
7: tpn Real (Kind=nag_wp) array Output
On exit: tpi contains the ith ordered distinct failure time, ti, for i=1,2,,nd.
8: pn Real (Kind=nag_wp) array Output
On exit: pi contains the Kaplan–Meier estimate of the survival probability, S^t, for time tpi, for i=1,2,,nd.
9: psign Real (Kind=nag_wp) array Output
On exit: psigi contains an estimate of the standard deviation of pi, for i=1,2,,nd.
10: iwkn Integer array Workspace
11: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 or 1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, n=value.
Constraint: n2.
ifail=2
On entry, freq=value.
Constraint: freq='F' or 'S'.
ifail=3
On entry, i=value and ici=value.
Constraint: ici=0 or 1.
ifail=4
On entry, i=value and ifreqi=value.
Constraint: ifreqi0.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The computations are believed to be stable.

8 Parallelism and Performance

g12aaf is not threaded in any implementation.

9 Further Comments

If there are no censored observations, S^t reduces to the ordinary binomial estimate of the probability of survival at time t.

10 Example

The remission times for a set of 21 leukaemia patients at 18 distinct time points are read in and the Kaplan–Meier estimate computed and printed. For further details see page 242 of Gross and Clark (1975).

10.1 Program Text

Program Text (g12aafe.f90)

10.2 Program Data

Program Data (g12aafe.d)

10.3 Program Results

Program Results (g12aafe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 0 0.2 0.4 0.6 0.8 1 5 10 15 20 Survival Probability Time Example Program Kaplan Meier Plot gnuplot_plot_1