Re: fitting
- To: mathgroup at smc.vnet.net
- Subject: [mg104784] Re: fitting
- From: Ray Koopman <koopman at sfu.ca>
- Date: Tue, 10 Nov 2009 05:57:31 -0500 (EST)
- References: <hd3mt8$9sd$1@smc.vnet.net> <hd6ddt$q2h$1@smc.vnet.net>
On Nov 8, 4:26 am, Ray Koopman <koop... at sfu.ca> wrote: > On Nov 7, 3:50 am, Vadim Zaliva <kroko... at gmail.com> wrote: >> Hi! >> >> I am very new to Mathematica and I am failing in trying to do >> something very simple. >> I am have the following data: >> >> x = {8, 36, 74, 96, 123, 152, 201, 269, 415, 460, 444, 579, 711, >> 731, 602, 364, 151}; >> >> Which is a curve, similar to PDF function of Beta distribution: >> >> ListLinePlot[x] >> >> And I am trying to fit it to: >> >> PDF[BetaDistribution[\[Alpha], \[Beta]], x >> >> finding Alpha and Beta values. >> >> I will appreciate it somebody can give me a hint how to do this >> properly using FindFit or any other means. I am too embarrassed >> to post my modest attempts here, but trust me, I've spent few >> hours trying before posting :) >> >> Vadim > > You haven't said what your 'x' represents or how it is supposed to > relate to the Beta distribution. If we take the values as the counts > in equal-width bins that cover [0,1], then we can get the sample mean > and variance using the midpoints of the bins as the x-values, and use > the method of moments to estimate 'a' and 'b', the parameters of the > distribution. > > k = Length[f = {8, 36, 74, 96, 123, 152, 201, 269, 415, 460, 444, > 579, 711, 731, 602, 364, 151}] > x = Range[1/2,k]/k; {n = Tr@f, N[m = f.x/n], N[v = f.x^2/n - m^2]} > Solve[{m == a/(a+b), v == m(1-m)/(1+a+b)}, {a,b}]//Flatten//N > > 17 > > {5416, 0.653065, 0.0391941} > > {a -> 3.12214, b -> 1.65861} 17 bins? That's a strange number! Were there 3 empty bins at the start? In any case, this will get maximum likelihood estimates of {a,b}. To keep them positive, we estimate their logs. k = Length[f = { 0,0,0, 8, 36, 74, 96, 123, 152, 201, 269, 415, 460, 444, 579, 711, 731, 602, 364, 151}] xx = N@Partition[Range[0,k]/k,2,1]; NMaximize[f.Log[BetaRegularized[Sequence@@#,E^ta,E^tb]&/@xx],{ta,tb}] {a->E^ta, b->E^tb}/.%[[2]] 20 {-13831.2, {ta -> 1.53959, tb -> 0.673633}} {a -> 4.66267, b -> 1.96135}