Re: Fit Gaussian function to histogram
- To: mathgroup at smc.vnet.net
- Subject: [mg117853] Re: Fit Gaussian function to histogram
- From: dr DanW <dmaxwarren at gmail.com>
- Date: Fri, 1 Apr 2011 02:37:11 -0500 (EST)
- Reply-to: comp.soft-sys.math.mathematica at googlegroups.com
I find it easier to fit to the CDF. The shape of the histogram depends on bin widths, so some of the decisions you have to make to get a good quality fit are arbitrary. The cumulative frequency of your data, however, is unambiguous. CumulativeFrequency[dat_] := With[{tsd = Tally[Sort[dat]]}, Transpose[{tsd[[All,1]], Accumulate[tsd[[All,2]]]/(Length[dat] + 1)}]] FitCDF[d_] := Module[{mean, sd, cf, param}, mean = Mean[d]; sd = StandardDeviation[d]; cf = CumulativeFrequency[d]; param = FindFit[cf, CDF[NormalDistribution[\[Mu], \[Sigma]], x], {{\[Mu], mean}, {\[Sigma], sd}}, x]; Print[Show[{ListPlot[cf], Plot[Evaluate[CDF[NormalDistribution[\[Mu], \[Sigma]], x] /. param], Evaluate[{x, \[Mu] - 3*\[Sigma], \[Mu] + 3*\[Sigma]} /. param]]}]]; param] Notice that this technique works with any distribution (with suitable modification of FitCDF). Mathematica 8 has a lot of new tools for statistics and probability, many of which I do not understand. Perhaps you are looking for HypothesisTesting`? Enjoy, Daniel