如果你有MMA V8,你可以使用新的DistributionFitTest
disFitObj = DistributionFitTest[daList, NormalDistribution[a, b],"HypothesisTestData"];
Show[
SmoothHistogram[daList],
Plot[PDF[disFitObj["FittedDistribution"], x], {x, 0, 120},
PlotStyle -> Red
],
PlotRange -> All
]
![enter image description here](https://i.stack.imgur.com/RyRDe.png)
disFitObj["FittedDistributionParameters"]
(* ==> {a -> 55.8115, b -> 20.3259} *)
disFitObj["FittedDistribution"]
(* ==> NormalDistribution[55.8115, 20.3259] *)
它可以适应其他发行过。
另一个有用的V8功能是HistogramList
,它为您提供了Histogram
的分级数据。它也需要大约全部的Histogram
的选项。
{bins, counts} = HistogramList[daList]
(* ==> {{0, 20, 40, 60, 80, 100}, {2, 10, 20, 17, 7}} *)
centers = MovingAverage[bins, 2]
(* ==> {10, 30, 50, 70, 90} *)
model = s E^(-((x - \[Mu])^2/\[Sigma]^2));
pars = FindFit[{centers, counts}\[Transpose],
model, {{\[Mu], 50}, {s, 20}, {\[Sigma], 10}}, x]
(* ==> {\[Mu] -> 56.7075, s -> 20.7153, \[Sigma] -> 31.3521} *)
Show[Histogram[daList],Plot[model /. pars // Evaluate, {x, 0, 120}]]
![enter image description here](https://i.stack.imgur.com/RS5aO.png)
您也可以尝试NonlinearModeFit
的配件。在这两种情况下,最好带上您自己的初始参数值,以获得全球最佳配合的最佳机会。
在V7没有HistogramList
但你可以使用this得到相同的列表:
在直方图[数据,bspec,FH]功能FH适用于两张 参数:列表{下标[b,1],下标[b, 2]},{下标[b,2],下标[b,3]},[省略号}}以及相应的计数列表{ c,1],下标[c,2],[Ellipsis]}。 函数应该返回每个 下标[c,i]的高度列表。
这可以用于如下(from my earlier answer):
Reap[Histogram[daList, Automatic, (Sow[{#1, #2}]; #2) &]][[2]]
(* ==> {{{{{0, 20}, {20, 40}, {40, 60}, {60, 80}, {80, 100}}, {2,
10, 20, 17, 7}}}} *)
当然,你仍然可以使用BinCounts
但是你错过了MMA的自动分级算法。你必须提供自己的分级:
counts = BinCounts[daList, {0, Ceiling[Max[daList], 10], 10}]
(* ==> {1, 1, 6, 4, 11, 9, 9, 8, 5, 2} *)
centers = Table[c + 5, {c, 0, Ceiling[Max[daList] - 10, 10], 10}]
(* ==> {5, 15, 25, 35, 45, 55, 65, 75, 85, 95} *)
pars = FindFit[{centers, counts}\[Transpose],
model, {{\[Mu], 50}, {s, 20}, {\[Sigma], 10}}, x]
(* ==> \[Mu] -> 56.6575, s -> 10.0184, \[Sigma] -> 32.8779} *)
Show[
Histogram[daList, {0, Ceiling[Max[daList], 10], 10}],
Plot[model /. pars // Evaluate, {x, 0, 120}]
]
![enter image description here](https://i.stack.imgur.com/hSw9f.png)
正如你可以看到合适的参数可能取决于您选择的分级颇有几分。特别是我称为s
的参数主要取决于垃圾箱的数量。越多的垃圾箱,单个垃圾箱数量越低,s
的值就越低。
非常感谢你,这是非常有帮助的。 – 500