Main Content

hazardratio

Estimate Cox model hazard relative to baseline

Since R2021a

Description

hazard = hazardratio(coxMdl,X) returns the estimated hazard relative to the baseline for a fitted Cox proportional hazards model coxMdl using the predictors X.

example

hazard = hazardratio(coxMdl,X,Stratification) returns the estimated hazard relative to the baseline using the predictors X and stratification levels Stratification. The number of rows in X and Stratification must be the same.

Note

When you train coxMdl using stratification variables and pass predictor variables X, hazardratio also requires you to pass stratification variables.

example

hazard = hazardratio(___,'Baseline',baseline) estimates the hazard relative to the supplied baseline using any of the input argument combinations in the previous syntaxes.

example

Examples

collapse all

Perform a Cox proportional hazards regression on the lightbulb data set, which contains simulated lifetimes of light bulbs. The first column of the light bulb data contains the lifetime (in hours) of two different types of bulbs. The second column contains a binary variable indicating whether the bulb is fluorescent or incandescent; 0 indicates the bulb is fluorescent, and 1 indicates it is incandescent. The third column contains the censoring information, where 0 indicates the bulb was observed until failure, and 1 indicates the observation was censored.

Fit a Cox proportional hazards model for the lifetime of the light bulbs, accounting for censoring. The predictor variable is the type of bulb.

load lightbulb
coxMdl = fitcox(lightbulb(:,2),lightbulb(:,1), ...
    'Censoring',lightbulb(:,3));

View the default baseline for the fitted model.

defaultBaseline = coxMdl.Baseline
defaultBaseline = 
0.5000

Compute the hazard ratio of an incandescent bulb (1) relative to this baseline.

defaultHazard = hazardratio(coxMdl,1)
defaultHazard = 
10.6238

Compute the hazard ratio of an incandescent bulb relative to a fluorescent bulb (0).

relHazard = hazardratio(coxMdl,1,'Baseline',0)
relHazard = 
112.8646

The hazard rate of an incandescent bulb is estimated to be over 100 times the hazard rate of a fluorescent bulb.

Create a Cox model from the readmissiontimes data. In this data, 0 indicates a male patient, and 1 indicates a female patient.

load readmissiontimes
coxMdl = fitcox([Age,Sex,Weight],ReadmissionTime,'Censoring',Censored);

Calculate the relative hazard of a 40-year-old man weighing 200 lbs. relative to the baseline hazard.

hazard = hazardratio(coxMdl,[40 0 200])
hazard = 
4.3112

Calculate the hazard of this same man relative to a 50-year-old woman weighing 150 lbs.

hazard2 = hazardratio(coxMdl,[40 0 200],'Baseline',[50 1 150])
hazard2 = 
5.2053

Load the coxModel data. (This simulated data is generated in the example Cox Proportional Hazards Model Object.) The model named coxMdl has three stratification levels (1, 2, and 3) and a predictor X with three categorical values (1, 1/20, and 1/100).

load coxModel

Find the hazard ratio of the predictor value categorical(1) and stratification level 3 with respect to the baseline.

X = categorical(1);
stratification = 3;
hazard = hazardratio(coxMdl,X,stratification)
hazard = 
12.7096

Calculate the ratio with respect to a baseline of 0.

hazard = hazardratio(coxMdl,X,stratification,'Baseline',0)
hazard = 
95.5127

Calculate the ratio of a categorical(1/100) predictor with respect to a baseline of 0.

X = categorical(1/100);
hazard = hazardratio(coxMdl,X,stratification,'Baseline',0)
hazard = 
1

Input Arguments

collapse all

Fitted Cox proportional hazards model, specified as a CoxModel object. Create coxMdl using fitcox.

Data for estimating the hazard, specified as a matrix or table. The data must be the same type as the data used to train coxMdl.

Data Types: double | table | categorical

Stratification level, specified as a variable or variables of the same type used for training coxMdl. Specify the same number of rows in Stratification as in X.

Data Types: single | double | logical | char | string | table | cell | categorical

Baseline hazard, specified as a real scalar or row vector.

  • A scalar value applies to all predictors.

  • A row vector value must have the same number of entries as the number of predictors.

The returned hazard ratio is relative to the baseline.

Example: [1 20 100]

Data Types: single | double

Output Arguments

collapse all

Hazard ratio relative to the baseline, returned as a nonnegative vector. hazard gives the factor by which to multiply the baseline hazard, so you can obtain the relative hazard of an individual with predictor values X and, if applicable, stratification level Stratification.

Version History

Introduced in R2021a