WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

CoxModelFit [{e1,,en}]

constructs a model of the baseline hazard for events times ei.

CoxModelFit [{{{ξ11,,ξ1p},,{ξn1,,ξnp}},{e1,,en}},{f1,,fm},{x1,,xp}]

constructs a Cox model of the form , where the fi depend on the xk.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Basic Uses  
Model Specification  
Parameter Estimates and Model Diagnostics  
Survival Estimates and Confidence Measures  
Options  
ConfidenceLevel  
ConfidenceRange  
ConfidenceTransform  
Show More Show More
Method  
NominalVariables  
StrataVariables  
WorkingPrecision  
Applications  
Ear Mite Treatment  
Larynx Cancer  
Acute Leukemia  
Properties & Relations  
See Also
Related Guides
History
Cite this Page

CoxModelFit [{e1,,en}]

constructs a model of the baseline hazard for events times ei.

CoxModelFit [{{{ξ11,,ξ1p},,{ξn1,,ξnp}},{e1,,en}},{f1,,fm},{x1,,xp}]

constructs a Cox model of the form , where the fi depend on the xk.

Details and Options

  • CoxModelFit is used in survival, reliability, and duration analysis. It quantifies relative survival risk and estimates an underlying baseline hazard.
  • CoxModelFit returns a symbolic CoxModel object to represent the proportional hazards model it constructs. The properties and diagnostics of the model can be obtained from model["property"].
  • A list of available model properties can be obtained using model["Properties"].
  • The form of events ei follows the form used in EventData .
  • CoxModelFit produces a conditional hazard function proportional to the baseline hazard function .
  • The model is semiparametric, with parameters found by maximizing a partial likelihood. The baseline hazard is estimated using nonparametric methods.
  • A null model that only estimates can be specified using CoxModelFit [e], which is equivalent to CoxModelFit [{ξ,e},{},{x1,,xp}].
  • Constant values specified in the basis functions fi are ignored in the fitting and absorbed in the estimation of the baseline hazard .
  • The following tables of properties pertain to the estimates, diagnostics, and testing of the parametric components of the model. »
  • Properties related to data and the fitted function obtained using model["property"] include:
  • "BaselineList" list containing baseline covariate levels for each stratum
    "BasisFunctions" list of basis functions
    "BestFitParameters" parameter estimates
    "Data" the matrix of covariate input data
    "EventData" the event input data
    "RelativeRisk" relative risk for the model parameters
    "StrataModels" list containing submodels for each stratum
    "StrataSummary" list containing name and count pairings for each stratum
  • Properties that measure goodness of fit include:
  • "AIC" Akaike information criterion
    "BIC" SchwartzBayes information criterion
    "LogLikelihood" model log likelihood
    "MaxRSquared" maximum possible coefficient
    "RSquared" pseudo coefficient of determination
  • Types of residuals and influence measures:
  • "BetaDifferences" DFBETAs measure of influence on parameter values
    "CoxSnellResiduals" CoxSnell type residuals
    "DevianceResiduals" scaled Martingale residuals
    "MartingaleResiduals" estimate of the excess number of events over time
    "ScaledBetaDifferences" DFBETAs computed using the model standard deviation
    "SchoenfeldResiduals" Schoenfeld-type residuals
    "ScoreResiduals" score residuals
  • Properties and diagnostics for parameter estimates include:
  • "CovarianceMatrix" covariance estimate for model parameters
    "InformationMatrix" information matrix for model parameters
    "LikelihoodRatioStatistic" likelihood ratio of fitted model to the null model
    "ParameterConfidenceIntervals" confidence intervals about the parameter estimates
    "ParameterStandardErrors" standard errors of model parameters
    "ParameterTable" table of fitted parameter information
    "ParameterTableEntries" entries in the parameter table
    "RelativeRiskConfidenceIntervals" confidence intervals about relative risk estimates
    "RiskScores" risk scores for each observation
    "ScoreStatistic" score statistic comparing fitted and null models
    "TestTable" table of significance information for model parameters
    "TestTableEntries" entries from the test table
    "TestTableEntriesFunction" entries from table created with test table function
    "TestTableFunction" creates a test table under a specified null hypothesis
    "WaldStatistic" Wald statistic comparing fitted and null models
  • As in SurvivalModelFit , it is possible to obtain information about the nonparametric component of the model , including estimates of survival probabilities, survival confidence intervals, and moment estimates. »
  • CoxModelFit has all of the properties available to SurvivalModelFit .
  • Properties related to are specified as in SurvivalModelFit , but additionally require that the covariate level x0 be given as model["property"][x0].
  • Different functional forms of the hazard rate for covariate levels x0 can be obtained by specifying the form h in model[h][x0]. The following forms can be used.
  • "CDF" cumulative distribution function
    "CHF" cumulative hazard function
    "SF" survival function
  • The value of the fitted function h from CoxModelFit at a particular point t and covariate levels x0 can be found from model[h][x0][t]. model[h][][t] gives the form h of the baseline hazard h0[t].
  • Specifying Normal [model] gives a pure function form of model["SF"][][t].
  • CoxModelFit takes the following options:
  • ConfidenceLevel 95/100 level to use for intervals and bands
    ConfidenceRange All range for simultaneous confidence bands
    ConfidenceTransform "LogLog" confidence transform to use
    Method Automatic method to use for model fitting
    NominalVariables None variables considered as categorical
    StrataVariables None variables considered as strata
    WorkingPrecision Automatic precision used in internal computations
  • With ConfidenceLevel ->p, probability-p confidence intervals and bands are computed for the various functional forms and parameter estimates.
  • ConfidenceRange ->{tmin,tmax} gives probability-p simultaneous confidence intervals and bands for the fitted function between tmin and tmax.
  • Possible settings for ConfidenceTransform include "Linear", "LogLog", "ArcSinSqrt", "Log", "Logit", or a pure function g.
  • The setting Method ->m specifies the method for handling ties. Possible settings include the following.
  • "Breslow" use Breslow's partial likelihood
    "Efron" use Efron's partial likelihood
    "Exact" use the exact marginal likelihood
  • By default, the "Breslow" method is used for handling ties.
  • Additional method settings can be found in the options section of examples. »

Examples

open all close all

Basic Examples  (2)

Fit a Cox proportional hazards model to some data with right-censored event times:

Wolfram Language code: ξ = {2, 0, 0, 1, 1, 1, 3, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0}; e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, x, x]

Visualize the survival estimates at each covariate level:

Wolfram Language code: Plot[Evaluate@Table[𝒮["SF"][{x}][t], {x, r = {0, 1, 2, 3}}], {t, 0, 35}, PlotPoints -> 75, Exclusions -> None, PlotLegends -> (Row[{"x = ", #}]& /@ r)]

Compute fit diagnostics for a fitted Cox model:

Wolfram Language code: e = EventData[{1, 2, 3, 4}, {0, 0, 1, 0}];
Wolfram Language code: 𝒮 = CoxModelFit[{{2, 1, 3, 1}, e}, x, x]

Summarize parameter estimates:

Wolfram Language code: 𝒮["ParameterTable"]

Test overall model significance:

Wolfram Language code: 𝒮["TestTable"]

Scope  (26)

Basic Uses  (8)

Estimate and test parameters in a Cox proportional hazards model:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

The parameter estimates for and both differ significantly from zero at the 5% level:

Wolfram Language code: 𝒮["ParameterTable"]

Compare the fitted model to the null model, containing no covariates:

Wolfram Language code: 𝒮["TestTable"]

Form 95% confidence intervals about relative risk and parameter estimates:

Wolfram Language code: 𝒮["RelativeRiskConfidenceIntervals"]
Wolfram Language code: 𝒮["ParameterConfidenceIntervals"]

Find survival probabilities and plot model estimates:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Compare survival for different levels of with fixed at 25 with the baseline survival:

Wolfram Language code: Plot[Evaluate@{𝒮["SF"][{25, 0}][t], 𝒮["SF"][{25, 1}][t], 𝒮["SF"][][t]}, {t, 0, 35}, Exclusions -> None, PlotPoints -> 100, PlotLegends -> {"SubscriptBox[x, 2] = 0", "SubscriptBox[x, 2] = 1", "baseline"}]

Compute the median survival time for both levels of with fixed at 25:

Wolfram Language code: 𝒮["MedianSurvival"][#]& /@ {{25, 0}, {25, 1}}

The baseline median survival:

Wolfram Language code: 𝒮["MedianSurvival"][]

The probability that an individual with levels and will survive beyond 20:

Wolfram Language code: 𝒮["SF"][{30, 0}][20]

A 95% confidence interval for the same probability:

Wolfram Language code: 𝒮["PointwiseBands", "SF"][{30, 0}][20]

Fit a stratified model:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮S = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1]}, {Subscript[x, 1], Subscript[x, 2]}, StrataVariables -> Subscript[x, 2]];

The number of observations in each stratum:

Wolfram Language code: 𝒮S["StrataSummary"]

Plot different forms of the hazard for levels and :

Wolfram Language code: Table[Plot[𝒮S[i][{60, 1}][t], {t, 0, 20}, PlotLabel -> i, Exclusions -> None], {i, {"SF", "CDF", "CHF"}}]

The model parameter table:

Wolfram Language code: 𝒮S["ParameterTable"]

Fit a model with categorical predictor variables:

Wolfram Language code: ξ = {{67, "Orange"}, {11, "Blue"}, {32, "Blue"}, {50, "Orange"}, {65, "Orange"}, {44, "Orange"}, {20, "Orange"}, {26, "Blue"}, {69, "Orange"}, {50, "Orange"}, {25, "Orange"}, {18, "Blue"}, {63, "Orange"}, {41, "Blue"}, {30, "Blue"}, {32, "Orange"}, {46, "Orange"}, {35, "Blue"}, {33, "Blue"}, {22, "Blue"}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, NominalVariables -> Subscript[x, 2]];
Wolfram Language code: 𝒮["ParameterTable"]

Plots of the estimated CDFs for each level in the data:

Wolfram Language code: color["Orange"] = StandardOrange; color["Blue"] = StandardBlue;
Wolfram Language code: Show@Table[Plot[Evaluate[𝒮["SF"][i][t]], {t, 0, 35}, PlotStyle -> color[i[[2]]], PlotRange -> All, AxesOrigin -> {0, 0}], {i, 𝒮["Data"]}]

Add interaction terms to the model:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 1]Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

No significant interaction is detected in the model:

Wolfram Language code: 𝒮["ParameterTable"]

Nominal and strata variables can be used in interaction terms:

Wolfram Language code: 𝒮N = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 1]Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, NominalVariables -> Subscript[x, 2]]; 𝒮S = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 1]Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, StrataVariables -> Subscript[x, 2]];
Wolfram Language code: 𝒮N["ParameterTable"]
Wolfram Language code: 𝒮S["ParameterTable"]

Test model parameters against specific null hypotheses:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Test :

Wolfram Language code: Subscript[β, 0] = {0, 0};
Wolfram Language code: 𝒮["TestTableFunction"][Subscript[β, 0]]

Test with the second parameter free:

Wolfram Language code: Subscript[β, 0] = {0.1, b};
Wolfram Language code: 𝒮["TestTableFunction"][Subscript[β, 0]]

Use a contrast matrix to test a linear combination of the parameters:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Test the following null hypothesis:

Wolfram Language code: c = {{1, 1}};Subscript[β, 0] = {0, 2};
Wolfram Language code: Total[c.{Subscript[β, 1], Subscript[β, 2]}] == Total[c.Subscript[β, 0]]
Wolfram Language code: 𝒮["TestTableFunction"][c, Subscript[β, 0]]

Specifying only a contrast matrix tests a hypothesis of the following form:

Wolfram Language code: 𝒮["BestFitParameters"]
Wolfram Language code: Total[c.{Subscript[β, 1], Subscript[β, 2]}] == Total[c.{0, 0}]
Wolfram Language code: 𝒮["TestTableFunction"][c]

Show the list of available properties for a model:

Wolfram Language code: 𝒮 = CoxModelFit[{1, 2, 3}];
Wolfram Language code: 𝒮["Properties"]

Model Specification  (4)

Create a model with no covariates (null model):

Wolfram Language code: e = RandomVariate[WeibullDistribution[1, 2], 100];
Wolfram Language code: 𝒮 = CoxModelFit[e];

The model is simply an estimate of the baseline survival:

Wolfram Language code: Plot[Evaluate@𝒮[t], {t, 0, 10}, Exclusions -> None]

An equivalent null model:

Wolfram Language code: ξ = RandomChoice[{0, 1}, {100, 3}];
Wolfram Language code: 𝒮2 = CoxModelFit[{ξ, e}, {}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]}];
Wolfram Language code: 𝒮[t] === 𝒮2[t]

Basis functions specify which of the available variables should be included in the model:

Wolfram Language code: ξ = RandomVariate[NormalDistribution[], {100, 4}]; e = RandomVariate[ExponentialDistribution[1 / 30], 100];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}];

Parameter estimates corresponding to each of the four covariates:

Wolfram Language code: 𝒮["ParameterTable"]

Not all variables must be used in the basis functions:

Wolfram Language code: 𝒮2 = CoxModelFit[{ξ, e}, {Subscript[x, 2], Subscript[x, 3]}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}];
Wolfram Language code: 𝒮2["ParameterTable"]

Basis functions also control the functional form of model terms:

Wolfram Language code: ξ = RandomVariate[NormalDistribution[], {100, 4}]; e = RandomVariate[ExponentialDistribution[1 / 30], 100];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {2Subscript[x, 1], Exp[Subscript[x, 2]], Subscript[x, 3] + Subscript[x, 4]}, {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4]}];

Parameter estimates for the terms in the model:

Wolfram Language code: 𝒮["ParameterTable"]

Use EventData to specify right-censored or left-truncated response times:

Wolfram Language code: t = RandomVariate[WeibullDistribution[1, 2], 100]; c = RandomChoice[{0, 1}, 100]; ξ = RandomVariate[NormalDistribution[], {100, 2}];

A Cox model with randomly right-censored response:

Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[t, c]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];
Wolfram Language code: 𝒮["ParameterTable"]

Parameter Estimates and Model Diagnostics  (6)

Obtain parameter estimates and parameter confidence intervals:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

The model parameters and relative risk estimates :

Wolfram Language code: 𝒮["BestFitParameters"]
Wolfram Language code: 𝒮["RelativeRisk"]

Confidence intervals about the parameter estimates:

Wolfram Language code: 𝒮["ParameterConfidenceIntervals"]
Wolfram Language code: 𝒮["RelativeRiskConfidenceIntervals"]

Parameter summary tables:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];
Wolfram Language code: 𝒮["ParameterTable"]

Entries from the parameter table:

Wolfram Language code: 𝒮["ParameterTableEntries"]

Obtain a variety of model residuals:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Martingale, CoxSnell, and deviance residuals:

Wolfram Language code: Table[ListPlot[𝒮[i], Filling -> Axis, PlotLabel -> i], {i, {"MartingaleResiduals", "CoxSnellResiduals", "DevianceResiduals"}}]

DFBETAs and scaled DFBETAS:

Wolfram Language code: Table[ListPlot[Transpose@𝒮[i], Filling -> Axis, PlotLabel -> i], {i, {"BetaDifferences", "ScaledBetaDifferences"}}]

Score and Schoenfeld residuals:

Wolfram Language code: Table[ListPlot[Transpose@𝒮[i], Filling -> Axis, PlotLabel -> i], {i, {"ScoreResiduals", "SchoenfeldResiduals"}}]

Compute a selection of goodness-of-fit measures:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];
Wolfram Language code: prop = {"AIC", "BIC", "LogLikelihood", "RSquared", "MaxRSquared"};
Wolfram Language code: Grid[{prop, 𝒮[prop]}, Alignment -> {{Left, "."}}]

Perform global hypothesis tests:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Three tests of global model significance:

Wolfram Language code: 𝒮["TestTable"]

Entries from the test table:

Wolfram Language code: 𝒮["TestTableEntries"]

Individual test statistics:

Wolfram Language code: 𝒮[{"LikelihoodRatioStatistic", "WaldStatistic", "ScoreStatistic"}]

Test local hypotheses:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Test whether :

Wolfram Language code: 𝒮["TestTableFunction"][{0, Subscript[x, 2]}]

Entries from the test table:

Wolfram Language code: 𝒮["TestTableEntriesFunction"][{0, Subscript[x, 2]}]

Survival Estimates and Confidence Measures  (8)

Compute estimates of the SurvivalFunction , CDF , or cumulative hazard function:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

The estimated SurvivalFunction for covariate levels and :

Wolfram Language code: 𝒮["SF"][{60, 1}][t]//PiecewiseExpand

The estimated baseline SurvivalFunction , CDF , and cumulative hazard at time :

Wolfram Language code: 𝒮["SF"][][12]
Wolfram Language code: 𝒮["CDF"][][12]
Wolfram Language code: 𝒮["CHF"][][12]

Tabulate a summary of the estimated SurvivalFunction :

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

A survival summary for covariate levels and :

Wolfram Language code: 𝒮["FullEventTable", "SF"][{60, 1}]

Entries form the table:

Wolfram Language code: 𝒮["FullEventTableEntries", "SF"][{60, 1}]

Properties of distribution function estimates default to "SF":

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];
Wolfram Language code: 𝒮["EventTable"][{60, 1}] === 𝒮["EventTable", "SF"][{60, 1}]

Tabulate the cumulative hazard function:

Wolfram Language code: 𝒮["EventTable", "CHF"][{60, 1}]

Compute pointwise confidence bands and intervals:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

A set of pointwise survival confidence intervals for covariate levels and :

Wolfram Language code: pwi = 𝒮["PointwiseIntervals"][{50, 1 / 2}]

These are "PointwiseBands" evaluated at the model "EstimationPoints":

Wolfram Language code: pwi == 𝒮["PointwiseBands"][{50, 1 / 2}][𝒮["EstimationPoints"]]

Estimate simultaneous confidence bands and intervals:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

A set of HallWellner simultaneous confidence intervals for covariate levels and :

Wolfram Language code: hwi = 𝒮["HallWellnerIntervals"][{35, 1}]

These are "HallWellnerBands" evaluated at the model "EstimationPoints":

Wolfram Language code: hwi == 𝒮["HallWellnerBands"][{35, 1}][𝒮["EstimationPoints"]]

Alternatively, use "EqualPrecisionIntervals" to measure simultaneous confidence:

Wolfram Language code: epi = 𝒮["EqualPrecisionIntervals"][{35, 1}]
Wolfram Language code: epi == 𝒮["EqualPrecisionBands"][{35, 1}][𝒮["EstimationPoints"]]

Plot survival estimates and confidence bands:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Plots of baseline survival and cumulative hazard with 95% pointwise confidence bands:

Wolfram Language code: Table[Plot[Evaluate@{𝒮[i][][t], 𝒮["PointwiseBands", i][][t]}, {t, 0, 35}, PlotPoints -> 100, PlotLabel -> i], {i, {"SF", "CHF"}}]

The same plots for covariate levels and :

Wolfram Language code: Table[Plot[Evaluate@{𝒮[i][{60, 1}][t], 𝒮["PointwiseBands", i][{60, 1}][t]}, {t, 0, 35}, PlotPoints -> 100, PlotLabel -> i], {i, {"SF", "CHF"}}]

Estimate median survival times:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

The median survival time for covariate levels and and at the baseline:

Wolfram Language code: {𝒮["MedianSurvival"][{60, 1}], 𝒮["MedianSurvival"][]}

Estimate mean survival times:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

The survival function does not reach zero due to right censoring; the mean is not well defined:

Wolfram Language code: Plot[𝒮["SF"][{60, 1}][t], {t, 0, 40}, PlotRange -> {0, 1}, Exclusions -> None]
Wolfram Language code: {𝒮["MeanSurvival"][{60, 1}], 𝒮["MeanSurvival"][]}

Adding a model for the remaining probability allows the mean to be estimated:

Wolfram Language code: 𝒮2 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {Automatic, "TailModel" -> "Censored"}];
Wolfram Language code: Plot[𝒮2["SF"][{60, 1}][t], {t, 0, 40}, PlotRange -> {0, 1}, Exclusions -> None]
Wolfram Language code: {𝒮2["MeanSurvival"][{60, 1}], 𝒮2["MeanSurvival"][]}

Options  (13)

ConfidenceLevel  (3)

Change the confidence level for parameter confidence intervals:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}}; e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];

Use a 90% confidence level:

Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, ConfidenceLevel -> .9];
Wolfram Language code: 𝒮["ParameterConfidenceIntervals"]

The level can be changed after fitting:

Wolfram Language code: Table[𝒮["ParameterConfidenceIntervals", ConfidenceLevel -> i], {i, {.85, .9, .95}}]

Plot survival estimates with 90% confidence bands:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}}; e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, ConfidenceLevel -> .9];

Plots of baseline survival with 90% pointwise confidence bands:

Wolfram Language code: Table[Plot[Evaluate@{𝒮[i][][t], 𝒮["PointwiseBands", i][][t]}, {t, 0, 35}, PlotPoints -> 100, PlotLabel -> i], {i, {"SF", "CDF", "CHF"}}]

The level can be changed after fitting:

Wolfram Language code: 𝒮["PointwiseBands"][][6]
Wolfram Language code: 𝒮["PointwiseBands", ConfidenceLevel -> .95][][6]

The setting for ConfidenceLevel is also used in summary tables:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];

Summarize the cumulative hazard function with 90% confidence limits:

Wolfram Language code: 𝒮["EventTable", "CHF", ConfidenceLevel -> .9][{50, 1}]

ConfidenceRange  (1)

Set the confidence range for simultaneous intervals and bands:

Wolfram Language code: 𝒮 = CoxModelFit[EventData[Automatic, {{{2081, Infinity}, {1602, Infinity}, {1496, Infinity}, {1462, Infinity}, {1433, Infinity}, {1377, Infinity}, {1330, Infinity}, {996, Infinity}, {226, Infinity}, {1199, Infinity}, {1111, Infinity}, {530, Infinity}, {1182, Infinity}, {1167, Infinity}, 418, 383, 276, 104, 609, 172, 487, 662, 194, 230, 526, 122, 129, 74, 122, 86, 466, 192, 109, 55, 1, 107, 110, 332}, None, None}]];

The bands are only defined over the confidence range:

Wolfram Language code: Plot[Evaluate@{𝒮["SF"][][x], 𝒮["EqualPrecisionBands", ConfidenceRange -> {172, 383}][][x]}, {x, 100, 500}, PlotRange -> {0, 1}]

By default the range is set to All :

Wolfram Language code: Plot[Evaluate@{𝒮["SF"][][x], 𝒮["EqualPrecisionBands", ConfidenceRange -> All][][x]}, {x, 0, 2081}, PlotRange -> {0, 1}]

Set the range to Full :

Wolfram Language code: Plot[Evaluate@{𝒮["SF"][][x], 𝒮["EqualPrecisionBands", ConfidenceRange -> Full][][x]}, {x, 0, 2081}, PlotRange -> {0, 1}]

ConfidenceTransform  (3)

Apply transformations to confidence intervals and bands:

Wolfram Language code: ξ = {1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}]}, x, x];

A collection of available transforms:

Wolfram Language code: tr = {"Linear", "LogLog", "ArcSinSqrt", "Log", "Logit"};
Wolfram Language code: Table[{i, 𝒮["PointwiseBands", ConfidenceTransform -> i][{0}][15]}, {i, tr}]//Grid

"LogLog" bands and intervals are used by default:

Wolfram Language code: 𝒮["PointwiseBands", ConfidenceTransform -> "LogLog"][{0}][15]
Wolfram Language code: 𝒮["PointwiseBands"][{0}][15]

Transformations can ensure that intervals and bands are appropriately bounded:

Wolfram Language code: 𝒮 = CoxModelFit[EventData[Automatic, {{30, 32, 26, {37, Infinity}, 29, {32, Infinity}, 24, {31, Infinity}, {31, Infinity}, 42}, None, None}]];

Notice that linear confidence limits may exceed 1. or be less than zero:

Wolfram Language code: 𝒮["EventTable", ConfidenceTransform -> "Linear"][]

Using a "LogLog" transform corrects this issue:

Wolfram Language code: 𝒮["EventTable", ConfidenceTransform -> "LogLog"][]

Define custom transformations:

Wolfram Language code: 𝒮 = CoxModelFit[EventData[Automatic, {{30, 32, 26, {37, Infinity}, 29, {32, Infinity}, 24, {31, Infinity}, {31, Infinity}, 42}, None, None}]];

Explicit definitions for the various named transforms:

Wolfram Language code: tr = {"Linear", "LogLog", "ArcSinSqrt", "Log", "Logit"}; trans = {#&, Log[Log[#]]&, ArcSin[Sqrt[#]]&, Log[#]&, Log[(#/1 - #)]&};
Wolfram Language code: MapThread[{#1, 𝒮["PointwiseBands", ConfidenceTransform -> #2][][40]}&, {tr, trans}]//Grid

Method  (3)

Select the method used for handling tied event times:

Wolfram Language code: ξ = {1, 1, 1, 0, 0, 0}; e = EventData[{1, 1, 6, 6, 8, 9}, {0, 1, 0, 0, 1, 0}];

The default method maximizes Breslow's partial likelihood:

Wolfram Language code: efron = CoxModelFit[{ξ, e}, Subscript[x, 1], Subscript[x, 1], Method -> "Efron"]; breslow = CoxModelFit[{ξ, e}, Subscript[x, 1], Subscript[x, 1], Method -> "Breslow"]; exact = CoxModelFit[{ξ, e}, Subscript[x, 1], Subscript[x, 1], Method -> "Exact"];

When the proportion of ties is high, the estimates may differ considerably:

Wolfram Language code: #["BestFitParameters"]& /@ {efron, breslow, exact}

In the absence of tied event times, all of the methods are equivalent:

Wolfram Language code: e2 = EventData[{1, 5, 3, 4, 2, 6}];
Wolfram Language code: Equal@@Table[CoxModelFit[{ξ, e2}, Subscript[x, 1], Subscript[x, 1], Method -> i]["BestFitParameters"], {i, {"Efron", "Breslow", "Exact"}}]

Choose an estimator for the baseline hazard:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];

By default, the baseline hazard estimator is matched to the tie method:

Wolfram Language code: efron = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Efron", "BaselineHazardMethod" -> "Efron"}];
Wolfram Language code: breslow = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Breslow", "BaselineHazardMethod" -> "BreslowNelsonAalen"}];
Wolfram Language code: exact = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Exact", "BaselineHazardMethod" -> "KalbfleischPrentice"}];

The estimators generally agree closely:

Wolfram Language code: Plot[Evaluate@Table[i["SF"][][t], {i, {efron, breslow, exact}}], {t, 0, 35}, PlotPoints -> 75, Exclusions -> None, PlotLegends -> {"efron", "breslow", "exact"}]

Any combination of tie and baseline method can be used:

Wolfram Language code: ekp = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {"Efron", "BaselineHazardMethod" -> "KalbfleischPrentice"}];
Wolfram Language code: Plot[ekp["SF"][][t], {t, 0, 35}, Exclusions -> None, PlotPoints -> 75]

If the last observation is censored, the survival will be Indeterminate beyond that point:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: e = EventData[{1, 2, 4, 6, 6, 6, 6, 8, 8, 9, 9, 11, 12, 15, 15, 22, 25, 32, 34, 34}, {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1}];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}];
Wolfram Language code: Plot[𝒮["SF"][{60, 1}][x], {x, 0, 50}, PlotRange -> {0, 1}]

The "TailModel" suboption can control this behavior:

Wolfram Language code: tailMods = {"Censored", "Exponential", "Weibull", "Gamma", "Normal", "LogNormal", "GompertzMakeham", "InverseGaussian", "LogLogistic"};
Wolfram Language code: models = Table[CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, Method -> {Automatic, "TailModel" -> i}]["SF"][{60, 1}], {i, tailMods}]//Quiet;
Wolfram Language code: MapThread[Plot[#1[t], {t, 0, 70}, PlotLabel -> ToString@#2, Ticks -> None, Exclusions -> None, PlotRange -> {0, 1}]&, {models, tailMods}]

NominalVariables  (1)

Some hypothetical data with two categorical predictors, species and treatment:

Wolfram Language code: ξ = {{"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "yes"}, {"cat", "no"}, {"cat", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "yes"}, {"dog", "no"}, {"dog", "yes"}};
Wolfram Language code: e = EventData[Automatic, {{20, 14, 20, 92, 1, 90, 5, 11, 15, 41, 60, 4, 2, 66, 21, 3, 18, 32, 33, 36, 6, 55, 134, 7, 15}, None, None}];

Multiple nominal variables can be specified in a list:

Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {spec, treat}, {spec, treat}, NominalVariables -> {spec, treat}];

The presence of treatment appears to reduce risk significantly at the 5% level:

Wolfram Language code: 𝒮["ParameterTable"]

StrataVariables  (1)

Create a stratified Cox model for some hypothetical data with species and treatment predictors:

Wolfram Language code: ξ = {{"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "yes"}, {"cat", "no"}, {"cat", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "yes"}, {"dog", "no"}, {"dog", "yes"}};
Wolfram Language code: e = EventData[Automatic, {{20, 14, 20, 92, 1, 90, 5, 11, 15, 41, 60, 4, 2, 66, 21, 3, 18, 32, 33, 36, 6, 55, 134, 7, 15}, None, None}];

Here the treatment predictor is treated as nominal and the species as a strata variable:

Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {treat}, {spec, treat}, NominalVariables -> treat, StrataVariables -> spec];
Wolfram Language code: 𝒮["StrataSummary"]

No parameters are estimated for strata variables:

Wolfram Language code: 𝒮["ParameterTable"]

Multiple strata can be assigned using a list:

Wolfram Language code: 𝒮2 = CoxModelFit[{ξ, e}, {}, {spec, treat}, StrataVariables -> {spec, treat}];
Wolfram Language code: 𝒮2["StrataSummary"]
Wolfram Language code: 𝒮2["BaselineList"]

Baseline survival functions for each of the strata:

Wolfram Language code: Table[Plot[𝒮2["SF"][i][t], {t, 0, 50}, PlotRange -> {0, 1}, PlotLabel -> i], {i, 𝒮2["BaselineList"]}]

WorkingPrecision  (1)

Set the precision used during computation:

Wolfram Language code: ξ = {{67, 1}, {11, 0}, {32, 0}, {50, 1}, {65, 1}, {44, 1}, {20, 1}, {26, 0}, {69, 1}, {50, 1}, {25, 1}, {18, 0}, {63, 1}, {41, 0}, {30, 0}, {32, 1}, {46, 1}, {35, 0}, {33, 0}, {22, 0}};
Wolfram Language code: e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];

Use 30-digit precision:

Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}, WorkingPrecision -> 30]
Wolfram Language code: 𝒮["ParameterConfidenceIntervals"]

Applications  (5)

Ear Mite Treatment  (1)

A group of 16 dogs and 9 cats was selected to test a new treatment for ear mites. Each animal was randomly assigned to be treated with an older medication or the new drug. Determine whether the new treatment extends the time in weeks to ear mite reinfection:

Wolfram Language code: ξ = {{"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "no"}, {"dog", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"dog", "no"}, {"dog", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "no"}, {"cat", "no"}, {"dog", "yes"}, {"cat", "no"}, {"cat", "no"}, {"cat", "yes"}, {"cat", "yes"}, {"dog", "yes"}, {"dog", "no"}, {"dog", "yes"}};
Wolfram Language code: e = EventData[Automatic, {{20, 14, 20, 92, 1, 90, 5, 11, 15, 41, 60, 4, 2, 66, 21, 3, 18, 32, 33, 36, 6, 55, 134, 7, 15}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, None}];

Fit a proportional hazards model stratified on species:

Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, drug, {species, drug}, NominalVariables -> drug, StrataVariables -> species];

The new treatment seems to significantly extend the time to ear mite reinfection:

Wolfram Language code: 𝒮["ParameterTable"]

Assess the fit using a CoxSnell residual plot:

Wolfram Language code: csr = 𝒮["CoxSnellResiduals"];
Wolfram Language code: Subscript[𝒮, csr] = SurvivalModelFit[EventData[csr, 𝒮["CensoringIndicators"]], Method -> "NelsonAalen"];

The plot suggests that the model is a reasonable fit to the data:

Wolfram Language code: Show[Plot[x, {x, 0, 3}, PlotStyle -> {Dashed, Gray}], ListPlot[Transpose[{Subscript[𝒮, csr]["CHF"][csr], csr}], AspectRatio -> 1]]

Larynx Cancer  (3)

A group of 90 male patients diagnosed with cancer of the larynx was observed. Each patient was classified as having one of four stages of cancer with 1 being least severe and 4 most severe. Of interest is whether the stage of cancer is significantly linked to survival:

Wolfram Language code: larynx = ExampleData[{"Statistics", "LarynxCancer"}];
Wolfram Language code: ξ = larynx[[All, {1, 3}]]; e = EventData[larynx[[All, 2]], larynx[[All, 5]]];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {stage, age}, {stage, age}, NominalVariables -> stage];

The table gives the relative risk of dying for each stage compared to stage 1:

Wolfram Language code: 𝒮["ParameterTable"]

The risk of dying for stage 2 patients is not different from stage 1 at the 5% level:

Wolfram Language code: 𝒮["RelativeRiskConfidenceIntervals"][[2]]

Find an estimate of the relative risk of death for stage 4 larynx cancer patients compared to those with stage 2 larynx cancer:

Wolfram Language code: larynx = ExampleData[{"Statistics", "LarynxCancer"}];
Wolfram Language code: ξ = larynx[[All, {1, 3}]]; e = EventData[larynx[[All, 2]], larynx[[All, 5]]];
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, e}, {stage, age}, {stage, age}, NominalVariables -> stage];

Parameter estimates for stage 2 and stage 4 larynx cancer:

Wolfram Language code: {stg2, stg4} = 𝒮["BestFitParameters"][[{1, 3}]]
Wolfram Language code: est = Exp[stg4 - stg2]

Use the parameter covariance matrix to compute the standard error of the estimate:

Wolfram Language code: cov = 𝒮["CovarianceMatrix"];
Wolfram Language code: se = Sqrt[cov[[3, 3]] + cov[[1, 1]] - 2 cov[[1, 3]]]

At the 5% level, the risk of death is higher for stage 4 patients compared to stage 2 patients:

Wolfram Language code: α = .05;
Wolfram Language code: z = Quantile[NormalDistribution[], 1 - α / 2];
Wolfram Language code: Exp[{(stg4 - stg2) - z * se, (stg4 - stg2) + z * se}]

Visually compare the survival of 50-year-old patients in each stage:

Wolfram Language code: Plot[Evaluate@Table[𝒮["SF"][{i, 50}][t], {i, 4}], {t, 0, 12}, Exclusions -> None, PlotLegends -> (Row[{"Stage ", #}]& /@ Range[4])]

Under a null hypothesis of no trend, test whether increasing the stage of larynx cancer increases the risk of dying:

Wolfram Language code: larynx = ExampleData[{"Statistics", "LarynxCancer"}];
Wolfram Language code: y = EventData[larynx[[All, 2]], larynx[[All, 5]]]; x = larynx[[All, 1]];

Fit a Cox model stratified on stage:

Wolfram Language code: 𝒮 = CoxModelFit[{x, y}, {}, stage, StrataVariables -> stage];

LogRankTest can be used to perform a test for trend, given ordered strata:

Wolfram Language code: {z, Σ} = LogRankTest[#["Response"]& /@ 𝒮["StrataModels"], "Equal", {"TestStatisticList", "CovarianceMatrix"}];

The test statistic for trend based on the 4 levels of stage:

Wolfram Language code: p = Length[𝒮["StrataModels"]];
Wolfram Language code: t = (Underoverscript[∑, j = 1, p]j z[[j]]/Sqrt[Underoverscript[∑, j = 1, p]Underoverscript[∑, g = 1, p]j g Σ[[j, g]]])

Reject the null hypothesis of nonpositive trend. Death rate appears to increase with stage:

Wolfram Language code: NProbability[stat > t, statNormalDistribution[]]

Acute Leukemia  (1)

A sample of 101 patients with advanced acute myelogenous leukemia was recorded. Fifty-one of these patients had received an autologous bone marrow transplant and 50 patients had an allogeneic bone marrow transplant. Of interest is whether a proportional hazards model would be valid for this data:

Wolfram Language code: bone = ExampleData[{"Statistics", "BoneMarrowTransplants"}];
Wolfram Language code: y = EventData[bone[[All, 1]], bone[[All, 3]]];
Wolfram Language code: x = bone[[All, 2]];

Fit a model stratified on transplant type:

Wolfram Language code: 𝒮 = CoxModelFit[{x, y}, {}, type, StrataVariables -> type]

The log cumulative hazards cross, indicating non-proportional hazards:

Wolfram Language code: Plot[Evaluate@{Log[𝒮["CHF"][{1}][t]], Log[𝒮["CHF"][{2}][t]]}, {t, 0, 25}, AxesOrigin -> {0, -4}, Exclusions -> None]

The difference in log cumulative hazards is not constant:

Wolfram Language code: Plot[Evaluate[Log[𝒮["CHF"][{2}][t]] - Log[𝒮["CHF"][{1}][t]]], {t, 0, 25}, AxesOrigin -> {0, 0}, Exclusions -> None, PlotRange -> {-1.5, 1}]

An Anderson plot of the cumulative hazards is not linear:

Wolfram Language code: Show[Plot[x, {x, 0, 1}, PlotStyle -> {Dashed, Gray}], ListLinePlot[Evaluate@Table[{𝒮["CHF"][{1}][t], 𝒮["CHF"][{2}][t]}, {t, 𝒮["EstimationPoints"]}], InterpolationOrder -> 0]]

Properties & Relations  (4)

Relative risk is of the parameter estimates :

Wolfram Language code: ξ = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31, 29}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, None}]}, x, x];
Wolfram Language code: β = 𝒮["BestFitParameters"]

A unit increase in more than triples the risk of failure:

Wolfram Language code: rr = 𝒮["RelativeRisk"]
Wolfram Language code: Exp[β] == rr

Relative risk can be more difficult to interpret when the parameter estimates are negative:

Wolfram Language code: ξ = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[Automatic, {{32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31, 29}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, None}]}, x, x];
Wolfram Language code: 𝒮["BestFitParameters"]
Wolfram Language code: 𝒮["RelativeRisk"]

Compute absolute relative risk instead:

Wolfram Language code: Exp[Abs[𝒮["BestFitParameters"]]]

In this case the same result can be found by reversing the coding of :

Wolfram Language code: 𝒮2 = CoxModelFit[{1 - ξ, EventData[Automatic, {{32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31, 29}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}, None}]}, x, x];
Wolfram Language code: 𝒮2["RelativeRisk"]

CoxModelFit is a generalization of SurvivalModelFit :

Wolfram Language code: e = EventData[Automatic, {{8, 22, 6, 4, 12, 11, 2, 34, 25, 15, 8, 6, 34, 6, 32, 1, 15, 9, 9, 6}, {0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0}, None}];

Equivalent null models:

Wolfram Language code: mod = CoxModelFit[e]; smod = SurvivalModelFit[e, Method -> "NelsonAalen"];
Wolfram Language code: t = smod["EstimationPoints"];
Wolfram Language code: Chop[mod["SF"][][t] - smod["SF"][t]]
Wolfram Language code: mod2 = CoxModelFit[e, Method -> {Automatic, "BaselineHazardMethod" -> "KalbfleischPrentice"}]; smod2 = SurvivalModelFit[e, Method -> "KaplanMeier"];
Wolfram Language code: Chop[mod2["SF"][][t] - smod2["SF"][t]]

Use LogRankTest to compare the hazard rates of groups:

Wolfram Language code: t = {32, 34, 28, 26, 31, 25, 29, 31, 28, 25, 30, 19, 28, 35, 35, 29, 33, 32, 31, 29}; ci = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1}; ξ = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
Wolfram Language code: 𝒮 = CoxModelFit[{ξ, EventData[t, ci]}, x, x];
Wolfram Language code: Plot[{𝒮["CHF"][{0}][t], 𝒮["CHF"][{1}][t]}, {t, 18, 40}, Exclusions -> None]

A significant difference in hazard rates for the two groups is detected at the 5% level:

Wolfram Language code: LogRankTest[Table[EventData[Pick[t, ξ, i], Pick[ci, ξ, i]], {i, Union[ξ]}]]
Wolfram Research (2012), CoxModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/CoxModelFit.html.

Text

Wolfram Research (2012), CoxModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/CoxModelFit.html.

CMS

Wolfram Language. 2012. "CoxModelFit." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CoxModelFit.html.

APA

Wolfram Language. (2012). CoxModelFit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CoxModelFit.html

BibTeX

@misc{reference.wolfram_2026_coxmodelfit, author="Wolfram Research", title="{CoxModelFit}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/CoxModelFit.html}", note=[Accessed: 14-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_coxmodelfit, organization={Wolfram Research}, title={CoxModelFit}, year={2012}, url={https://reference.wolfram.com/language/ref/CoxModelFit.html}, note=[Accessed: 14-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /