Re: Gaussian PDF Overlay
- To: mathgroup at smc.vnet.net
- Subject: [mg19283] Re: [mg19277] Gaussian PDF Overlay
- From: BobHanlon at aol.com
- Date: Sat, 14 Aug 1999 01:45:11 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Lawrence, Use a GeneralizedBarChart: Needs["Statistics`ContinuousDistributions`"] Needs["Statistics`DataManipulation`"]; Needs["Graphics`Graphics`"]; dist = NormalDistribution[mu = 4., sigma = 2.]; xmin = mu - 3sigma; xmax = mu + 3sigma; plt1 = Plot[PDF[dist, x], {x, xmin, xmax}, PlotStyle -> AbsoluteThickness[2], DisplayFunction -> Identity]; nbrSamples = 1000; data = RandomArray[dist, nbrSamples]; nbrBins = 10; step = (xmax - xmin)/nbrBins; freq = BinCounts[data, {xmin, xmax, step}]/nbrSamples; midPoints = Table[xmin + step(k - 1/2), {k, nbrBins}]; plt2 = GeneralizedBarChart[Transpose[{midPoints, freq, Table[1, {nbrBins}]}], DisplayFunction -> Identity]; Show[{plt2, plt1}, DisplayFunction -> $DisplayFunction]; Bob Hanlon In a message dated 8/12/99 5:35:54 AM, lwalker701 at earthlink.net writes: >I've tried to overlay a continuous gaussian probability >density curve onto a bar chart of similar distribution. The >values for the barchart were generated by bin counting the >data using the BinCounts function. The data is a list >generated by Random[NormalDistribution[]]. > >At first I simply tried to overlay the plot and barchart >using Show. The x-axis scale of the curve was different >from the >barchart's scale. So I had to manually change the position >and rescale the curve until it overlayed the barchart using >the program below. I didn't like the fact that the x-scale >shows 0 to 40 instead of -4 to 4. > >Is there a better way of doing this? >