NAG Library Routine Document
g12abf (logrank)
1
Purpose
g12abf calculates the rank statistics, which can include the logrank test, for comparing survival curves.
2
Specification
Fortran Interface
Subroutine g12abf ( 
n, t, ic, grp, ngrp, freq, ifreq, weight, wt, ts, df, p, obsd, expt, nd, di, ni, ldn, ifail) 
Integer, Intent (In)  ::  n, ic(n), grp(n), ngrp, ifreq(*), ldn  Integer, Intent (Inout)  ::  ifail  Integer, Intent (Out)  ::  df, nd, di(ldn), ni(ldn)  Real (Kind=nag_wp), Intent (In)  ::  t(n), wt(*)  Real (Kind=nag_wp), Intent (Out)  ::  ts, p, obsd(ngrp), expt(ngrp)  Character (1), Intent (In)  ::  freq, weight 

C Header Interface
#include <nagmk26.h>
void 
g12abf_ (const Integer *n, const double t[], const Integer ic[], const Integer grp[], const Integer *ngrp, const char *freq, const Integer ifreq[], const char *weight, const double wt[], double *ts, Integer *df, double *p, double obsd[], double expt[], Integer *nd, Integer di[], Integer ni[], const Integer *ldn, Integer *ifail, const Charlen length_freq, const Charlen length_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
Arguments
 1: $\mathbf{n}$ – IntegerInput

On entry: $n$, the number of failure and censored times.
Constraint:
${\mathbf{n}}\ge 2$.
 2: $\mathbf{t}\left({\mathbf{n}}\right)$ – 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: $\mathbf{ic}\left({\mathbf{n}}\right)$ – 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: $\mathbf{grp}\left({\mathbf{n}}\right)$ – 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: $\mathbf{ngrp}$ – IntegerInput

On entry: $g$, the number of groups.
Constraint:
$2\le {\mathbf{ngrp}}\le {\mathbf{n}}$.
 6: $\mathbf{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: $\mathbf{ifreq}\left(*\right)$ – 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: $\mathbf{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: $\mathbf{wt}\left(*\right)$ – 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: $\mathbf{ts}$ – Real (Kind=nag_wp)Output

On exit: $T$, the test statistic.
 11: $\mathbf{df}$ – IntegerOutput

On exit: $\nu $, the degrees of freedom.
 12: $\mathbf{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: $\mathbf{obsd}\left({\mathbf{ngrp}}\right)$ – Real (Kind=nag_wp) arrayOutput

On exit: ${O}_{i}$, the observed number of failures in each group.
 14: $\mathbf{expt}\left({\mathbf{ngrp}}\right)$ – Real (Kind=nag_wp) arrayOutput

On exit: ${E}_{i}$, the expected number of failures in each group.
 15: $\mathbf{nd}$ – IntegerOutput

On exit: ${n}_{d}$, the number of distinct failure times.
 16: $\mathbf{di}\left({\mathbf{ldn}}\right)$ – 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: $\mathbf{ni}\left({\mathbf{ldn}}\right)$ – 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: $\mathbf{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: $\mathbf{ifail}$ – IntegerInput/Output

On entry:
ifail must be set to
$0$,
$1\text{or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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}}=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:
 ${\mathbf{ifail}}=1$

On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}\ge 2$.
 ${\mathbf{ifail}}=2$

On entry, all the times in
t are the same.
 ${\mathbf{ifail}}=3$

On entry, ${\mathbf{ic}}\left(\u2329\mathit{\text{value}}\u232a\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ic}}\left(i\right)=0$ or $1$.
 ${\mathbf{ifail}}=4$

On entry, ${\mathbf{grp}}\left(\u2329\mathit{\text{value}}\u232a\right)=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{ngrp}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: $1\le {\mathbf{grp}}\left(i\right)\le {\mathbf{ngrp}}$.
 ${\mathbf{ifail}}=5$

On entry, ${\mathbf{ngrp}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: $2\le {\mathbf{ngrp}}\le {\mathbf{n}}$.
 ${\mathbf{ifail}}=6$

On entry,
freq had an illegal value.
 ${\mathbf{ifail}}=7$

On entry, ${\mathbf{ifreq}}\left(\u2329\mathit{\text{value}}\u232a\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ifreq}}\left(i\right)\ge 0$.
 ${\mathbf{ifail}}=8$

On entry,
weight had an illegal value.
 ${\mathbf{ifail}}=9$

On entry, ${\mathbf{wt}}\left(\u2329\mathit{\text{value}}\u232a\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{wt}}\left(i\right)\ge 0.0$.
 ${\mathbf{ifail}}=11$

The degrees of freedom are zero.
 ${\mathbf{ifail}}=18$

On entry, ${\mathbf{ldn}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ldn}}\ge \u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=31$

On entry, all observations are censored.
 ${\mathbf{ifail}}=41$

On entry, group $\u2329\mathit{\text{value}}\u232a$ has no observations.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
Not applicable.
8
Parallelism and Performance
g12abf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g12abf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
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.
10
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).
10.1
Program Text
Program Text (g12abfe.f90)
10.2
Program Data
Program Data (g12abfe.d)
10.3
Program Results
Program Results (g12abfe.r)