NAG CL Interface
g12zac (coxmodel_​risksets)

Settings help

CL Name Style:


1 Purpose

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

2 Specification

#include <nag.h>
void  g12zac (Nag_OrderType order, Integer n, Integer m, Integer ns, const double z[], Integer pdz, const Integer isz[], Integer ip, const double t[], const Integer ic[], const Integer isi[], Integer *num, Integer ixs[], Integer *nxs, double x[], Integer mxn, Integer id[], Integer *nd, double tp[], Integer irs[], NagError *fail)
The function may be called by the names: g12zac, nag_surviv_coxmodel_risksets or nag_surviv_risk_sets.

3 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, for i=1,2,,n, be the failure time or censored time for the ith observation with the vector of p covariates zi. The covariance matrix Z is constructed so that it contains n rows with the ith row containing the p covariates zi. It is assumed that censoring and failure mechanisms are independent. The hazard function, λ(t,z), 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, λ(t,z) is of the form
λ(t,z)=λ0(t)exp(zTβ),  
where λ0 is the base-line hazard function, an unspecified function of time, and β is a vector of unknown parameters. As λ0 is unknown, the parameters β 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 varies from strata to strata but β remains constant, then g12zac 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 (g02gcc with g04eac to compute dummy variables) using Breslow's approximation for ties (see Breslow (1974)). This will give the same fit as g12bac. 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 g11cac.

4 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

5 Arguments

1: order Nag_OrderType Input
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2: n Integer Input
On entry: n, the number of data points.
Constraint: n2.
3: m Integer Input
On entry: the number of covariates in array z.
Constraint: m1.
4: ns Integer Input
On entry: the number of strata. If ns>0 then the stratum for each observation must be supplied in isi.
Constraint: ns0.
5: z[dim] const double Input
Note: the dimension, dim, of the array z must be at least
  • max(1,pdz×m) when order=Nag_ColMajor;
  • max(1,n×pdz) when order=Nag_RowMajor.
the (i,j)th element of the matrix Z is stored in
  • z[(j-1)×pdz+i-1] when order=Nag_ColMajor;
  • z[(i-1)×pdz+j-1] when order=Nag_RowMajor.
On entry: must contain the n covariates in column or row major order.
6: pdz Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
Constraints:
  • if order=Nag_ColMajor, pdzn;
  • if order=Nag_RowMajor, pdzm.
7: isz[m] const Integer Input
On entry: indicates which subset of covariates are to be included in the model.
isz[j-1]1
The jth covariate is included in the model.
isz[j-1]=0
The jth covariate is excluded from the model and not referenced.
Constraint: isz[j-1]0 and at least one value must be nonzero.
8: ip Integer Input
On entry: p, the number of covariates included in the model as indicated by isz.
Constraint: ip= the number of nonzero values of isz.
9: t[n] const double Input
On entry: the vector of n failure censoring times.
10: ic[n] const Integer Input
On entry: the status of the individual at time t given in t.
ic[i-1]=0
Indicates that the ith individual has failed at time t[i-1].
ic[i-1]=1
Indicates that the ith individual has been censored at time t[i-1].
Constraint: ic[i-1]=0 or 1, for i=1,2,,n.
11: isi[dim] const Integer Input
Note: the dimension, dim, of the array isi must be at least
  • n when ns>0;
  • 1 otherwise.
On entry: if ns>0, the stratum indicators which also allow data points to be excluded from the analysis.
If ns=0, isi is not referenced.
isi[i]=k
Indicates that the ith data point is in the kth stratum, where k=1,2,,ns.
isi[i]=0
Indicates that the ith data point is omitted from the analysis.
Constraint: if ns>0, 0isi[i]ns, for i=0,1,,n-1.
12: num Integer * Output
On exit: the number of values in the combined risk sets.
13: ixs[mxn] Integer Output
On exit: the factor giving the risk sets/strata for the data in x and id.
If ns=0 or 1, ixs[i-1]=l for members of the lth risk set.
If ns>1, ixs[i-1]=(j-1)×nd+l for the observations in the lth risk set for the jth strata.
14: nxs Integer * Output
On exit: the number of levels for the risk sets/strata factor given in ixs.
15: x[mxn×ip] double Output
Note: The (i,j)th element of the matrix X is stored in
  • x[(j-1)×mxn+i-1] when order=Nag_ColMajor;
  • x[(i-1)×ip+j-1] when order=Nag_RowMajor.
On exit: the first num rows contain the values of the covariates for the members of the risk sets.
16: mxn Integer Input
On entry: the first dimension of the array x and the dimension of the arrays ixs and id.
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 fail.code= NE_INT.
17: id[mxn] Integer Output
On exit: indicates if the member of the risk set given in x failed.
id[i-1]=1 if the member of the risk set failed at the time defining the risk set and id[i-1]=0 otherwise.
18: nd Integer * Output
On exit: the number of distinct failure times, i.e., the number of risk sets.
19: tp[n] double Output
On exit: tp[i-1] contains the ith distinct failure time, for i=1,2,,nd.
20: irs[n] Integer 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 tp[0] is given by rows 1 to irs[0]. The lth risk set is given by rows irs[l-2]+1 to irs[l-1], for l=1,2,,nd.
21: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, i=value and ic[i-1]=value.
Constraint: ic[i-1]=0 or 1.
On entry, i=value, isi[i-1]=value and ns=value.
Constraint: 0isi[i-1]ns.
On entry, i=value and isz[i-1]=value.
Constraint: isz[j-1]0.
On entry, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n2.
On entry, ns=value.
Constraint: ns0.
On entry, pdz=value.
Constraint: pdz>0.
NE_INT_2
On entry, pdz=value and m=value.
Constraint: pdzm.
NE_INT_ARRAY_ELEM_CONS
On entry, mxn=value and minimum value for mxn=value.
Constraint: mxn must be sufficiently large for the arrays to contain the expanded risk set.
On entry, there are not ip values of isz>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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g12zac is not threaded in any implementation.

9 Further Comments

When there are strata present, i.e., ns>1, not all the nxs groups may be present.

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

10.1 Program Text

Program Text (g12zace.c)

10.2 Program Data

Program Data (g12zace.d)

10.3 Program Results

Program Results (g12zace.r)