Re: Fitting NormalDistribution to 2D List
- To: mathgroup at smc.vnet.net
- Subject: [mg31427] Re: [mg31424] Fitting NormalDistribution to 2D List
- From: BobHanlon at aol.com
- Date: Sat, 3 Nov 2001 18:25:04 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2001/11/3 6:50:22 AM, post_12 at hotmail.com writes: >I have saved the output of a >lengthy simulation where I have "binned" the data as such: > >{{1,2},{2,8},{3,16},{4,7},{5,3}} >where the 1st number is the "bin" and the 2nd the number of >occurences. Of course, the real data set has several thousand bins and >occurences as high as 10^5. I would like to calculate a Mean and >Standard Deviation of this data, however, the only way I could see to >do it in Mathematica would be to "unroll" the list; i.e. print out 2 >1s in succession followed by 8 2s, 16 3s etc. How can I fit this 2 >dimensional list to a NormalDistribution? Needs["Statistics`NormalDistribution`"]; Needs["Statistics`DescriptiveStatistics`"]; data={{1,2},{2,8},{3,16},{4,7},{5,3}}; unrolledData = Flatten[Table[#[[1]],{#[[2]]}]& /@data]; mu = Mean[unrolledData]; To find the mean without unrolling mu==(Plus@@(Times@@#& /@ data))/(Plus@@data[[All,2]]) True or mu==Tr[Times@@#& /@ data]/Tr[data[[All,2]]] True or mu==(Dot@@Transpose[data])/Tr[data[[All,2]]] True Selecting a method binnedMean[data_] := Tr[Times@@#& /@ data]/Tr[data[[All,2]]]; m = binnedMean[data]; The StandardDeviationMLE of the data without "unrolling" is s = Sqrt[binnedMean[{(#[[1]]-m)^2, #[[2]]}& /@ data]]; s == StandardDeviationMLE[unrolledData] True The distribution is NormalDistribution[m, s] NormalDistribution[109/36, Sqrt[1259]/36] Bob Hanlon Chantilly, VA USA