Categories &

Functions List

Function Reference: fitcox

statistics: mdl = fitcox (X, T)
statistics: mdl = fitcox (tbl, respvar)
statistics: mdl = fitcox (…, Name, Value)

Fit a Cox proportional hazards regression model.

mdl = fitcox (X, T) fits the Cox proportional hazards model

$$ h(x_i, t) = h_0(t)\exp\left(\sum_{j=1}^{p} x_{ij} b_j\right) $$

to the n-by-p numeric matrix of predictors X and the n-by-1 vector of event times T, and returns a CoxModel object. T may instead be an n-by-2 matrix whose rows give a (start, stop] interval of exposure, the counting process form, in which an observation joins the risk set only after its start time.

h_0(t) is the baseline hazard, which is left unspecified: the coefficients are estimated by maximizing the Cox partial likelihood, which does not involve it. X must not contain a column of ones, the model having no constant term, since any constant is absorbed into that baseline.

mdl = fitcox (tbl, respvar) takes the data from the table tbl, using the variable named respvar as the response and every other variable as a predictor. A categorical variable is encoded as indicator columns, one per level bar the first, which the baseline hazard carries.

The following Name/Value pairs are accepted:

NameValue
"Baseline"The X values at which the baseline hazard is computed, either a scalar or a 1-by-p vector. The default is the mean of each numeric predictor and zero for each indicator column of a categorical predictor, taken within each stratum. Pass 0 for a hazard relative to the origin. The coefficients do not depend on this choice.
"Beta"The starting value of the iteration, a vector of length p. The default is 0.01 ./ std (X).
"CategoricalPredictors"The predictors to treat as categorical, given as column indices, a logical vector, or a cell array of predictor names. Table variables of class categorical are detected without this argument.
"Censoring"A logical or 0/1 vector of length n, where 1 marks an observation right-censored at its recorded time. The default is a vector of zeros, so every observation is a recorded event.
"Frequency"A vector of length n of non-negative values giving the number of observations each row represents, or a weight. The default is a vector of ones.
"OptimizationOptions"A structure of iteration settings, as built by statset ("fitcox"). The fields used are "MaxIter", "TolX" and "Display".
"PredictorNames"A cell array of p predictor names. The default is "X1", "X2", and so on, or the table variable names.
"Stratification"A vector of length n of stratum labels. Each stratum carries its own baseline hazard and its own risk sets, while the coefficients are shared across all of them.
"TieBreakMethod"The method of handling tied event times, either "breslow" (default) or "efron".

Source Code: fitcox

fitcox is the object interface to coxphfit, which fits the same model and returns the estimates as plain arrays. The two agree exactly; the object additionally reports the proportional hazards assumption tests and carries the survival, hazardratio, coefci, linhyptest and plotSurvival methods.

See also: CoxModel, coxphfit, ecdf, statset

Source Code: fitcox

Fit a Cox proportional hazards model to right-censored survival times

 X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1];
 T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30];
 C = [0; 0; 1; 0; 0; 1; 0; 0; 1; 0];
 mdl = fitcox (X, T, 'Censoring', C)
mdl =

  Cox proportional hazards regression model:
      y ~ X1 + X2

  Coefficients:

  2x4 table

            Beta         SE        zStat      pValue      
          ________    ________    _______    _________    

    X1    -1.04228    0.518315    -2.0109    0.0443365    
    X2     3.37448     1.86042    1.81383    0.0697043    


Log-likelihood: -7.69736
Likelihood ratio test vs. constant model: p-value = 0.0485565

The hazard of each observation relative to the average one

 X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1];
 T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30];
 mdl = fitcox (X, T);
 hazardratio (mdl, X)
ans =

   2.5150e+01
   3.1202e+01
   6.2729e+00
   4.8415e-01
   1.5646e+00
   1.9411e+00
   9.7336e-02
   1.2076e-01
   3.9025e-01
   3.0120e-02

Each stratum carries its own baseline hazard

 X = [2 0; 5 1; 3 0; 8 1; 4 0; 7 1; 6 0; 9 1; 5 0; 10 1];
 T = [4; 6; 8; 11; 13; 16; 18; 21; 25; 30];
 S = [1; 1; 1; 1; 1; 2; 2; 2; 2; 2];
 mdl = fitcox (X, T, 'Stratification', S);
 mdl.Baseline
ans =

   4.4000   0.4000
   7.4000   0.6000