MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Weibull Distribution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5625] Re: [mg5598] Weibull Distribution
  • From: BobHanlon at aol.com
  • Date: Wed, 1 Jan 1997 21:04:54 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

> I am trying to work with Weibull distribution.  Specifically, I would 
> like to create random numbers under a Weibull distribution and fit a 
> curve or data with a Weibull distribution.

> If anyone could give me insight on how to accomplish this on Mathematica 
> 2.x, or even better Mathematica 3.0, it would be much appreciated.

The following will generate the Weibull distributed data, plot the original
PDF and CDF, and plot the PDF and CDF for the MLE estimate of the Weibull
distribution.

MLE equations were taken from:

Hoyland, Arnljot, and Rausand, Marvin, "System Reliability Theory", John
Wiley & Sons, 1994, p. 481.

Bob Hanlon
______________________________________

Needs["Statistics`ContinuousDistributions`"]
ffgb11[str_] := FontForm[str, {"Geneva-Bold", 11}]; 
WeibullMLE::usage = "WeibullMLE[WeibullDistribution[alpha, beta],
	data] provides the maximum likelihood estimates for the alpha
	and beta to have produced the Weibull distributed data.";
WeibullMLE[WeibullDistribution[alpha_, beta_], data_List] := 
   Module[{est, alphaEst, betaEst, eqn}, 
		est = Solve[{Mean[data] == 
		Mean[WeibullDistribution[alphaEst, betaEst]], 
		Variance[data] == Variance[WeibullDistribution[alphaEst, 
			betaEst]]}, {alphaEst, betaEst}][[1]]; (* starting values *)
		eqn = {Plus @@ 
			(alpha*beta - alpha*beta^(1 - alpha)*data^alpha) == 0, 
			Plus @@ (-Log[beta] + 1/alpha + Log[data] - 
			(data/beta)^alpha*Log[data/beta]) == 0}; (* MLE equations *)
		FindRoot[eqn, {alpha, alphaEst /. est}, 
			{beta, betaEst /. est}]]; (* MLE estimates *)

Module[{alpha = 3, mean = 2, nbrPts = 100, beta, data, 
	a, b, distr1, distr2, sd}, 
	beta = mean/Gamma[1 + 1/alpha];
	distr1 = WeibullDistribution[alpha, beta];
	data = Table[Random[distr1], {nbrPts}];  (* test data *)
	sd = StandardDeviation[distr1];
	distr2 = (WeibullDistribution[a, b] /. 
		WeibullMLE[WeibullDistribution[a, b], data]);
	Plot[{PDF[distr1, t], CDF[distr1, t], 
		PDF[distr2, t], CDF[distr2, t]}, {t, 0, mean + 2 sd}, 
	PlotLabel -> ffgb11["Weibull PDF and CDF"], 
	PlotStyle -> {RGBColor[0, 0, 1], RGBColor[0, 0, 1], 
		{RGBColor[1, 0, 0], AbsoluteDashing[{4}]}, 
		{RGBColor[1, 0, 0], AbsoluteDashing[{4}]}}, 
	Epilog -> {RGBColor[0, 0, 1], Text[
		StringForm["mean = ``", NumberForm[mean, 3]], 
		{mean, 0.25}], RGBColor[1, 0, 0], Text[
		StringForm["data mean = ``", NumberForm[Mean[data], 3]], 
		{mean, 0.1}]}]];



  • Prev by Date: Re: Evaluation Group
  • Next by Date: defining function over new Notation ?
  • Previous by thread: Re: Evaluation Group
  • Next by thread: defining function over new Notation ?