0
$\begingroup$

Whenever the function "FindDistributionParameter" is used in Wolfram Mathematica, it needs two inputs: raw data and distribution function.

I have a problem where I have have data and I need to use Weibull distribution function, but bins in my histogram are unevenly spaced.

How do I add that information into "FindDistributionParameters" function in order to get a proper fit?

$\endgroup$
  • $\begingroup$ You can't get there from here with FindDistributionParameters. You'll need to use LogLikelihood, CDF, and FindMaximum and have the counts (rather than relative frequencies). I think there's an example in this forum but using the log normal distribution. I'll look for that. $\endgroup$ – JimB Oct 9 at 16:26
  • 1
    $\begingroup$ Take a look at mathematica.stackexchange.com/questions/203547/…. $\endgroup$ – JimB Oct 9 at 16:46
  • $\begingroup$ Thank you for your answer JImB! $\endgroup$ – Cro Simpson2.0 Oct 9 at 16:55
2
$\begingroup$

One can't use FindDistributionParameters once the data becomes binned. However, one can construct the log of the likelihood function and then use FindMaximum as long as you still have the counts. (The relative frequencies won't do.)

(* Generate histogram data with unequal bin widths *)
SeedRandom[12345]
x = RandomVariate[WeibullDistribution[2, 3], 1000];
{borders, counts} = HistogramList[Log[x]];
borders = Exp[borders] // N
(* {0.090718, 0.110803, 0.135335, 0.165299, 0.201897, 0.246597, 0.301194, 0.367879,
    0.449329, 0.548812, 0.67032, 0.818731, 1., 1.2214, 1.49182, 1.82212, 2.22554, 
    2.71828, 3.32012, 4.0552, 4.95303, 6.04965, 7.38906, 9.02501} *)
counts
(* {1, 1, 1, 1, 3, 3, 4, 7, 6, 16, 17, 26, 58, 59, 94, 117, 148, 176, 112, 78, 58, 13, 1} *)

(* Log of the likelihood *)
logL = Sum[counts[[i]] Log[CDF[WeibullDistribution[a, b], borders[[i + 1]]] - 
  CDF[WeibullDistribution[a, b], borders[[i]]]], {i, Length[counts]}];

(* Find maximum likelihood estimates using the default starting values of 1 for both parameters *)
mle = FindMaximum[{logL, a > 0 && b > 0}, {{a, 1}, {b, 1}}]
(* {-2460.29, {a -> 2.0714, b -> 2.9929}} *)

(* Estimates of standard errors *)
cov = -Inverse[(D[logL, {{a, b}, 2}]) /. mle[[2]]];
ase = cov[[1, 1]]^0.5
(* 0.0516358 *)
bse = cov[[2, 2]]^0.5
(* 0.0485239 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.