Estimate Cox model hazard relative to baseline
returns the estimated hazard relative to the baseline using the predictors
hazard = hazardratio(
X and stratification levels
number of rows in
Stratification must be the
When you train
coxMdl using stratification variables and
pass predictor variables
hazardratio also requires you to pass
Compute Relative Hazard
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.
Compute Hazard Relative to Different Baseline Values
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
Hazard Ratios for Stratified Model
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).
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
X — Data for estimating hazard
matrix | table
Data for estimating the hazard, specified as a matrix or table. The data must be the
same type as the data used to train
Stratification — Stratification level
variable or variables of type used for training
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
baseline — Baseline hazard
coxMdl (default) | real scalar | real row vector
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.
[1 20 100]
hazard — Hazard ratio relative to baseline
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
Introduced in R2021a