Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1432

Re: Fit Gaussian function to histogram

From Mark Fisher <particlefilter@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Fit Gaussian function to histogram
Date 2011-04-02 22:05 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <in86jl$9tr$1@smc.vnet.net> (permalink)
References <imsh9i$5me$1@smc.vnet.net>

Show all headers | View raw


On Mar 29, 7:54 am, cubsfan334 <cubsfan...@gmail.com> wrote:
> Hi,
>
> I realize that I can generate a histogram from a data set using the
> Histogram[{data},bin size] command, yet this only seems to create a
> graphic.  Is there anyway to fit a function (preferably Gaussian) to
> the histogram Mathematica creates?
>
> Thanks!

Maybe you're interesting in something like this:

data = RandomReal[NormalDistribution[], 100];
histo = Histogram[data, 10, "PDF"];
hdata = Cases[histo,
   RectangleBox[{x0_, _}, {x1_, y_}, _] :> {.5 (x0 + x1),
     y}, \[Infinity]];
fun = PDF[NormalDistribution[m, s], x] /.
   FindFit[hdata, PDF[NormalDistribution[m, s], x], {m, s}, {x}];
Show[histo, Plot[fun, {x, Min[data], Max[data]}]]

--Mark

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Fit Gaussian function to histogram Mark Fisher <particlefilter@gmail.com> - 2011-04-02 22:05 +0000

csiph-web