%Generate Weibull data depending on predictor x:x = 4*rand(100,1);
A = 50*exp(-0.5*x); B = 2;
y = wblrnd(A,B);
%Fit a Cox model :
[b,logL,H,stats] = coxphfit(x,y);
%Show the Cox estimate of the baseline survivor function together with
%the known Weibull function:
stairs(H(:,1),exp(-H(:,2)))
xx = linspace(0,100);
line(xx,1-wblcdf(xx,50*exp(-0.5*mean(x)),B),'color','r')
xlim([0,50])
title(sprintf('Baseline survivor function for X = %g',mean(x)));
legend('Survivor Function','Weibull Function')