nag_surviv_logrank (g12abc) (PDF version)
g12 Chapter Contents
g12 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_surviv_logrank (g12abc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_surviv_logrank (g12abc) calculates the rank statistics, which can include the logrank test, for comparing survival curves.

2  Specification

#include <nag.h>
#include <nagg12.h>
void  nag_surviv_logrank (Integer n, const double t[], const Integer ic[], const Integer grp[], Integer ngrp, const Integer ifreq[], const double wt[], double *ts, Integer *df, double *p, double obsd[], double expt[], Integer *nd, Integer di[], Integer ni[], Integer ldn, NagError *fail)

3  Description

A survivor function, St, is the probability of surviving to at least time t. Given a series of n failure or right-censored times from g groups nag_surviv_logrank (g12abc) calculates a rank statistic for testing the null hypothesis where τ is the largest observed time, against the alternative hypothesis
Let t i , for i=1,2,,nd, denote the list of distinct failure times across all g groups and wi a series of nd weights. Let dij denote the number of failures at time ti in group j and nij denote the number of observations in the group j that are known to have not failed prior to time ti, i.e., the size of the risk set for group j at time ti. If a censored observation occurs at time ti then that observation is treated as if the censoring had occurred slightly after ti and therefore the observation is counted as being part of the risk set at time ti. Finally let
di = j=1 g d ij   and   ni = j=1 g n ij .
The (weighted) number of observed failures in the jth group, Oj, is therefore given by
Oj = i=1 nd wi d ij
and the (weighted) number of expected failures in the jth group, Ej, by
Ej = i=1 nd wi n ij di ni .
If x denotes the vector of differences x = O1 - E1 , O2 - E2 , , Og - Eg  and
V jk = i=1 nd w i 2 di ni - di ni n i k I jk - n ij n ik n i 2 ni - 1
where I jk = 1  if j=k and 0 otherwise, then the rank statistic, T, is calculated as
T = x V- xT
where V- denotes a generalized inverse of the matrix V. Under the null hypothesis, T χ ν 2  where the degrees of freedom, ν, is taken as the rank of the matrix V.

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
Rostomily R C, Duong D, McCormick K, Bland M and Berger M S (1994) Multimodality management of recurrent adult malignant gliomas: results of a phase II multiagent chemotherapy study and analysis of cytoreductive surgery Neurosurgery 35 378

5  Arguments

1:     nIntegerInput
On entry: n, the number of failure and censored times.
Constraint: n2.
2:     t[n]const doubleInput
On entry: the observed failure and censored times; these need not be ordered.
Constraint: t[i-1]t[j-1] for at least one ij, for i=1,2,,n and j=1,2,,n.
3:     ic[n]const IntegerInput
On entry: ic[i-1] contains the censoring code of the ith observation, for i=1,2,,n.
ic[i-1]=0
the ith observation is a failure time.
ic[i-1]=1
the ith observation is right-censored.
Constraints:
  • ic[i-1]=0 or 1, for i=1,2,,n;
  • ic[i-1]=0 for at least one i.
4:     grp[n]const IntegerInput
On entry: grp[i-1] contains a flag indicating which group the ith observation belongs in, for i=1,2,,n.
Constraints:
  • 1grp[i-1]ngrp, for i=1,2,,n;
  • each group must have at least one observation.
5:     ngrpIntegerInput
On entry: g, the number of groups.
Constraint: 2ngrpn.
6:     ifreq[dim]const IntegerInput
Note: the dimension, dim, of the array ifreq must be at least n, unless ifreq is NULL.
On entry: optionally, the frequency (number of observations) that each entry in t corresponds to. If ifreq is NULL then each entry in t is assumed to correspond to a single observation, i.e., a frequency of 1 is assumed.
Constraint: if ifreq is not NULL, ifreq[i-1]0, for i=1,2,,n.
7:     wt[dim]const doubleInput
Note: the dimension, dim, of the array wt must be at least ldn, unless wt is NULL.
On entry: optionally, the nd weights, wi, where nd is the number of distinct failure times. If wt is NULL then wi=1 for all i.
Constraint: if wt is not NULL, wt[i-1]0.0, for i=1,2,,nd.
8:     tsdouble *Output
On exit: T, the test statistic.
9:     dfInteger *Output
On exit: ν, the degrees of freedom.
10:   pdouble *Output
On exit: PXT, when Xχν2, i.e., the probability associated with ts.
11:   obsd[ngrp]doubleOutput
On exit: Oi, the observed number of failures in each group.
12:   expt[ngrp]doubleOutput
On exit: Ei, the expected number of failures in each group.
13:   ndInteger *Output
On exit: nd, the number of distinct failure times.
14:   di[ldn]IntegerOutput
On exit: the first nd elements of di contain di, the number of failures, across all groups, at time ti.
15:   ni[ldn]IntegerOutput
On exit: the first nd elements of ni contain ni, the size of the risk set, across all groups, at time ti.
16:   ldnIntegerInput
On entry: the size of arrays di and ni. As ndn, if nd is not known a priori then a value of n can safely be used for ldn.
Constraint: ldnnd, the number of unique failure times.
17:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_GROUP_OBSERV
On entry, group value has no observations.
NE_INT
On entry, ldn=value.
Constraint: ldnvalue.
On entry, n=value.
Constraint: n2.
NE_INT_2
On entry, ngrp=value and n=value.
Constraint: 2ngrpn.
NE_INT_ARRAY
On entry, grp[value]=value and ngrp=value.
Constraint: 1grp[i-1]ngrp.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_INVALID_CENSOR_CODE
On entry, ic[value]=value.
Constraint: ic[i-1]=0 or 1.
NE_INVALID_FREQ
On entry, ifreq[value]=value.
Constraint: ifreq[i-1]0.
NE_NEG_WEIGHT
On entry, wt[value]=value.
Constraint: wt[i-1]0.0.
NE_OBSERVATIONS
On entry, all observations are censored.
NE_TIME_SERIES_IDEN
On entry, all the times in t are the same.
NE_ZERO_DF
The degrees of freedom are zero.

7  Accuracy

Not applicable.

8  Further Comments

The use of different weights in the formula given in Section 3 leads to different rank statistics being calculated. The logrank test has wi=1, for all i, which is the equivalent of calling nag_surviv_logrank (g12abc) when wt is NULL. Other rank statistics include Wilcoxon (wi=ni), Tarone–Ware (wi=ni) and Peto–Peto ( wi = S~ ti  where S~ ti = tj ti nj - dj + 1 nj+1 ) amongst others.
Calculation of any test, other than the logrank test, will probably require nag_surviv_logrank (g12abc) to be called twice, once to calculate the values of ni and di to facilitate in the computation of the required weights, and once to calculate the test statistic itself.

9  Example

This example compares the time to death for 51 adults with two different types of recurrent gliomas (brain tumour), astrocytoma and glioblastoma, using a logrank test. For further details on the data see Rostomily et al. (1994).

9.1  Program Text

Program Text (g12abce.c)

9.2  Program Data

Program Data (g12abce.d)

9.3  Program Results

Program Results (g12abce.r)


nag_surviv_logrank (g12abc) (PDF version)
g12 Chapter Contents
g12 Chapter Introduction
NAG C Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012