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_risksets (g12za)

## Purpose

nag_surviv_coxmodel_risksets (g12za) creates the risk sets associated with the Cox proportional hazards model for fixed covariates.

## Syntax

[num, ixs, nxs, x, id, nd, tp, irs, ifail] = g12za(ns, z, isz, ip, t, ic, isi, mxn, 'n', n, 'm', m)
[num, ixs, nxs, x, id, nd, tp, irs, ifail] = nag_surviv_coxmodel_risksets(ns, z, isz, ip, t, ic, isi, mxn, 'n', n, 'm', m)

## Description

The Cox proportional hazards model (see Cox (1972)) 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 ti${t}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$, be the failure time or censored time for the i$i$th observation with the vector of p$p$ covariates zi${z}_{i}$. It is assumed that censoring and failure mechanisms are independent. The hazard function, λ(t,z)$\lambda \left(t,z\right)$, is the probability that an individual with covariates z$z$ fails at time t$t$ given that the individual survived up to time t$t$. In the Cox proportional hazards model, λ(t,z)$\lambda \left(t,z\right)$ is of the form
 λ(t,z) = λ0(t)exp(zTβ), $λ(t,z)=λ0(t)exp(zTβ),$
where λ0${\lambda }_{0}$ is the base-line hazard function, an unspecified function of time, and β$\beta$ is a vector of unknown parameters. As λ0${\lambda }_{0}$ is unknown, the parameters β$\beta$ are estimated using the conditional or marginal likelihood. This involves considering the covariate values of all subjects that are at risk at the time when a failure occurs. The probability that the subject that failed had their observed set of covariate values is computed.
The risk set at a failure time consists of those subjects that fail or are censored at that time and those who survive beyond that time. As risk sets are computed for every distinct failure time, it should be noted that the combined risk sets may be considerably larger than the original data. If the data can be considered as coming from different strata such that λ0${\lambda }_{0}$ varies from strata to strata but β$\beta$ remains constant, then nag_surviv_coxmodel_risksets (g12za) will return a factor that indicates to which risk set/strata each member of the risk sets belongs rather than just to which risk set.
Given the risk sets the Cox proportional hazards model can then be fitted using a Poisson generalized linear model (nag_correg_glm_poisson (g02gc) with nag_anova_dummyvars (g04ea) to compute dummy variables) using Breslow's approximation for ties (see Breslow (1974)). This will give the same fit as nag_surviv_coxmodel (g12ba). If the exact treatment of ties in discrete time is required, as given by Cox (1972), then the model is fitted as a conditional logistic model using nag_contab_condl_logistic (g11ca).

## References

Breslow N E (1974) Covariate analysis of censored survival data Biometrics 30 89–99
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

## Parameters

### Compulsory Input Parameters

1:     ns – int64int32nag_int scalar
The number of strata. If ns > 0${\mathbf{ns}}>0$ then the stratum for each observation must be supplied in isi.
Constraint: ns0${\mathbf{ns}}\ge 0$.
2:     z(ldz,m) – double array
ldz, the first dimension of the array, must satisfy the constraint ldzn$\mathit{ldz}\ge {\mathbf{n}}$.
The i$i$th row must contain the covariates which are associated with the i$i$th failure time given in t.
3:     isz(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint m1${\mathbf{m}}\ge 1$.
Indicates which subset of covariates are to be included in the model.
isz(j)1${\mathbf{isz}}\left(j\right)\ge 1$
The j$j$th covariate is included in the model.
isz(j) = 0${\mathbf{isz}}\left(j\right)=0$
The j$j$th covariate is excluded from the model and not referenced.
Constraint: isz(j)0${\mathbf{isz}}\left(j\right)\ge 0$ and at least one value must be nonzero.
4:     ip – int64int32nag_int scalar
p$p$, the number of covariates included in the model as indicated by isz.
Constraint: ip = ${\mathbf{ip}}=\text{}$ the number of nonzero values of isz.
5:     t(n) – double array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
The vector of n$n$ failure censoring times.
6:     ic(n) – int64int32nag_int array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
The status of the individual at time t$t$ given in t.
ic(i) = 0${\mathbf{ic}}\left(i\right)=0$
Indicates that the i$i$th individual has failed at time t(i)${\mathbf{t}}\left(i\right)$.
ic(i) = 1${\mathbf{ic}}\left(i\right)=1$
Indicates that the i$i$th individual has been censored at time t(i)${\mathbf{t}}\left(i\right)$.
Constraint: ic(i) = 0${\mathbf{ic}}\left(\mathit{i}\right)=0$ or 1$1$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
7:     isi( : $:$) – int64int32nag_int array
Note: the dimension of the array isi must be at least n${\mathbf{n}}$ if ns > 0${\mathbf{ns}}>0$, and at least 1$1$ otherwise.
If ns > 0${\mathbf{ns}}>0$, the stratum indicators which also allow data points to be excluded from the analysis.
If ns = 0${\mathbf{ns}}=0$, isi is not referenced.
isi(i) = k${\mathbf{isi}}\left(i\right)=k$
Indicates that the i$i$th data point is in the k$k$th stratum, where k = 1,2,,ns$k=1,2,\dots ,{\mathbf{ns}}$.
isi(i) = 0${\mathbf{isi}}\left(i\right)=0$
Indicates that the i$i$th data point is omitted from the analysis.
Constraint: if ns > 0${\mathbf{ns}}>0$, 0isi(i)ns$0\le {\mathbf{isi}}\left(\mathit{i}\right)\le {\mathbf{ns}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
8:     mxn – int64int32nag_int scalar
The first dimension of the array x and the dimension of the arrays ixs and id as declared in the (sub)program from which nag_surviv_coxmodel_risksets (g12za) is called.
Constraint: mxn must be sufficiently large for the arrays to contain the expanded risk sets. The size will depend on the pattern of failures times and censored times. The minimum value will be returned in num unless the function exits with ${\mathbf{ifail}}={\mathbf{1}}$ or 2${\mathbf{2}}$.

### Optional Input Parameters

1:     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$n$, the number of data points.
Constraint: n2${\mathbf{n}}\ge 2$.
2:     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: m1${\mathbf{m}}\ge 1$.

ldz

### Output Parameters

1:     num – int64int32nag_int scalar
The number of values in the combined risk sets.
2:     ixs(mxn) – int64int32nag_int array
The factor giving the risk sets/strata for the data in x and id.
If ns = 0${\mathbf{ns}}=0$ or 1$1$, ixs(i) = l${\mathbf{ixs}}\left(i\right)=l$ for members of the l$l$th risk set.
If ns > 1${\mathbf{ns}}>1$, ixs(i) = (j1) × nd + l${\mathbf{ixs}}\left(i\right)=\left(j-1\right)×{\mathbf{nd}}+l$ for the observations in the l$l$th risk set for the j$j$th strata.
3:     nxs – int64int32nag_int scalar
The number of levels for the risk sets/strata factor given in ixs.
4:     x(mxn,ip) – double array
The first num rows contain the values of the covariates for the members of the risk sets.
5:     id(mxn) – int64int32nag_int array
Indicates if the member of the risk set given in x failed.
id(i) = 1${\mathbf{id}}\left(i\right)=1$ if the member of the risk set failed at the time defining the risk set and id(i) = 0${\mathbf{id}}\left(i\right)=0$ otherwise.
6:     nd – int64int32nag_int scalar
The number of distinct failure times, i.e., the number of risk sets.
7:     tp(n) – double array
tp(i)${\mathbf{tp}}\left(\mathit{i}\right)$ contains the i$\mathit{i}$th distinct failure time, for i = 1,2,,nd$\mathit{i}=1,2,\dots ,{\mathbf{nd}}$.
8:     irs(n) – int64int32nag_int array
Indicates rows in x and elements in ixs and id corresponding to the risk sets. The first risk set corresponding to failure time tp(1)${\mathbf{tp}}\left(1\right)$ is given by rows 1$1$ to irs(1)${\mathbf{irs}}\left(1\right)$. The l$\mathit{l}$th risk set is given by rows id(l1) + 1${\mathbf{id}}\left(\mathit{l}-1\right)+1$ to id(l)${\mathbf{id}}\left(\mathit{l}\right)$, for l = 1,2,,nd$\mathit{l}=1,2,\dots ,{\mathbf{nd}}$.
9:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, m < 1${\mathbf{m}}<1$, or n < 2${\mathbf{n}}<2$, or ns < 0${\mathbf{ns}}<0$, or ldz < n$\mathit{ldz}<{\mathbf{n}}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, isz(i) < 0${\mathbf{isz}}\left(i\right)<0$ for some i$i$, or the value of ip is incompatible with isz, or ic(i) ≠ 1${\mathbf{ic}}\left(i\right)\ne 1$ or 0$0$. or ns > 0${\mathbf{ns}}>0$ and isi(i) < 0${\mathbf{isi}}\left(i\right)<0$, or ns > 1${\mathbf{ns}}>1$ and isi(i) > ns${\mathbf{isi}}\left(i\right)>{\mathbf{ns}}$.
ifail = 3${\mathbf{ifail}}=3$
mxn is too small, the minimum value is returned in num.

## Accuracy

Not applicable.

When there are strata present, i.e., ns > 1${\mathbf{ns}}>1$, not all the nxs groups may be present.

## Example

```function nag_surviv_coxmodel_risksets_example
ns = int64(0);
z = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;1;1; ...
1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1];
isz = [int64(1)];
ip = 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];
ic = [int64(0);0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0; ...
0;0;0;0;0;0;0;0;0;1;1;1;1;1;1;1;1;1;1;1;1];
isi = [int64(0)];
mxn = int64(1000);
[num, ixs, nxs, x, id, nd, tp, irs, ifail] = ...
nag_surviv_coxmodel_risksets(ns, z, isz, ip, t, ic, isi, mxn);
num, nxs, nd, ifail
```
```

num =

418

nxs =

17

nd =

17

ifail =

0

```
```function g12za_example
ns = int64(0);
z = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;1;1; ...
1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1];
isz = [int64(1)];
ip = 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];
ic = [int64(0);0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0; ...
0;0;0;0;0;0;0;0;0;1;1;1;1;1;1;1;1;1;1;1;1];
isi = [int64(0)];
mxn = int64(1000);
[num, ixs, nxs, x, id, nd, tp, irs, ifail] = g12za(ns, z, isz, ip, t, ic, isi, mxn);
num, nxs, nd, ifail
```
```

num =

418

nxs =

17

nd =

17

ifail =

0

```

Chapter Contents
Chapter Introduction
NAG Toolbox

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