g12 Chapter Contents
g12 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_surviv_logrank (g12abc)

## 1  Purpose

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

## 2  Specification

 #include #include
 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, $S\left(t\right)$, 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
• ${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
 $di = ∑ j=1 g d ij and ni = ∑ j=1 g n ij .$
The (weighted) number of observed failures in the $j$th group, ${O}_{j}$, is therefore given by
 $Oj = ∑ i=1 nd wi d ij$
and the (weighted) number of expected failures in the $j$th group, ${E}_{j}$, by
 $Ej = ∑ i=1 nd wi n ij di ni .$
If $x$ denotes the vector of differences $x=\left({O}_{1}-{E}_{1},{O}_{2}-{E}_{2},\dots ,{O}_{g}-{E}_{g}\right)$ 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\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:     nIntegerInput
On entry: $n$, the number of failure and censored times.
Constraint: ${\mathbf{n}}\ge 2$.
2:     t[n]const doubleInput
On entry: the observed failure and censored times; these need not be ordered.
Constraint: ${\mathbf{t}}\left[\mathit{i}-1\right]\ne {\mathbf{t}}\left[\mathit{j}-1\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]const IntegerInput
On entry: ${\mathbf{ic}}\left[\mathit{i}-1\right]$ contains the censoring code of the $\mathit{i}$th observation, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
${\mathbf{ic}}\left[i-1\right]=0$
the $i$th observation is a failure time.
${\mathbf{ic}}\left[i-1\right]=1$
the $i$th observation is right-censored.
Constraints:
• ${\mathbf{ic}}\left[\mathit{i}-1\right]=0$ or $1$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$;
• ${\mathbf{ic}}\left[i-1\right]=0$ for at least one $i$.
4:     grp[n]const IntegerInput
On entry: ${\mathbf{grp}}\left[\mathit{i}-1\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}-1\right]\le {\mathbf{ngrp}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$;
• each group must have at least one observation.
5:     ngrpIntegerInput
On entry: $g$, the number of groups.
Constraint: $2\le {\mathbf{ngrp}}\le {\mathbf{n}}$.
6:     ifreq[$\mathit{dim}$]const IntegerInput
Note: the dimension, dim, of the array ifreq must be at least ${\mathbf{n}}$, unless ifreq is NULL.
On entry: optionally, the frequency (number of observations) that each entry in t corresponds to. If ${\mathbf{ifreq}}\phantom{\rule{0.25em}{0ex}}\text{is}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$ then each entry in t is assumed to correspond to a single observation, i.e., a frequency of $1$ is assumed.
Constraint: if ${\mathbf{ifreq}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$, ${\mathbf{ifreq}}\left[\mathit{i}-1\right]\ge 0$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
7:     wt[$\mathit{dim}$]const doubleInput
Note: the dimension, dim, of the array wt must be at least ${\mathbf{ldn}}$, unless wt is NULL.
On entry: optionally, the ${n}_{d}$ weights, ${w}_{i}$, where ${n}_{d}$ is the number of distinct failure times. If ${\mathbf{wt}}\phantom{\rule{0.25em}{0ex}}\text{is}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$ then ${w}_{i}=1$ for all $i$.
Constraint: if ${\mathbf{wt}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$, ${\mathbf{wt}}\left[\mathit{i}-1\right]\ge 0.0$, for $\mathit{i}=1,2,\dots ,{n}_{d}$.
8:     tsdouble *Output
On exit: $T$, the test statistic.
9:     dfInteger *Output
On exit: $\nu$, the degrees of freedom.
10:   pdouble *Output
On exit: $P\left(X\ge T\right)$, when $X\sim {\chi }_{\nu }^{2}$, i.e., the probability associated with ts.
11:   obsd[ngrp]doubleOutput
On exit: ${O}_{i}$, the observed number of failures in each group.
12:   expt[ngrp]doubleOutput
On exit: ${E}_{i}$, the expected number of failures in each group.
13:   ndInteger *Output
On exit: ${n}_{d}$, the number of distinct failure times.
14:   di[ldn]IntegerOutput
On exit: the first nd elements of di contain ${d}_{i}$, the number of failures, across all groups, at time ${t}_{i}$.
15:   ni[ldn]IntegerOutput
On exit: the first nd elements of ni contain ${n}_{i}$, the size of the risk set, across all groups, at time ${t}_{i}$.
16:   ldnIntegerInput
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.
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.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_GROUP_OBSERV
On entry, group $⟨\mathit{\text{value}}⟩$ has no observations.
NE_INT
On entry, ${\mathbf{ldn}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldn}}\ge ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
NE_INT_2
On entry, ${\mathbf{ngrp}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $2\le {\mathbf{ngrp}}\le {\mathbf{n}}$.
NE_INT_ARRAY
On entry, ${\mathbf{grp}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ngrp}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{grp}}\left[i-1\right]\le {\mathbf{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, ${\mathbf{ic}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ic}}\left[i-1\right]=0$ or $1$.
NE_INVALID_FREQ
On entry, ${\mathbf{ifreq}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ifreq}}\left[i-1\right]\ge 0$.
NE_NEG_WEIGHT
On entry, ${\mathbf{wt}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{wt}}\left[i-1\right]\ge 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.

Not applicable.

## 8  Parallelism and Performance

nag_surviv_logrank (g12abc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_surviv_logrank (g12abc) 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.

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 nag_surviv_logrank (g12abc) when ${\mathbf{wt}}\phantom{\rule{0.25em}{0ex}}\text{is}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$. 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)=\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 nag_surviv_logrank (g12abc) 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 (g12abce.c)

### 10.2  Program Data

Program Data (g12abce.d)

### 10.3  Program Results

Program Results (g12abce.r)