NAG Library Routine Document
G12ABF
1 Purpose
G12ABF calculates the rank statistics, which can include the logrank test, for comparing survival curves.
2 Specification
SUBROUTINE G12ABF ( 
N, T, IC, GRP, NGRP, FREQ, IFREQ, WEIGHT, WT, TS, DF, P, OBSD, EXPT, ND, DI, NI, LDN, IFAIL) 
INTEGER 
N, IC(N), GRP(N), NGRP, IFREQ(*), DF, ND, DI(LDN), NI(LDN), LDN, IFAIL 
REAL (KIND=nag_wp) 
T(N), WT(*), TS, P, OBSD(NGRP), EXPT(NGRP) 
CHARACTER(1) 
FREQ, WEIGHT 

3 Description
A survivor function,
$S\left(t\right)$, is the probability of surviving to at least time
$t$. Given a series of
$n$ failure or rightcensored times from
$g$ groups G12ABF calculates a rank statistic for testing the null hypothesis

${H}_{0}:{S}_{1}\left(t\right)={S}_{2}\left(t\right)=\cdots ={S}_{g}\left(t\right),\forall t\le \tau $
where
$\tau $ is the largest observed time, against the alternative hypothesis

${H}_{1}:$ at least one of the
${S}_{i}\left(t\right)$ differ, for some
$t\le \tau $.
Let
${t}_{\mathit{i}}$, for
$\mathit{i}=1,2,\dots ,{n}_{d}$, denote the list of distinct failure times across all
$g$ groups and
${w}_{i}$ a series of
${n}_{d}$ weights. Let
${d}_{ij}$ denote the number of failures at time
${t}_{i}$ in group
$j$ and
${n}_{ij}$ denote the number of observations in the group
$j$ that are known to have not failed prior to time
${t}_{i}$, i.e., the size of the risk set for group
$j$ at time
${t}_{i}$. If a censored observation occurs at time
${t}_{i}$ then that observation is treated as if the censoring had occurred slightly after
${t}_{i}$ and therefore the observation is counted as being part of the risk set at time
${t}_{i}$. Finally let
The (weighted) number of observed failures in the
$j$th group,
${O}_{j}$, is therefore given by
and the (weighted) number of expected failures in the
$j$th group,
${E}_{j}$, by
If
$x$ denotes the vector of differences
$x=\left({O}_{1}{E}_{1},{O}_{2}{E}_{2},\dots ,{O}_{g}{E}_{g}\right)$ and
where
${I}_{jk}=1$ if
$j=k$ and
$0$ otherwise, then the rank statistic,
$T$, is calculated as
where
${V}^{}$ denotes a generalized inverse of the matrix
$V$. Under the null hypothesis,
$T\sim {\chi}_{\nu}^{2}$ where the degrees of freedom,
$\nu $, 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 Parameters
 1: N – INTEGERInput
On entry: $n$, the number of failure and censored times.
Constraint:
${\mathbf{N}}\ge 2$.
 2: T(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observed failure and censored times; these need not be ordered.
Constraint:
${\mathbf{T}}\left(\mathit{i}\right)\ne {\mathbf{T}}\left(\mathit{j}\right)$ for at least one $\mathit{i}\ne \mathit{j}$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{N}}$.
 3: IC(N) – INTEGER arrayInput
On entry:
${\mathbf{IC}}\left(\mathit{i}\right)$ contains the censoring code of the
$\mathit{i}$th observation, for
$\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
 ${\mathbf{IC}}\left(i\right)=0$
 the $i$th observation is a failure time.
 ${\mathbf{IC}}\left(i\right)=1$
 the $i$th observation is rightcensored.
Constraints:
 ${\mathbf{IC}}\left(\mathit{i}\right)=0$ or $1$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$;
 ${\mathbf{IC}}\left(i\right)=0$ for at least one $i$.
 4: GRP(N) – INTEGER arrayInput
On entry: ${\mathbf{GRP}}\left(\mathit{i}\right)$ contains a flag indicating which group the $\mathit{i}$th observation belongs in, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
Constraints:
 $1\le {\mathbf{GRP}}\left(\mathit{i}\right)\le {\mathbf{NGRP}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$;
 each group must have at least one observation.
 5: NGRP – INTEGERInput
On entry: $g$, the number of groups.
Constraint:
$2\le {\mathbf{NGRP}}\le {\mathbf{N}}$.
 6: FREQ – CHARACTER(1)Input
On entry: indicates whether frequencies are provided for each time point.
 ${\mathbf{FREQ}}=\text{'F'}$
 Frequencies are provided for each failure and censored time.
 ${\mathbf{FREQ}}=\text{'S'}$
 The failure and censored times are considered as single observations, i.e., a frequency of $1$ is assumed.
Constraint:
${\mathbf{FREQ}}=\text{'F'}$ or $\text{'S'}$.
 7: IFREQ($*$) – INTEGER arrayInput

Note: the dimension of the array
IFREQ
must be at least
${\mathbf{N}}$ if
${\mathbf{FREQ}}=\text{'F'}$.
On entry: if
${\mathbf{FREQ}}=\text{'F'}$,
${\mathbf{IFREQ}}\left(i\right)$ must contain the frequency (number of observations) to which each entry in
T corresponds.
If
${\mathbf{FREQ}}=\text{'S'}$, each entry in
T is assumed to correspond to a single observation, i.e., a frequency of
$1$ is assumed, and
IFREQ is not referenced.
Constraint:
if ${\mathbf{FREQ}}=\text{'F'}$, ${\mathbf{IFREQ}}\left(\mathit{i}\right)\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
 8: WEIGHT – CHARACTER(1)Input
On entry: indicates if weights are to be used.
 ${\mathbf{WEIGHT}}=\text{'U'}$
 All weights are assumed to be $1$.
 ${\mathbf{WEIGHT}}=\text{'W'}$
 The weights, ${w}_{i}$ are supplied in WT.
Constraint:
${\mathbf{WEIGHT}}=\text{'U'}$ or $\text{'W'}$.
 9: WT($*$) – REAL (KIND=nag_wp) arrayInput

Note: the dimension of the array
WT
must be at least
${\mathbf{LDN}}$ if
${\mathbf{WEIGHT}}=\text{'W'}$.
On entry: if
${\mathbf{WEIGHT}}=\text{'W'}$,
WT must contain the
${n}_{d}$ weights,
${w}_{i}$, where
${n}_{d}$ is the number of distinct failure times.
If
${\mathbf{WEIGHT}}=\text{'U'}$,
WT is not referenced and
${w}_{i}=1$ for all
$i$.
Constraint:
if ${\mathbf{WEIGHT}}=\text{'W'}$, ${\mathbf{WT}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,{n}_{d}$.
 10: TS – REAL (KIND=nag_wp)Output
On exit: $T$, the test statistic.
 11: DF – INTEGEROutput
On exit: $\nu $, the degrees of freedom.
 12: P – REAL (KIND=nag_wp)Output
On exit:
$P\left(X\ge T\right)$, when
$X\sim {\chi}_{\nu}^{2}$, i.e., the probability associated with
TS.
 13: OBSD(NGRP) – REAL (KIND=nag_wp) arrayOutput
On exit: ${O}_{i}$, the observed number of failures in each group.
 14: EXPT(NGRP) – REAL (KIND=nag_wp) arrayOutput
On exit: ${E}_{i}$, the expected number of failures in each group.
 15: ND – INTEGEROutput
On exit: ${n}_{d}$, the number of distinct failure times.
 16: DI(LDN) – INTEGER arrayOutput
On exit: the first
ND elements of
DI contain
${d}_{i}$, the number of failures, across all groups, at time
${t}_{i}$.
 17: NI(LDN) – INTEGER arrayOutput
On exit: the first
ND elements of
NI contain
${n}_{i}$, the size of the risk set, across all groups, at time
${t}_{i}$.
 18: LDN – INTEGERInput
On entry: the size of arrays
DI and
NI. As
${n}_{d}\le n$, if
${n}_{d}$ is not known
a priori then a value of
N can safely be used for
LDN.
Constraint:
${\mathbf{LDN}}\ge {n}_{d}$, the number of unique failure times.
 19: IFAIL – INTEGERInput/Output
On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ 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 parameter, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{N}}<2$.
 ${\mathbf{IFAIL}}=2$
On entry, all the times in
T are the same.
 ${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{IC}}\left(i\right)\ne 0$ or $1$, for at least one $i=1,2,\dots ,{\mathbf{N}}$.
 ${\mathbf{IFAIL}}=31$
On entry, all observations are censored.
 ${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{GRP}}\left(i\right)<1$ or ${\mathbf{GRP}}\left(i\right)>{\mathbf{NGRP}}$, for at least one $i=1,2,\dots ,{\mathbf{N}}$.
 ${\mathbf{IFAIL}}=41$
On entry, at least one group has no observations.
 ${\mathbf{IFAIL}}=5$
On entry, ${\mathbf{NGRP}}<2$ or ${\mathbf{NGRP}}>{\mathbf{N}}$.
 ${\mathbf{IFAIL}}=6$
On entry, ${\mathbf{FREQ}}\ne \text{'F'}$ or $\text{'S'}$.
 ${\mathbf{IFAIL}}=7$
On entry, ${\mathbf{FREQ}}=\text{'F'}$ and ${\mathbf{IFREQ}}\left(i\right)<0$, for at least one $i=1,2,\dots ,{\mathbf{N}}$.
 ${\mathbf{IFAIL}}=8$
On entry, ${\mathbf{WEIGHT}}\ne \text{'U'}$ or $\text{'W'}$.
 ${\mathbf{IFAIL}}=9$
On entry, ${\mathbf{WEIGHT}}=\text{'W'}$ and ${\mathbf{WT}}\left(i\right)<0.0$, for some $i=1,2,\dots ,{\mathbf{N}}$.
 ${\mathbf{IFAIL}}=11$
The degrees of freedom are zero.
 ${\mathbf{IFAIL}}=18$
On entry, ${\mathbf{LDN}}<{n}_{d}$.
7 Accuracy
Not applicable.
The use of different weights in the formula given in
Section 3 leads to different rank statistics being calculated. The logrank test has
${w}_{i}=1$, for all
$i$, which is the equivalent of calling G12ABF when
${\mathbf{WEIGHT}}=\text{'U'}$ . Other rank statistics include Wilcoxon (
${w}_{i}={n}_{i}$), Tarone–Ware (
${w}_{i}=\sqrt{{n}_{i}}$) and Peto–Peto (
${w}_{i}=\stackrel{~}{S}\left({t}_{i}\right)$ where
$\stackrel{~}{S}\left({t}_{i}\right)={\displaystyle \prod _{{t}_{j}\le {t}_{i}}}\phantom{\rule{0.25em}{0ex}}\frac{{n}_{j}{d}_{j}+1}{{n}_{j}+1}$) amongst others.
Calculation of any test, other than the logrank test, will probably require G12ABF to be called twice, once to calculate the values of ${n}_{i}$ and ${d}_{i}$ 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 (g12abfe.f90)
9.2 Program Data
Program Data (g12abfe.d)
9.3 Program Results
Program Results (g12abfe.r)