bootsonfire
bootsonfire

Reputation: 49

Scipy Weibull parameter confidence intervals

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?

Upvotes: 4

Views: 799

Answers (2)

Derryn Knife
Derryn Knife

Reputation: 104

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)

Upvotes: 2

F. Win
F. Win

Reputation: 410

You could use scipy.optimize.curve_fit to fit the weibull distribution to your data. This will also give you the covariance and thus you can estimate the error of the fitted parameters.

Upvotes: 0

Related Questions