MATLAB Examples

Estimate Parameters of a Three-Parameter Weibull Distribution

This example shows how to estimate parameters of a three-parameter Weibull distribution by using a custom probability density function.

Statistics and Machine Learning Toolbox™ uses a two-parameter Weibull distribution with a shape parameter $a$ and a scale parameter $b$. The Weibull distribution can take one more parameter, a location parameter $c$. The probability density function becomes

$$ f(x|a,b,c) = \left\{ \begin{array}{ll}
\frac{b}{a}\left(\frac{x-c}{a}\right)^{b-1}\exp\left(-\left(\frac{x-c}{a}\right)^b\right) & \mbox{if } x>c,\\
0 & \mbox{if } x \leq c, \end{array} \right.$$

where $a$ and $b$ are positive values, and $c$ is a real value.

Generate sample data of size 1000 from a three-parameter Weibull distribution with the shape parameter 1, scale parameter 1, and location parameter 10.

rng('default') % For reproducibility
data = wblrnd(1,1,[1000,1])+10;

Define a probability density function for a three-parameter Weibull distribution.

custpdf = @(x,a,b,c) (x>c).*(b/a).*(((x-c)/a).^(b-1)).*exp(-((x-c)/a).^b);

The Weibull probability density function is positive only for $x>c$. This constraint also implies that a location parameter $c$ is smaller than the minimum of the sample data. Include the lower and upper bounds of parameters by using the name-value pair arguments 'LowerBound' and 'UpperBound', respectively.

opt = statset('MaxIter',1e5,'MaxFunEvals',1e5,'FunValCheck','off');
phat = mle(data,'pdf',custpdf,'start',[5 5 5],'Options',opt,...
    'LowerBound',[0 0 -Inf],'UpperBound',[Inf Inf min(data)])
phat =

    1.0258    1.0618   10.0004

If mle does not converge with default statistics options, you can modify them by using the name-value pair argument 'Options'. Create a statistics options structure opt by using the function statset. Then use opt as the value of 'Options'.

The option opt includes the following:

  • 'MaxIter',1e5 — Increase the maximum number of iterations to 1e5.
  • 'MaxFunEvals',1e5 — Increase the maximum number of object function evaluations to 1e5.
  • 'FunValCheck','off' — Turn off checking for invalid object function values.

For a distribution with a region that has zero probability density, mle might try some parameters that have zero density, and it will fail to estimate parameters. To avoid this problem, you can turn off the option that checks for invalid function values by using 'FunValCheck','off'.

If the scale parameter $b$ is smaller than 1, the probability density of the Weibull distribution approaches infinity as $x$ goes to $c$, where $c$ is the location parameter. The maximum of the likelihood function is infinite. mle may find satisfactory estimates in some cases, but the global maximum is degenerate when $b<1$.