MATLAB: How to use the output arguments of the COXPHFIT function in MATLAB 7.13 (R2011b) to evaluate the Cox proportional hazards model at new points

Statistics and Machine Learning Toolbox

I am using the COXPHFIT function in MATLAB 7.13 (R2011b).
I have used the COXPHFIT function in MATLAB 7.13 (R2011b) to perform a regression on a set of predictors and responses. I see from the documentation that the function returns the estimated coefficients and "H" which is a two-column matrix containing y values in the first column and the estimated baseline cumulative hazard evaluated at those values in the second column. How can I use these outputs to evaluate the Cox proportional hazards model at new points?

Best Answer

The example below illustrates the use of COXPHFIT.
Please note that the use of the STAIRS function when evaluating the model at a variety of responses in 'y'. This is because the estimated baseline cumulative hazard function (i.e., h(t) in the documentation) is not smooth. The function COXPHFIT is doing a type of maximum likelihood estimation. The likelihood is maximized if the cumulative hazard jumps at observed failure times and is flat otherwise.
% Number of observations
n = 30;
% Number of predictors
p = 5;
%Observed Data
X_observed = rand(n,p);
y_observed = rand(n,1);
%Get mean of X
Xbar = mean(X_observed);
%Get model
[b, ~, H] = coxphfit(X_observed,y_observed);
%Use model
%Make new observation
x_new = rand(1,p);
%Evaluate the model for a variety of y for this new, fixed observation
stairs( H(:,1), H(:,2) * exp((x_new - Xbar)*b));
title('Model');
%Plot estimated baseline survivor function for a variety of y
figure;
stairs( H(:,1), exp(-H(:,2)));
title('Survivor');