I've been using Matlab to fit data to a Weibull distribution using [paramhat, paramci] = wblfit(data, alpha). This gives the shape and scale parameters for a Weibull distribution as well as the confidence intervals for each value.
I'm trying to use Scipy to accomplish the sane task and can easily get the parameters with scipy.stats.weibull_min.fit but I cannot figure out a way to get the confidence intervals on the vlauee. Does Scipy offer this functionality? Or do I need to write the MLE confidence intervals estimation myself?
You can use the surpyval python package to get the inverse hessian matrix (the covariance) of the MLE.
import surpyval as surv
x = [1, 4, 5, 7, 8, 10]
model = surv.Weibull.fit(x)
model.hess_inv
array([[1.87507778, 0.27362521],
[0.27362521, 0.5031063 ]])
You can then use the diagonals to estimate the confidence bounds of the parameters:
from scipy.special import ndtri as z
import numpy as np
d = z(0.05) * np.sqrt(model.hess_inv[0, 0])
model.alpha + d, model.alpha - d
(4.283756480648752, 8.788467083439066)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With