# Fitting a beta distribution to a probability density curve

If I have a spectral data set showing measured energy on the y-axis and frequency on the x-axis, how would I go about fitting this to a beta distribution?

For example, lets say I had the data for the following curves showing spectrum for this ship:

How do I determine the beta curve fit parameters to say the blue line?

Taking it one step further. If I have a wav sound file of the sound of an engine, how would I do the same thing?

UPDATE

I attempted to use the supplied answer and got an error as follows:

The data file can be downloaded from the following URL: acoustic power spectrum data to 3k hz

The overall goal here is to generate a curve approximating the shape like this:

-
Are you sure about fitting a Beta Distribution to this data? A Beta distribution has a finite support (0..1) which your data doesn't have and an interpretation related to probability, which I find hard to make in the context of frequency spectra of sounds. –  Sjoerd C. de Vries Jan 15 at 12:55
What do you mean by finite support? –  Tyler Durden Jan 15 at 15:41
A beta distribution is defined only between 0 and 1. –  Sjoerd C. de Vries Jan 15 at 16:00
I get the same answer if I scale the values so they are less than 1. –  Tyler Durden Jan 16 at 20:10
suggest you spend some time learning what a beta distribution is. Do some plots and manually try to find some parameters that reasonably resemble your data. –  george2079 Jan 16 at 20:41

data = Import["http://pastebin.com/download.php?i=Tuq6zvba", "TEXT"];
data1 = Transpose[{Rest@Range[0, 1, 1./Length@#], #}] &@ ToExpression@StringSplit[data];
parms = FindFit[data1, model, {a, b}, x]
Show[Graphics[Point@data1, Axes -> True],
Plot[model /. parms, {x, 0, 1}, Evaluated -> True, PlotRange -> All],
AspectRatio -> 1]


-
I tried to use this method and got an error about a "gradient" as shown above in the updated question. –  Tyler Durden Jan 16 at 17:14
@TylerDurden See Sjoerd's comments under your question –  belisarius Jan 16 at 19:24
I get the same error if I scale the y-values to be less than 1 (see updated screenshot in question) –  Tyler Durden Jan 16 at 20:11
@TylerDurden Please post a sample of your data set. Otherwise your problem is impossible to debug –  belisarius Jan 16 at 21:16
How do I post data (it is a .wav file that is about 1 megabyte in size)? –  Tyler Durden Jan 16 at 21:37

You mentioned in the comments that you are interested in a general shape of your data. This can be inferred from the nature of your data, and most probably does not follow a beta distribution. You can use a polynomial series of a chosen degree to visualize a more general shape of your data:

data = Import["http://pastebin.com/download.php?i=Tuq6zvba", "TEXT"];
data1 = Transpose[{Rest@Range[0, 1, 1./Length@#], #}] &@
ToExpression@StringSplit[data];
lp = ListLinePlot[MovingAverage[data1, 50]];

Clear[n, a, b, c, i, x, polynome, polyGauss]
polynome[n_] :=
NonlinearModelFit[data1, Sum[a[i + 1]*x^i, {i, 0, n}],
Flatten[Table[{a[i + 1]}, {i, 0, n}]], x]

Show[{Plot[Evaluate[Table[polynome[n][x], {n, 3, 12, 3}]], {x, 0, 1},
PlotRange -> All, AxesOrigin -> {0, 0}, PlotStyle -> Thick], lp}, ImageSize -> 600]


Or you can use a series of Gaussian bell functions:

polyGauss[n_] :=
NonlinearModelFit[data1, Sum[a[i]*Exp[-(b[i] x - c[i])^2], {i, n}],
Flatten[Table[{{a[i], 1}, {b[i], i/(n + 1)}, c[i]}, {i, n}], 1], x]

Show[{Plot[Evaluate[Table[polyGauss[n][x], {n, 3, 12, 3}]], {x, 0, 1},
PlotRange -> All, AxesOrigin -> {0, 0}, PlotStyle -> Thick], lp}, ImageSize -> 600]


-