Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_surviv_coxmodel (g12ba)

## Purpose

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

## Syntax

[dev, b, se, sc, covar, res, nd, tp, sur, ifail] = g12ba(offset, ns, z, isz, t, ic, omega, isi, b, ndmax, tol, maxit, iprint, 'n', n, 'm', m, 'ip', ip)
[dev, b, se, sc, covar, res, nd, tp, sur, ifail] = nag_surviv_coxmodel(offset, ns, z, isz, t, ic, omega, isi, b, ndmax, tol, maxit, iprint, 'n', n, 'm', m, 'ip', ip)

## 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 (see Cox (1972)) $\lambda \left(t,z\right)$ is of the form:
 $λt,z=λ0texpzTβ+ω$
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=1ndexpsiTβ+ωi ∑l∈RtiexpzlTβ+ωldi$ (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:
 $Ujβ= ∂ln⁡L ∂βj =∑i=1ndsji-diαjiβ=0$ (2)
for $j=1,2,\dots ,p$, where ${s}_{ji}$ is the $j$th element in the vector ${s}_{i}$ and
 $αjiβ=∑l∈RtizjlexpzlTβ+ωl ∑l∈RtiexpzlTβ+ωl .$
Similarly,
 $Ihjβ=- ∂2ln⁡L ∂βh∂βj =∑i=1nddiγhji$ (3)
where
 $γhji=∑l∈Rti zhlzjlexpzlTβ+ωl ∑l∈RtiexpzlTβ+ω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 $\mathbf{\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 $\mathit{k}$th stratum is ${n}_{\mathit{k}}$, for $\mathit{k}=1,2,\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νLk,$ (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^ti=∑tj≤ti di∑l∈RtjexpzlTβ^+ω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:
 $rtl= H^tlexpzlTβ^+ω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×\text{}$(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.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{offset}$ – string (length ≥ 1)
Indicates if an offset is to be used.
${\mathbf{offset}}=\text{'Y'}$
An offset must be included in omega.
${\mathbf{offset}}=\text{'N'}$
No offset is included in the model.
Constraint: ${\mathbf{offset}}=\text{'Y'}$ or $\text{'N'}$.
2:     $\mathrm{ns}$int64int32nag_int scalar
The number of strata. If ${\mathbf{ns}}>0$ then the stratum for each observation must be supplied in isi.
Constraint: ${\mathbf{ns}}\ge 0$.
3:     $\mathrm{z}\left(\mathit{ldz},{\mathbf{m}}\right)$ – double array
ldz, the first dimension of the array, must satisfy the constraint $\mathit{ldz}\ge {\mathbf{n}}$.
The $i$th row must contain the covariates which are associated with the $i$th failure time given in t.
4:     $\mathrm{isz}\left({\mathbf{m}}\right)$int64int32nag_int array
Indicates which subset of covariates is to be included in the model.
${\mathbf{isz}}\left(j\right)\ge 1$
The $j$th covariate is included in the model.
${\mathbf{isz}}\left(j\right)=0$
The $j$th covariate is excluded from the model and not referenced.
Constraint: ${\mathbf{isz}}\left(j\right)\ge 0$ and at least one and at most ${n}_{0}-1$ elements of isz must be nonzero where ${n}_{0}$ is the number of observations excluding any with zero value of isi.
5:     $\mathrm{t}\left({\mathbf{n}}\right)$ – double array
The vector of $n$ failure censoring times.
6:     $\mathrm{ic}\left({\mathbf{n}}\right)$int64int32nag_int array
The status of the individual at time $t$ given in t.
${\mathbf{ic}}\left(i\right)=0$
The $i$th individual has failed at time ${\mathbf{t}}\left(i\right)$.
${\mathbf{ic}}\left(i\right)=1$
The $i$th individual has been censored at time ${\mathbf{t}}\left(i\right)$.
Constraint: ${\mathbf{ic}}\left(\mathit{i}\right)=0$ or $1$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
7:     $\mathrm{omega}\left(:\right)$ – double array
The dimension of the array omega must be at least ${\mathbf{n}}$ if ${\mathbf{offset}}=\text{'Y'}$, and at least $1$ otherwise
If ${\mathbf{offset}}=\text{'Y'}$, the offset, ${\omega }_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$. Otherwise omega is not referenced.
8:     $\mathrm{isi}\left(:\right)$int64int32nag_int array
The dimension of the array isi must be at least ${\mathbf{n}}$ if ${\mathbf{ns}}>0$, and at least $1$ otherwise
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.
${\mathbf{isi}}\left(i\right)=k$
The $i$th data point is in the $k$th stratum, where $k=1,2,\dots ,{\mathbf{ns}}$.
${\mathbf{isi}}\left(i\right)=0$
The $i$th data point is omitted from the analysis.
Constraint: if ${\mathbf{ns}}>0$, $0\le {\mathbf{isi}}\left(\mathit{i}\right)\le {\mathbf{ns}}$ and more than ip values of ${\mathbf{isi}}\left(\mathit{i}\right)>0$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
9:     $\mathrm{b}\left({\mathbf{ip}}\right)$ – double array
Suggested value: in many cases an initial value of zero for ${\mathbf{b}}\left(j\right)$ may be used. For other suggestions see Further Comments.
Initial estimates of the covariate coefficient arguments $\beta$. ${\mathbf{b}}\left(j\right)$ must contain the initial estimate of the coefficient of the covariate in z corresponding to the $j$th nonzero value of isz.
10:   $\mathrm{ndmax}$int64int32nag_int scalar
The dimension of the array tp and the first dimension of the array sur.
Constraint: ${\mathbf{ndmax}}\ge \text{the number of distinct failure times. This is returned in ​}{\mathbf{nd}}$.
11:   $\mathrm{tol}$ – double scalar
Indicates the accuracy required for the estimation. Convergence is assumed when the decrease in deviance is less than ${\mathbf{tol}}×\left(1.0+\mathrm{CurrentDeviance}\right)$. This corresponds approximately to an absolute precision if the deviance is small and a relative precision if the deviance is large.
Constraint: .
12:   $\mathrm{maxit}$int64int32nag_int scalar
The maximum number of iterations to be used for computing the estimates. If maxit 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{maxit}}\ge 0$.
13:   $\mathrm{iprint}$int64int32nag_int scalar
Indicates if the printing of information on the iterations is required.
${\mathbf{iprint}}\le 0$
No printing.
${\mathbf{iprint}}\ge 1$
The deviance and the current estimates are printed every iprint iterations. When printing occurs the output is directed to the current advisory message unit (see nag_file_set_unit_advisory (x04ab)).

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays t, ic and the first dimension of the array z. (An error is raised if these dimensions are not equal.)
$n$, the number of data points.
Constraint: ${\mathbf{n}}\ge 2$.
2:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the array isz and the second dimension of the array z. (An error is raised if these dimensions are not equal.)
The number of covariates in array z.
Constraint: ${\mathbf{m}}\ge 1$.
3:     $\mathrm{ip}$int64int32nag_int scalar
Default: the dimension of the array b.
The number of covariates included in the model as indicated by isz.
Constraints:
• ${\mathbf{ip}}\ge 1$;
• ${\mathbf{ip}}=\text{​ number of nonzero values of ​}{\mathbf{isz}}$.

### Output Parameters

1:     $\mathrm{dev}$ – double scalar
The deviance, that is $-2×\text{}$(maximized log marginal likelihood).
2:     $\mathrm{b}\left({\mathbf{ip}}\right)$ – double array
Suggested value: in many cases an initial value of zero for ${\mathbf{b}}\left(j\right)$ may be used. For other suggestions see Further Comments.
${\mathbf{b}}\left(j\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 isz.
3:     $\mathrm{se}\left({\mathbf{ip}}\right)$ – double array
${\mathbf{se}}\left(\mathit{j}\right)$ is the asymptotic standard error of the estimate contained in ${\mathbf{b}}\left(\mathit{j}\right)$ and score function in ${\mathbf{sc}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{\mathbf{ip}}$.
4:     $\mathrm{sc}\left({\mathbf{ip}}\right)$ – double array
${\mathbf{sc}}\left(j\right)$ is the value of the score function, ${U}_{j}\left(\beta \right)$, for the estimate contained in ${\mathbf{b}}\left(j\right)$.
5:     $\mathrm{covar}\left({\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2\right)$ – double array
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\right)$ and ${\mathbf{b}}\left(j\right)$, $j\ge i$, is stored in ${\mathbf{covar}}\left(j\left(j-1\right)/2+i\right)$.
6:     $\mathrm{res}\left({\mathbf{n}}\right)$ – double array
The residuals, $r\left({t}_{\mathit{l}}\right)$, for $\mathit{l}=1,2,\dots ,{\mathbf{n}}$.
7:     $\mathrm{nd}$int64int32nag_int scalar
The number of distinct failure times.
8:     $\mathrm{tp}\left({\mathbf{ndmax}}\right)$ – double array
${\mathbf{tp}}\left(\mathit{i}\right)$ contains the $\mathit{i}$th distinct failure time, for $\mathit{i}=1,2,\dots ,{\mathbf{nd}}$.
9:     $\mathrm{sur}\left({\mathbf{ndmax}},:\right)$ – double array
The second dimension of the array sur will be $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{ns}},1\right)$.
If ${\mathbf{ns}}=0$, ${\mathbf{sur}}\left(i,1\right)$ contains the estimated survival function for the $i$th distinct failure time.
If ${\mathbf{ns}}>0$, ${\mathbf{sur}}\left(i,k\right)$ contains the estimated survival function for the $i$th distinct failure time in the $k$th stratum.
10:   $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=1$
 On entry, ${\mathbf{offset}}\ne \text{'Y'}$ or $\text{'N'}$, or ${\mathbf{m}}<1$, or ${\mathbf{n}}<2$, or ${\mathbf{ns}}<0$, or ${\mathbf{ip}}<1$, or $\mathit{ldz}<{\mathbf{n}}$, or , or ${\mathbf{maxit}}<0$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{isz}}\left(i\right)<0$ for some $i$, or the value of ip is incompatible with isz, or ${\mathbf{ic}}\left(i\right)\ne 1$ or $0$. or ${\mathbf{isi}}\left(i\right)<0$ or ${\mathbf{isi}}\left(i\right)>{\mathbf{ns}}$, or number of values of ${\mathbf{isz}}\left(i\right)>0$ is greater than or equal to ${n}_{0}$, the number of observations excluding any with ${\mathbf{isi}}\left(i\right)=0$, or all observations are censored, i.e., ${\mathbf{ic}}\left(i\right)=1$ for all $i$, or ndmax is too small.
${\mathbf{ifail}}=3$
The matrix of second partial derivatives is singular. Try different starting values or include fewer covariates.
${\mathbf{ifail}}=4$
Overflow has been detected. Try using different starting values.
W  ${\mathbf{ifail}}=5$
Convergence has not been achieved in maxit iterations. The progress toward convergence can be examined by using a nonzero value of iprint. Any non-convergence may be due to a linear combination of covariates being monotonic with time.
Full results are returned.
W  ${\mathbf{ifail}}=6$
In the current iteration $10$ step halvings have been performed without decreasing the deviance from the previous iteration. Convergence is assumed.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The accuracy is specified by tol.

nag_surviv_coxmodel (g12ba) 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_correg_glm_poisson (g02gc).

## Example

The data are the remission times for two groups of leukemia patients (see page 242 of Gross and Clark (1975)). 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.
```function g12ba_example

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

% Data
n = 42;
m = 1;
z          = zeros(n,m);
ic         = zeros(n,1,'int64');
ic(31:end) = 1;
z(22:end)  = 1;
isz        = [int64(1)];

t = [ 1;      1;      2;      2;      3;      4;      4;
5;      5;      8;      8;      8;      8;     11;
11;     12;     12;     15;     17;     22;     23;
6;      6;      6;      7;     10;     13;     16;
22;     23;      6;      9;     10;     11;     17;
19;     20;     25;     32;     32;     34;     35];

% Parameters for Cox proportional hazards model
offset = 'No-offset';
ns     = int64(0);
omega  = ;
isi    = [int64(0)];
b(1)   = ;
ndmax  = int64(n);
tol    = 5e-05;
maxit  = int64(20);
iprint = int64(0);

% Fit Cox proportional hazards model
[dev, b, se, sc, covar, res, nd, tp, sur, ifail] = ...
g12ba( ...
offset, ns, z, isz, t, ic, omega, isi, b, ndmax, tol, maxit, iprint);

% Display results
ns = max(ns,1);
fprintf(' Parameter      Estimate       Standard Error\n\n');
ivar = [1:m]';
fprintf('%6d%18.4f%18.4f\n',[ivar b se]');
fprintf('\n Deviance = %13.3e\n\n', dev);
fprintf('    Time     Survivor Function\n\n');
results = [tp(1:nd) sur(1:nd,1:ns)];
fprintf('%7.0f%16.4f\n', results');

```
```g12ba example results

Parameter      Estimate       Standard Error

1           -1.5092            0.4096

Deviance =     1.728e+02

Time     Survivor Function

1          0.9640
2          0.9264
3          0.9065
4          0.8661
5          0.8235
6          0.7566
7          0.7344
8          0.6506
10          0.6241
11          0.5724
12          0.5135
13          0.4785
15          0.4447
16          0.4078
17          0.3727
22          0.2859
23          0.1908
```