from _api_doc_utils import *WeibullPH
Parametric proportional hazards with flexible monotone baseline hazard
1 Where it fits
Group: Survival / event-time models
WeibullPH generalizes the exponential PH model to
\[ h_i(t \mid x_i) = \lambda_0 ho t^{ho-1} \exp(x_i'eta), \]
which nests increasing, decreasing, and constant baseline hazards depending on the shape parameter \(ho\). Like ExponentialPH, it identifies absolute hazard and survival objects.
2 Likelihood and predictions
With \(\lambda=\exp(\alpha)\) and shape \(\rho=\exp(\gamma)\), the model is
\[ h(t\mid x) = \lambda\rho t^{\rho-1}\exp(x'\beta), \qquad H(t\mid x) = \lambda t^\rho\exp(x'\beta). \]
The right-censored log-likelihood is
\[ \ell(\alpha,\beta,\gamma) = \sum_i \left[ d_i\{\alpha+\gamma+x_i'\beta+(\rho-1)\log t_i\} -\exp(\alpha+x_i'\beta+\rho\log t_i) \right]. \]
Newton optimization uses analytic derivatives, a \(10^{-8}\) Hessian ridge, per-coordinate step clipping to \([-2,2]\), and backtracking. Initialization uses the exponential event-rate estimate for \(\alpha\), zero slopes, and \(\rho=1\). Default prediction is \(\exp\{-H(t\mid x)\}\); the linear prediction is the time-specific log hazard.
3 Inference
The covariance is inverse observed information for the parameter order
\[ (\alpha,\ \beta',\ \gamma)'. \]
It is model-based under a correctly specified Weibull PH likelihood, independent observations, and noninformative right censoring. The summary exposes the full covariance and shape but does not split out standard errors. There is no robust, cluster, bootstrap, or Wald method. Maximum-iteration termination is not distinguished from convergence in the stored result; inspect the reported iteration count.
4 Performance and numerical behavior
Dense Hessian construction costs \(O(np^2)\) and its Newton solve up to \(O(p^3)\) per iteration. Terms involving \(\exp(\gamma)\log t\) make the model more sensitive than ExponentialPH to extreme time scales; rescaling time can materially improve conditioning while changing the scale parameter in the expected way. Exponentials are not clipped. The implementation accepts only positive finite stop times and binary event indicators, with no delayed entry, weights, strata, or time-varying covariates.
5 Python API
Constructor: cm.WeibullPH
Use fit(x, time, event). predict_lin(x, time) returns the log hazard at a specific horizon, while predict_hazard, predict_cumulative_hazard, and predict_survival expose the absolute prediction surface. The default predict(x, time) returns survival probabilities.
print(inspect.signature(cm.WeibullPH))()
cls = cm.WeibullPH
display(HTML(html_table(["Public method"], public_methods(cls))))| Public method |
|---|
fit(self, /, x, time, event, max_iterations=100, tolerance=1e-08) |
predict(self, /, x, time) |
predict_cumulative_hazard(self, /, x, time) |
predict_hazard(self, /, x, time) |
predict_lin(self, /, x, time) |
predict_log_hazard(self, /, x, time) |
predict_survival(self, /, x, time) |
summary(self, /) |
survival(self, /, x, time) |
6 Minimal example
rng=np.random.default_rng(32)
x=rng.normal(size=(300,2)); rho=1.4; lam=0.03; u=rng.uniform(size=300); t_event=(( -np.log(u)) /(lam*np.exp(x@np.array([0.45,-0.25]))))**(1.0/rho); c=rng.exponential(35,size=300)
time=np.minimum(t_event,c); event=(t_event<=c).astype(float)
model=cm.WeibullPH(); model.fit(x,time,event)
print(model.predict_lin(x[:3], time[:3]))
print(model.predict_hazard(x[:3], time[:3]))
print(model.predict_cumulative_hazard(x[:3], time[:3]))
print(model.predict(x[:3], time[:3]))[-1.9818025 -2.48230672 -2.03104686]
[0.13782059 0.08355028 0.1311981 ]
[0.94552302 0.49164741 1.19831413]
[0.38847634 0.61161798 0.30170242]
7 summary() contract
The table below is generated by fitting the live class in this repository and then inspecting summary(). Shapes are shown because most values are plain NumPy arrays or scalars.
rng=np.random.default_rng(132); x=rng.normal(size=(140,2)); rho=1.3; lam=0.04; u=rng.uniform(size=140); te=(( -np.log(u)) /(lam*np.exp(x@np.array([0.35,-0.15]))))**(1.0/rho); c=rng.exponential(25,size=140); time=np.minimum(te,c); event=(te<=c).astype(float)
model=cm.WeibullPH(); model.fit(x,time,event)
summary = model.summary()
display(HTML(html_table(["summary() key", "shape"], summary_shape_rows(summary))))| summary() key | shape |
|---|---|
log_scale_hazard |
() |
shape |
() |
coef |
(2,) |
hazard_ratio |
(2,) |
vcov |
(4, 4) |
log_likelihood |
() |
iterations |
() |