NAG Library Function Document
nag_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 <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, 
, is the probability of surviving to at least time 
. Given a series of 
 failure or right-censored times from 
 groups 
nag_surviv_logrank (g12abc) calculates a rank statistic for testing the null hypothesis
- 
  
 
where 
 is the largest observed time, against the alternative hypothesis
- 
   at least one of the
   differ, for some
  .
 
Let
 
, for 
, denote the list of distinct failure times across all 
 groups and 
 a series of 
 weights. Let 
 denote the number of failures at time 
 in group 
 and 
 denote the number of observations in the group 
 that are known to have not failed prior to time 
, i.e., the size of the risk set for group 
 at time 
. If a censored observation occurs at time 
 then that observation is treated as if the censoring had occurred slightly after 
 and therefore the observation is counted as being part of the risk set at time 
. Finally let
 
The (weighted) number of observed failures in the 
th group, 
, is therefore given by
 
and the (weighted) number of expected failures in the  
th group, 
,  by
If 
 denotes the vector of differences
 and
where
 if 
 and 
 otherwise, then the rank statistic, 
, is calculated as
where 
 denotes a generalized inverse of the matrix 
. Under the null hypothesis,
 where the degrees of freedom, 
, is taken as the rank of the matrix 
.
 
 
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:
  
      – IntegerInput
 - 
On entry: , the number of failure and censored times.
Constraint:
  .
 - 2:
  
      – const doubleInput
 - 
On entry: the observed failure and censored times; these need not be ordered.
Constraint:
   for at least one , for  and .
 - 3:
  
      – const IntegerInput
 - 
On entry: 
 contains the censoring code of the 
th observation, for 
. 
- the th observation is a failure time.
 
- the th observation is right-censored.
 
 
Constraints:
   
 
-  or , for ;
 
-  for at least one .
 
 
 - 4:
  
      – const IntegerInput
 - 
On entry:  contains a flag indicating which group the th observation belongs in, for .
Constraints:
   
 
- , for ;
 
- each group must have at least one observation.
 
 
 - 5:
  
      – IntegerInput
 - 
On entry: , the number of groups.
Constraint:
  .
 - 6:
  
      – const IntegerInput
 - 
Note: the dimension, 
dim, of the array 
ifreq
must be at least
, unless 
ifreq is 
NULL.
 
  
  
 
On entry: optionally, the frequency (number of observations) that each entry in 
t corresponds to. If 
 then each entry in 
t is assumed to correspond to a single observation, i.e., a frequency of 
 is assumed.
 
Constraint:
  
 if , , for .
 - 7:
  
      – const doubleInput
 - 
Note: the dimension, 
dim, of the array 
wt
must be at least
, unless 
wt is 
NULL.
 
 On entry: optionally, the  weights, , where  is the number of distinct failure times. If  then  for all .
Constraint:
  
 if , , for .
 - 8:
  
      – double *Output
 - 
On exit: , the test statistic.
 - 9:
  
      – Integer *Output
 - 
On exit: , the degrees of freedom.
 - 10:
  
    – double *Output
 - 
On exit: 
, when 
, i.e., the probability associated with 
ts.
 
 - 11:
  
    – doubleOutput
 - 
On exit: , the observed number of failures in each group.
 - 12:
  
    – doubleOutput
 - 
On exit: , the expected number of failures in each group.
 - 13:
  
    – Integer *Output
 - 
On exit: , the number of distinct failure times.
 - 14:
  
    – IntegerOutput
 - 
On exit: the first 
nd elements of 
di contain 
, the number of failures, across all groups, at time 
.
 
 - 15:
  
    – IntegerOutput
 - 
On exit: the first 
nd elements of 
ni contain 
, the size of the risk set, across all groups, at time 
.
 
 - 16:
  
    – IntegerInput
 - 
On entry: the size of arrays 
di and 
ni. As 
, if 
 is not known 
a priori then a value of 
n can safely be used for 
ldn.
 
Constraint:
  , the number of unique failure times.
 - 17:
  
    – NagError *Input/Output
 - 
The NAG error argument (see 
Section 3.7 in How to Use the NAG Library and its Documentation).
 
 
 
6
 Error Indicators and Warnings
- NE_ALLOC_FAIL
 
- 
Dynamic memory allocation failed.
      
      See 
Section 2.3.1.2  in How to Use the NAG Library and its Documentation for further information.
 
 
- NE_BAD_PARAM
 
- 
On entry, argument   had an illegal value.
 
- NE_GROUP_OBSERV
 
- 
On entry, group  has no observations.
 
- NE_INT
 
- 
On entry, .
Constraint: .
On entry, .
Constraint: .
 
- NE_INT_2
 
- 
On entry,  and .
Constraint: .
 
- NE_INT_ARRAY
 
- 
On entry,  and  .
Constraint: .
 
- 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.
	See 
Section 2.7.6  in How to Use the NAG Library and its Documentation for further information.
 
 
- NE_INVALID_CENSOR_CODE
 
- 
On entry, .
Constraint:  or .
 
- NE_INVALID_FREQ
 
- 
On entry, .
Constraint: .
 
- NE_NEG_WEIGHT
 
- 
On entry, .
Constraint: .
 
- NE_NO_LICENCE
 
- 
Your licence key may have expired or may not have been installed correctly.
      
      See 
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
 
 
- 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
 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.
Please consult the 
x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the 
Users' Note for your implementation for any additional implementation-specific information.
 
The use of different weights in the formula given in 
Section 3 leads to different rank statistics being calculated. The logrank test has 
, for all 
, which is the equivalent of calling 
nag_surviv_logrank (g12abc) when  
.  Other rank statistics include Wilcoxon (
), Tarone–Ware (
) and Peto–Peto (
 where 
) 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  and  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 
 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)