# NAG FL Interfaceg12zaf (coxmodel_​risksets)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g12zaf creates the risk sets associated with the Cox proportional hazards model for fixed covariates.

## 2Specification

Fortran Interface
 Subroutine g12zaf ( n, m, ns, z, ldz, isz, ip, t, ic, isi, num, ixs, nxs, x, mxn, id, nd, tp, irs,
 Integer, Intent (In) :: n, m, ns, ldz, isz(m), ip, ic(n), isi(*), mxn Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: num, ixs(mxn), nxs, id(mxn), nd, irs(n) Real (Kind=nag_wp), Intent (In) :: z(ldz,m), t(n) Real (Kind=nag_wp), Intent (Inout) :: x(mxn,ip) Real (Kind=nag_wp), Intent (Out) :: tp(n)
#include <nag.h>
 void g12zaf_ (const Integer *n, const Integer *m, const Integer *ns, const double z[], const Integer *ldz, const Integer isz[], const Integer *ip, const double t[], const Integer ic[], const Integer isi[], Integer *num, Integer ixs[], Integer *nxs, double x[], const Integer *mxn, Integer id[], Integer *nd, double tp[], Integer irs[], Integer *ifail)
The routine may be called by the names g12zaf or nagf_surviv_coxmodel_risksets.

## 3Description

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 ${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, $\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, and $\beta$ is a vector of unknown parameters. As ${\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 ${\lambda }_{0}$ varies from strata to strata but $\beta$ remains constant, then g12zaf 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 (g02gcf with g04eaf to compute dummy variables) using Breslow's approximation for ties (see Breslow (1974)). This will give the same fit as g12baf. 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 g11caf.

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of data points.
Constraint: ${\mathbf{n}}\ge 2$.
2: $\mathbf{m}$Integer Input
On entry: the number of covariates in array z.
Constraint: ${\mathbf{m}}\ge 1$.
3: $\mathbf{ns}$Integer Input
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: $\mathbf{z}\left({\mathbf{ldz}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
On entry: the $i$th row must contain the covariates which are associated with the $i$th failure time given in t.
5: $\mathbf{ldz}$Integer Input
On entry: the first dimension of the array z as declared in the (sub)program from which g12zaf is called.
Constraint: ${\mathbf{ldz}}\ge {\mathbf{n}}$.
6: $\mathbf{isz}\left({\mathbf{m}}\right)$Integer array Input
On entry: indicates which subset of covariates are 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 value must be nonzero.
7: $\mathbf{ip}$Integer Input
On entry: $p$, the number of covariates included in the model as indicated by isz.
Constraint: ${\mathbf{ip}}=\text{}$ the number of nonzero values of isz.
8: $\mathbf{t}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the vector of $n$ failure censoring times.
9: $\mathbf{ic}\left({\mathbf{n}}\right)$Integer array Input
On entry: the status of the individual at time $t$ given in t.
${\mathbf{ic}}\left(i\right)=0$
Indicates that the $i$th individual has failed at time ${\mathbf{t}}\left(i\right)$.
${\mathbf{ic}}\left(i\right)=1$
Indicates that 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}}$.
10: $\mathbf{isi}\left(*\right)$Integer array Input
Note: the dimension of the array isi must be at least ${\mathbf{n}}$ if ${\mathbf{ns}}>0$, and at least $1$ otherwise.
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.
${\mathbf{isi}}\left(i\right)=k$
Indicates that the $i$th data point is in the $k$th stratum, where $k=1,2,\dots ,{\mathbf{ns}}$.
${\mathbf{isi}}\left(i\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}\right)\le {\mathbf{ns}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
11: $\mathbf{num}$Integer Output
On exit: the number of values in the combined risk sets.
12: $\mathbf{ixs}\left({\mathbf{mxn}}\right)$Integer array Output
On exit: the factor giving the risk sets/strata for the data in x and id.
If ${\mathbf{ns}}=0$ or $1$, ${\mathbf{ixs}}\left(i\right)=l$ for members of the $l$th risk set.
If ${\mathbf{ns}}>1$, ${\mathbf{ixs}}\left(i\right)=\left(j-1\right)×{\mathbf{nd}}+l$ for the observations in the $l$th risk set for the $j$th strata.
13: $\mathbf{nxs}$Integer Output
On exit: the number of levels for the risk sets/strata factor given in ixs.
14: $\mathbf{x}\left({\mathbf{mxn}},{\mathbf{ip}}\right)$Real (Kind=nag_wp) array Output
On exit: the first num rows contain the values of the covariates for the members of the risk sets.
15: $\mathbf{mxn}$Integer Input
On entry: the first dimension of the array x and the dimension of the arrays ixs and id as declared in the (sub)program from which g12zaf 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 routine exits with ${\mathbf{ifail}}={\mathbf{1}}$ or ${\mathbf{2}}$.
16: $\mathbf{id}\left({\mathbf{mxn}}\right)$Integer array Output
On exit: indicates if the member of the risk set given in x failed.
${\mathbf{id}}\left(i\right)=1$ if the member of the risk set failed at the time defining the risk set and ${\mathbf{id}}\left(i\right)=0$ otherwise.
17: $\mathbf{nd}$Integer Output
On exit: the number of distinct failure times, i.e., the number of risk sets.
18: $\mathbf{tp}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{tp}}\left(\mathit{i}\right)$ contains the $\mathit{i}$th distinct failure time, for $\mathit{i}=1,2,\dots ,{\mathbf{nd}}$.
19: $\mathbf{irs}\left({\mathbf{n}}\right)$Integer array Output
On exit: indicates rows in x and elements in ixs and id corresponding to the risk sets. The first risk set corresponding to failure time ${\mathbf{tp}}\left(1\right)$ is given by rows $1$ to ${\mathbf{irs}}\left(1\right)$. The $\mathit{l}$th risk set is given by rows ${\mathbf{irs}}\left(\mathit{l}-1\right)+1$ to ${\mathbf{irs}}\left(\mathit{l}\right)$, for $\mathit{l}=1,2,\dots ,{\mathbf{nd}}$.
20: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ldz}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldz}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
On entry, ${\mathbf{ns}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ns}}\ge 0$.
${\mathbf{ifail}}=2$
On entry, $i=⟨\mathit{\text{value}}⟩$, ${\mathbf{isi}}\left(i\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ns}}=⟨\mathit{\text{value}}⟩$.
Constraint: $0\le {\mathbf{isi}}\left(i\right)\le {\mathbf{ns}}$.
On entry, $i=⟨\mathit{\text{value}}⟩$ and ${\mathbf{ic}}\left(i\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ic}}\left(i\right)=0$ or $1$.
On entry, $i=⟨\mathit{\text{value}}⟩$ and ${\mathbf{isz}}\left(i\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{isz}}\left(j\right)\ge 0$.
On entry, there are not ip values of ${\mathbf{isz}}>0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{mxn}}=⟨\mathit{\text{value}}⟩$ and minimum value for ${\mathbf{mxn}}=⟨\mathit{\text{value}}⟩$.
Constraint: mxn must be sufficiently large for the arrays to contain the expanded risk set.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g12zaf is not threaded in any implementation.

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

## 10Example

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. The risk sets are computed using g12zaf and the Cox's proportional hazard model is fitted using g11caf.

### 10.1Program Text

Program Text (g12zafe.f90)

### 10.2Program Data

Program Data (g12zafe.d)

### 10.3Program Results

Program Results (g12zafe.r)