crabbymetrics
  • Home
  • API
    • API Overview
    • Regression And GLMs
    • Survival / Event-Time
    • Causal Inference And Panels
    • Hypothesis Testing And Utilities
    • Transforms
    • Estimation Interfaces
  • Binding Crash Course
  • Regression And GLMs
    • OLS
    • ABC OLS
    • Anytime-Valid Confidence Sequences
    • Ridge
    • Bagged Polynomial Regression
    • Fixed Effects OLS
    • ElasticNet
    • Logit
    • Multinomial Logit
    • Poisson
    • MLE Prediction Interface
    • Survival / Recurrent Events
    • GMM
    • FTRL
    • MEstimator Poisson
  • Causal Inference
    • Balancing Weights
    • EPLM
    • Average Derivative
    • Double ML And AIPW
    • Richer Regression
    • TwoSLS
    • Synthetic Control
    • Synthetic DID
    • Horizontal Panel Ridge
    • Matrix Completion
    • Interactive Fixed Effects
    • Staggered Panel Event Study
    • Joint Hypothesis Tests
  • Transforms
    • PCA And Kernel Basis
  • Ablations
    • Variance Estimators
    • Semiparametric Estimator Comparisons
    • Two-Period Semiparametric DID
    • Bridging Finite And Superpopulation
    • Panel Estimator DGP Comparisons
    • Same Root Panel Case Studies
    • Randomized Sketching And Least Squares
  • Optimization
    • Optimizers
    • GMM With Optimizers
  • Ding: First Course
    • Overview And TOC
    • Ch 1 Correlation And Simpson
    • Ch 2 Potential Outcomes
    • Ch 3 CRE And Fisher RT
    • Ch 4 CRE And Neyman
    • Ch 9 Bridging Finite And Superpopulation
    • Ch 11 Propensity Score
    • Ch 12 Double Robust ATE
    • Ch 13 Double Robust ATT
    • Ch 21 Experimental IV
    • Ch 23 Econometric IV
    • Ch 27 Mediation

On this page

  • 1 Where it fits
  • 2 Likelihood and predictions
  • 3 Inference
  • 4 Performance and numerical behavior
  • 5 Python API
  • 6 Minimal example
  • 7 summary() contract

WeibullPH

Parametric proportional hazards with flexible monotone baseline hazard

from _api_doc_utils import *

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 ()