Generate Weibull data depending on predictor `X`.

rng('default') % for reproducibility
X = 4*rand(100,1);
A = 50*exp(-0.5*X);
B = 2;
y = wblrnd(A,B);

The response values are generated from a Weibull distribution
with a shape parameter depending on the predictor variable `X` and
a scale parameter of 2.

Fit a Cox proportional hazards model.

[b,logL,H,stats] = coxphfit(X,y);
[b logL]

ans =
0.9409 -331.1479

The coefficient estimate is 0.9409 and the log likelihood value
is –331.1479.

Request the model statistics.

stats

stats =
covb: 0.0158
beta: 0.9409
se: 0.1256
z: 7.4889
p: 6.9462e-14

The covariance matrix of the coefficient estimates, `covb`,
contains only one value, which is equal to the variance of the coefficient
estimate in this example. The coefficient estimate, `beta`,
is the same as `b` and is equal to 0.9409. The standard
error of the coefficient estimate, `se`, is 0.1256,
which is the square root of the variance 0.0158. The *z*-statistic, `z`,
is `beta/se` = 0.9409/0.1256 = 7.4880. The p-value, `p`,
indicates that the effect of `X` is significant.

Plot the Cox estimate of the baseline survivor function
together with the known Weibull function.

stairs(H(:,1),exp(-H(:,2)),'LineWidth',2)
xx = linspace(0,100);
line(xx,1-wblcdf(xx,50*exp(-0.5*mean(X)),B),'color','r','LineWidth',2)
xlim([0,50])
legend('Estimated Survivor Function','Weibull Survivor Function')

The fitted model gives a close estimate to the survivor function
of the actual distribution.