hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_surviv_logrank (g12ab)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

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

Syntax

[ts, df, p, obsd, expt, nd, di, ni, ifail] = g12ab(t, ic, grp, ngrp, freq, weight, 'n', n, 'ifreq', ifreq, 'wt', wt, 'ldn', ldn)
[ts, df, p, obsd, expt, nd, di, ni, ifail] = nag_surviv_logrank(t, ic, grp, ngrp, freq, weight, 'n', n, 'ifreq', ifreq, 'wt', wt, 'ldn', ldn)

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 (g12ab) 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.

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

Parameters

Compulsory Input Parameters

1:     tn – double array
The observed failure and censored times; these need not be ordered.
Constraint: titj for at least one ij, for i=1,2,,n and j=1,2,,n.
2:     icn int64int32nag_int array
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.
Constraints:
  • ici=0 or 1, for i=1,2,,n;
  • ici=0 for at least one i.
3:     grpn int64int32nag_int array
grpi contains a flag indicating which group the ith observation belongs in, for i=1,2,,n.
Constraints:
  • 1grpingrp, for i=1,2,,n;
  • each group must have at least one observation.
4:     ngrp int64int32nag_int scalar
g, the number of groups.
Constraint: 2ngrpn.
5:     freq – string (length ≥ 1)
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'.
6:     weight – string (length ≥ 1)
Indicates if weights are to be used.
weight='U'
All weights are assumed to be 1.
weight='W'
The weights, wi are supplied in wt.
Constraint: weight='U' or 'W'.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array t and the dimension of the array ic and the dimension of the array grp. (An error is raised if these dimensions are not equal.)
n, the number of failure and censored times.
Constraint: n2.
2:     ifreq: int64int32nag_int array
The dimension of the array ifreq must be at least n if freq='F'
If freq='F', ifreqi must contain the frequency (number of observations) to which each entry in t corresponds.
If freq='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 freq='F', ifreqi0, for i=1,2,,n.
3:     wt: – double array
The dimension of the array wt must be at least ldn if weight='W'
If weight='W', wt must contain the nd weights, wi, where nd is the number of distinct failure times.
If weight='U', wt is not referenced and wi=1 for all i.
Constraint: if weight='W', wti0.0, for i=1,2,,nd.
4:     ldn int64int32nag_int scalar
Default: n
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.

Output Parameters

1:     ts – double scalar
T, the test statistic.
2:     df int64int32nag_int scalar
ν, the degrees of freedom.
3:     p – double scalar
PXT, when Xχν2, i.e., the probability associated with ts.
4:     obsdngrp – double array
Oi, the observed number of failures in each group.
5:     exptngrp – double array
Ei, the expected number of failures in each group.
6:     nd int64int32nag_int scalar
nd, the number of distinct failure times.
7:     dildn int64int32nag_int array
The first nd elements of di contain di, the number of failures, across all groups, at time ti.
8:     nildn int64int32nag_int array
The first nd elements of ni contain ni, the size of the risk set, across all groups, at time ti.
9:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
Constraint: n2.
   ifail=2
On entry, all the times in t are the same.
   ifail=3
Constraint: ici=0 or 1.
   ifail=4
Constraint: 1grpingrp.
   ifail=5
Constraint: 2ngrpn.
   ifail=6
On entry, freq had an illegal value.
   ifail=7
Constraint: ifreqi0.
   ifail=8
On entry, weight had an illegal value.
   ifail=9
Constraint: wti0.0.
   ifail=11
The degrees of freedom are zero.
   ifail=18
ldn is too small.
   ifail=31
On entry, all observations are censored.
   ifail=41
On entry, group _ has no observations.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

The use of different weights in the formula given in Description 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 (g12ab) when weight='U' . 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 (g12ab) 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.

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).
function g12ab_example


fprintf('g12ab example results\n\n');

t = [  6;  13;  21; 30; 31; 37; 38; 47; 49; 50; 63; 79; 80; 82; 82;  86;  98;
     149; 202; 219; 10; 10; 12; 13; 14; 15; 16; 17; 18; 20; 24; 24;  25;  28;
      30;  33;  34; 35; 37; 40; 40; 40; 46; 48; 70; 76; 81; 82; 91; 112; 181];
n = numel(t);

ic   = zeros(n,1,'int64');
ic(5)  = 1; ic(8)  = 1; ic(13:15) = 1;
ic(18) = 1; ic(37) = 1; ic(42)    = 1;
ic(45) = 1;

grp = ones(n,1,'int64');
grp(21:end) = 2;
ngrp = int64(2);

freq = 's';
weight = 'u';

% Calculate the statistic
[ts, df, p, obsd, expt, nd, di, ni, ifail] = ...
  g12ab( ...
         t, ic, grp, ngrp, freq, weight);

% Display Results
fprintf('           Observed  Expected\n');
for i=1:ngrp
  fprintf(' Group %d %8.2f  %8.2f\n', i, obsd(i), expt(i));
end
fprintf('\n No. Unique Failure Times = %d\n\n', nd);
fprintf(' Test Statistic           = %8.4f\n', ts);
fprintf(' Degrees of Freedom       = %3d\n', df);
fprintf(' p-value                  = %8.4f\n', p);


g12ab example results

           Observed  Expected
 Group 1    14.00     22.48
 Group 2    28.00     19.52

 No. Unique Failure Times = 36

 Test Statistic           =   7.4966
 Degrees of Freedom       =   1
 p-value                  =   0.0062

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015