nag_surviv_cox_model (g12bac) (PDF version)
g12 Chapter Contents
g12 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_surviv_cox_model (g12bac)

## 1  Purpose

nag_surviv_cox_model (g12bac) returns parameter estimates and other statistics that are associated with the Cox proportional hazards model for fixed covariates.

## 2  Specification

 #include #include
 void nag_surviv_cox_model (Integer n, Integer m, Integer ns, const double z[], Integer tdz, const Integer sz[], Integer ip, const double t[], const Integer ic[], const double omega[], const Integer isi[], double *dev, double b[], double se[], double sc[], double cov[], double res[], Integer *nd, double tp[], double sur[], Integer tdsur, Integer ndmax, double tol, Integer max_iter, Integer iprint, const char *outfile, NagError *fail)

## 3  Description

The proportional hazard model relates the time to an event, usually death or failure, to a number of explanatory variables known as covariates. Some of the observations may be right censored, that is the exact time to failure is not known, only that it is greater than a known time.
Let ${t}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$ be the failure time or censored time for the $i$th observation with the vector of $p$ covariates ${z}_{i}$. It is assumed that censoring and failure mechanisms are independent. The hazard function, $\lambda \left(t,z\right)$, is the probability that an individual with covariates $z$ fails at time $t$ given that the individual survived up to time $t$. In the Cox proportional hazards model (Cox (1972)) $\lambda \left(t,z\right)$ is of the form:
 $λ t,z = λ 0 t exp zT β + ω$
where ${\lambda }_{0}$ is the base-line hazard function, an unspecified function of time, $\beta$ is a vector of unknown arguments and $\omega$ is a known offset.
Assuming there are ties in the failure times giving ${n}_{d} distinct failure times, ${t}_{\left(1\right)}<\cdots <{t}_{\left({n}_{d}\right)}$ such that ${d}_{i}$ individuals fail at ${t}_{\left(i\right)}$, it follows that the marginal likelihood for $\beta$ is well approximated (see Kalbfleisch and Prentice (1980)) by:
 $L = ∏ i=1 n d exp siT β + ω i ∑ l ∈ R t i exp zlT β + ω l d i$ (1)
where ${s}_{i}$ is the sum of the covariates of individuals observed to fail at ${t}_{\left(i\right)}$ and $R\left({t}_{\left(i\right)}\right)$ is the set of individuals at risk just prior to ${t}_{\left(i\right)}$, that is it is all individuals that fail or are censored at time ${t}_{\left(i\right)}$ along with all individuals that survive beyond time ${t}_{\left(i\right)}$. The maximum likelihood estimates (MLEs) of $\beta$, given by $\stackrel{^}{\beta }$, are obtained by maximizing (1) using a Newton–Raphson iteration technique that includes step halving and utilizes the first and second partial derivatives of (1) which are given by equations (2) and (3) below:
 $U j β = ∂ln⁡L ∂βj = ∑ i=1 n d s ji - d i α ji β = 0$ (2)
for $j=1,\dots ,p$, where ${s}_{ji}$ is the $j$th element in the vector ${s}_{i}$ and
 $α ji β = ∑ l ∈ R t i z jl exp zlT β + ω l ∑ l ∈ R t i exp zlT β + ω l .$
Similarly,
 $I hj β = - ∂2ln⁡L ∂βh ∂βj = ∑ i=1 n d d i γ hji$ (3)
where
 $γ hji = ∑ l ∈ R t i z hl z jl exp zlT β + ω l ∑ l ∈ R t i exp zlT β + ω l - α hi β α ji β h , j = 1 , … , p .$
${U}_{j}\left(\beta \right)$ is the $j$th component of a score vector and ${I}_{hj}\left(\beta \right)$ is the $\left(h,j\right)$ element of the observed information matrix $I\left(\beta \right)$ whose inverse $I{\left(\beta \right)}^{-1}={\left[{I}_{hj}\left(\beta \right)\right]}^{-1}$ gives the variance-covariance matrix of $\beta$.
It should be noted that if a covariate or a linear combination of covariates is monotonically increasing or decreasing with time then one or more of the ${\beta }_{j}$'s will be infinite.
If ${\lambda }_{0}\left(t\right)$ varies across $\nu$ strata, where the number of individuals in the $k$th stratum is ${n}_{k}$, $k=1,\dots ,\nu$ with $n={\sum }_{k=1}^{\nu }{n}_{k}$, then rather than maximizing (1) to obtain $\stackrel{^}{\beta }$, the following marginal likelihood is maximized:
 $L = ∏ k=1 ν L k ,$ (4)
where ${L}_{k}$ is the contribution to likelihood for the ${n}_{k}$ observations in the $k$th stratum treated as a single sample in (1). When strata are included the covariate coefficients are constant across strata but there is a different base-line hazard function ${\lambda }_{0}$.
The base-line survivor function associated with a failure time ${t}_{\left(i\right)}$, is estimated as $\mathrm{exp}\left(-\stackrel{^}{H}\left({t}_{\left(i\right)}\right)\right)$, where
 $H ^ t i = ∑ t j ≤ t i d i ∑ l ∈ R t j exp zlT β ^ + ω l ,$ (5)
where ${d}_{i}$ is the number of failures at time ${t}_{\left(i\right)}$. The residual for the $l$th observation is computed as:
 $r t l = H ^ t l exp - zlT β ^ + ω l$
where $\stackrel{^}{H}\left({t}_{l}\right)=\stackrel{^}{H}\left({t}_{\left(i\right)}\right),{t}_{\left(i\right)}\le {t}_{l}<{t}_{\left(i+1\right)}$. The deviance is defined as $-2×$(logarithm of marginal likelihood). There are two ways to test whether individual covariates are significant: the differences between the deviances of nested models can be compared with the appropriate ${\chi }^{2}$-distribution; or, the asymptotic normality of the parameter estimates can be used to form $z$ tests by dividing the estimates by their standard errors or the score function for the model under the null hypothesis can be used to form $z$ tests.
Cox D R (1972) Regression models in life tables (with discussion) J. Roy. Statist. Soc. Ser. B 34 187–220
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

## 5  Arguments

1:     nIntegerInput
On entry: the number of data points, $n$.
Constraint: ${\mathbf{n}}\ge 2$.
2:     mIntegerInput
On entry: the number of covariates in array z.
Constraint: ${\mathbf{m}}\ge 1$.
3:     nsIntegerInput
On entry: the number of strata. If ${\mathbf{ns}}>0$ then the stratum for each observation must be supplied in isi.
Constraint: ${\mathbf{ns}}\ge 0$.
4:     z[${\mathbf{n}}×{\mathbf{tdz}}$]const doubleInput
Note: the $\left(i,j\right)$th element of the matrix $Z$ is stored in ${\mathbf{z}}\left[\left(i-1\right)×{\mathbf{tdz}}+j-1\right]$.
On entry: the $i$th row must contain the covariates which are associated with the $i$th failure time given in t.
5:     tdzIntegerInput
On entry: the stride separating matrix column elements in the array z.
Constraint: ${\mathbf{tdz}}\ge {\mathbf{m}}$.
6:     sz[m]const IntegerInput
On entry: indicates which subset of covariates is to be included in the model.
${\mathbf{sz}}\left[i-1\right]\ge 1$
The $j$th covariate is included in the model.
${\mathbf{sz}}\left[i-1\right]=0$
The $j$th covariate is excluded from the model and not referenced.
Constraints:
• ${\mathbf{sz}}\left[j-1\right]\ge 0$;
• At least one and at most ${n}_{0}-1$ elements of sz must be nonzero where ${n}_{0}$ is the number of observations excluding any with zero value of isi.
7:     ipIntegerInput
On entry: the number of covariates included in the model as indicated by sz.
Constraint: ${\mathbf{ip}}=\text{}$ number of nonzero values of sz.
8:     t[n]const doubleInput
On entry: the vector of $n$ failure censoring times.
9:     ic[n]const IntegerInput
On entry: the status of the individual at time $t$ given in t.
${\mathbf{ic}}\left[i-1\right]=0$
Indicates that the $i$th individual has failed at time ${\mathbf{t}}\left[i-1\right]$.
${\mathbf{ic}}\left[i-1\right]=1$
Indicates that the $i$th individual has been censored at time ${\mathbf{t}}\left[i-1\right]$.
Constraint: ${\mathbf{ic}}\left[\mathit{i}-1\right]=0\text{​ or ​}1$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
10:   omega[n]const doubleInput
On entry: if an offset is required then omega must contain the value of ${\omega }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$. Otherwise omega must be set NULL.
11:   isi[$×$]const IntegerInput
On entry: if ${\mathbf{ns}}>0$ the stratum indicators which also allow data points to be excluded from the analysis. If ${\mathbf{ns}}=0$, isi is not referenced and may be NULL.
${\mathbf{isi}}\left[\mathit{i}-1\right]=k$
Indicates that the $\mathit{i}$th data point is in the $\mathit{k}$th stratum, for $\mathit{k}=1,2,\dots ,{\mathbf{ns}}$.
${\mathbf{isi}}\left[\mathit{i}-1\right]=0$
Indicates that the $i$th data point is omitted from the analysis.
Constraint: if ${\mathbf{ns}}>0$, $0\le {\mathbf{isi}}\left[\mathit{i}-1\right]\le {\mathbf{ns}}$, and more than ip values of ${\mathbf{isi}}\left[\mathit{i}-1\right]>0$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
12:   devdouble *Output
On exit: the deviance, that is $-2×$(maximized log marginal likelihood).
13:   b[ip]doubleInput/Output
On entry: initial estimates of the covariate coefficient arguments $\beta$. ${\mathbf{b}}\left[j-1\right]$ must contain the initial estimate of the coefficient of the covariate in z corresponding to the $j$th nonzero value of sz.
Suggested value: In many cases an initial value of zero for ${\mathbf{b}}\left[j-1\right]$ may be used. For other suggestions see Section 9.
On exit: ${\mathbf{b}}\left[j-1\right]$ contains the estimate ${\stackrel{^}{\beta }}_{i}$, the coefficient of the covariate stored in the $i$th column of z where $i$ is the $j$th nonzero value in the array sz.
14:   se[ip]doubleOutput
On exit: ${\mathbf{se}}\left[j-1\right]$ is the asymptotic standard error of the estimate contained in ${\mathbf{b}}\left[j-1\right]$ and score function in ${\mathbf{sc}}\left[j-1\right]$ for $j=1,2,\dots ,{\mathbf{ip}}$.
15:   sc[ip]doubleOutput
On exit: ${\mathbf{sc}}\left[j-1\right]$ is the value of the score function, ${U}_{j}\left(\beta \right)$, for the estimate contained in ${\mathbf{b}}\left[j-1\right]$.
16:   cov[${\mathbf{ip}}×\left({\mathbf{ip}}+1\right)$]doubleOutput
On exit: the variance-covariance matrix of the parameter estimates in b stored in packed form by column, i.e., the covariance between the parameter estimates given in ${\mathbf{b}}\left[i-1\right]$ and ${\mathbf{b}}\left[j-1\right]$, $j\ge i$, is stored in ${\mathbf{cov}}\left(j\left(j-1\right)/2+i\right)$.
17:   res[n]doubleOutput
On exit: the residuals, $r\left({t}_{l}\right)$, $l=1,2,\dots ,{\mathbf{n}}$.
18:   ndInteger *Output
On exit: the number of distinct failure times.
19:   tp[ndmax]doubleOutput
On exit: ${\mathbf{tp}}\left[i-1\right]$ contains the $i$th distinct failure time, for $i=1,2,\dots ,{\mathbf{nd}}$.
20:   sur[${\mathbf{ndmax}}×{\mathbf{tdsur}}$]doubleOutput
Note: the $\left(i,j\right)$th element of the matrix is stored in ${\mathbf{sur}}\left[\left(i-1\right)×{\mathbf{tdsur}}+j-1\right]$.
On exit: if ${\mathbf{ns}}=0$, sur$\left(i,1\right)$ contains the estimated survival function for the $i$th distinct failure time.
If ${\mathbf{ns}}>0$, sur$\left(i,k\right)$ contains the estimated survival function for the $i$th distinct failure time in the $k$th stratum.
21:   tdsurIntegerInput
On entry: the stride separating matrix column elements in the array sur.
Constraint: ${\mathbf{tdsur}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
22:   ndmaxIntegerInput
On entry: the second dimension of the array sur.
Constraint: ${\mathbf{ndmax}}\ge$ the number of distinct failure times. This is returned in nd.
23:   toldoubleInput
On entry: indicates the accuracy required for the estimation. Convergence is assumed when the decrease in deviance is less than ${\mathbf{tol}}×$($1.0+$CurrentDeviance). This corresponds approximately to an absolute precision if the deviance is small and a relative precision if the deviance is large.
Constraint: .
24:   max_iterIntegerInput
On entry: the maximum number of iterations to be used for computing the estimates. If max_iter is set to 0 then the standard errors, score functions, variance-covariance matrix and the survival function are computed for the input value of $\beta$ in b but $\beta$ is not updated.
Constraint: ${\mathbf{max_iter}}\ge 0$.
25:   iprintIntegerInput
On entry: indicates if the printing of information on the iterations is required.
${\mathbf{iprint}}\le 0$
There is no printing.
${\mathbf{iprint}}\ge 1$
The deviance and the current estimates are printed every iprint iterations.
26:   outfileconst char *Input
On entry: the name of the file into which information is to be output. If outfile is set to NULL or to the string ‘stdout’, then the monitoring information is output to stdout.
27:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{tdsur}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{ns}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{tdsur}}\ge {\mathbf{ns}}$.
On entry, ${\mathbf{tdz}}=⟨\mathit{\text{value}}⟩$ while ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$. These arguments must satisfy ${\mathbf{tdz}}\ge {\mathbf{m}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_ARRAY_CONS
The contents of array ic are not valid.
Constraint: not all values of ic can be 1.
NE_G12BA_CONV
Convergence has not been achieved in max_iter iterations. The progress towards convergence can be examined by using by setting iprint to $\ge 1$. Any non-convergence may be due to a linear combination of covariates being monotonic with time. Full results are returned.
NE_G12BA_DEV
In the current iteration 10 step halvings have been performed without decreasing the deviance from the previous iteration. Convergence is assumed.
NE_G12BA_MAT_SING
The matrix of second partial derivatives is singular. Try different starting values or include fewer covariates.
NE_G12BA_NDMAX
On entry, ndmax is $\text{}=⟨\mathit{\text{value}}⟩$ while the output value of ${\mathbf{nd}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ndmax}}\ge {\mathbf{nd}}$.
NE_G12BA_OVERFLOW
Overflow has been detected. Try different starting values.
NE_G12BA_SZ_IP
On entry, ${\mathbf{ip}}=⟨\mathit{\text{value}}⟩$ and the number of nonzero values of ${\mathbf{sz}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ip}}=\text{}$ the number of nonzero values of sz.
NE_G12BA_SZ_ISI
On entry, the number of values of ${\mathbf{sz}}\left[i\right]>0$ is $⟨\mathit{\text{value}}⟩$, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$ and excluded observations with ${\mathbf{isi}}\left[i\right]=0$ is $⟨\mathit{\text{value}}⟩$.
Constraint: the number of values of nonzero sz must be less than ${\mathbf{n}}-$ excluded observations.
NE_INT_ARG_LT
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, max_iter must not be less than 0: ${\mathbf{max_iter}}=⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
On entry, ${\mathbf{ns}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ns}}\ge 0$.
On entry, ${\mathbf{tdsur}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{tdsur}}\ge 1$.
NE_INT_ARRAY_CONS
On entry, ${\mathbf{ic}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ic}}\left[⟨\mathit{\text{value}}⟩\right]=0$ or 1.
On entry, ${\mathbf{isi}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $0\le {\mathbf{isi}}\left[⟨\mathit{\text{value}}⟩\right]\le {\mathbf{ns}}$.
On entry, ${\mathbf{sz}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{sz}}\left[⟨\mathit{\text{value}}⟩\right]\ge 0$.
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_NOT_APPEND_FILE
Cannot open file outfile for appending.
NE_NOT_CLOSE_FILE
Cannot close file outfile.
NE_REAL_MACH_PREC
On entry, ${\mathbf{tol}}=⟨\mathit{\text{value}}⟩$, .
Constraint: .

## 7  Accuracy

The accuracy is specified by tol.

Not applicable.

## 9  Further Comments

nag_surviv_cox_model (g12bac) uses mean centering which involves subtracting the means from the covariables prior to computation of any statistics. This helps to minimize the effect of outlying observations and accelerates convergence.
If the initial estimates are poor then there may be a problem with overflow in calculating $\mathrm{exp}\left({\beta }^{\mathrm{T}}{z}_{i}\right)$ or there may be non-convergence. Reasonable estimates can often be obtained by fitting an exponential model using nag_glm_poisson (g02gcc).

## 10  Example

The data are the remission times for two groups of leukemia patients (see Gross and Clark (1975) p242). A dummy variable indicates which group they come from. An initial estimate is computed using the exponential model and then the Cox proportional hazard model is fitted and parameter estimates and the survival function are printed.

### 10.1  Program Text

Program Text (g12bace.c)

### 10.2  Program Data

Program Data (g12bace.d)

### 10.3  Program Results

Program Results (g12bace.r)

nag_surviv_cox_model (g12bac) (PDF version)
g12 Chapter Contents
g12 Chapter Introduction
NAG Library Manual