FindFit 与 Mathematica 中的 BinCounts 或直方图
daList={62.8347, 88.5806, 74.8825, 61.1739, 66.1062, 42.4912, 62.7023,
39.0254, 48.3332, 48.5521, 51.5432, 69.4951, 60.0677, 48.4408,
59.273, 30.0093, 94.6293, 43.904, 59.6066, 58.7394, 68.6183, 83.0942,
73.1526, 47.7382, 75.6227, 58.7549, 59.2727, 26.7627, 89.493,
49.3775, 79.9154, 73.2187, 49.5929, 84.4546, 28.3952, 75.7541,
72.5095, 60.5712, 53.2651, 33.5062, 80.4114, 63.7094, 90.2438,
55.2248, 44.437, 28.1884, 4.77477, 36.8398, 70.3579, 28.1913,
43.9001, 23.8907, 12.7823, 22.3473, 57.6724, 49.0148}
以上是我正在处理的实际数据示例。 我使用 BinCounts,但这只是为了直观地说明直方图应该这样做:我想适应该直方图的形状
Histogram@data
我知道如何拟合数据点本身,例如:
model = 0.2659615202676218` E^(-0.2222222222222222` (x - \[Mu])^2)
FindFit[data, model, \[Mu], x]
这与我想要做的相距甚远:如何在 Mathematica 中拟合 bin 计数/直方图?
daList={62.8347, 88.5806, 74.8825, 61.1739, 66.1062, 42.4912, 62.7023,
39.0254, 48.3332, 48.5521, 51.5432, 69.4951, 60.0677, 48.4408,
59.273, 30.0093, 94.6293, 43.904, 59.6066, 58.7394, 68.6183, 83.0942,
73.1526, 47.7382, 75.6227, 58.7549, 59.2727, 26.7627, 89.493,
49.3775, 79.9154, 73.2187, 49.5929, 84.4546, 28.3952, 75.7541,
72.5095, 60.5712, 53.2651, 33.5062, 80.4114, 63.7094, 90.2438,
55.2248, 44.437, 28.1884, 4.77477, 36.8398, 70.3579, 28.1913,
43.9001, 23.8907, 12.7823, 22.3473, 57.6724, 49.0148}
The above are a sample of actual data I am dealing with.
I use BinCounts, but this is just to illustrate visually histogram should do it : I would like to fit the shape of that histogram
Histogram@data
I know how to fit datapoints themselves like :
model = 0.2659615202676218` E^(-0.2222222222222222` (x - \[Mu])^2)
FindFit[data, model, \[Mu], x]
Which is far from what I wan to do : How can I fit bin-counts/histograms in Mathematica ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有 MMA V8,您可以使用新的
DistributionFitTest
它可以适合其他分布也是如此。
另一个有用的 V8 函数是
HistogramList
,它为您提供Histogram
的分箱数据。它也需要直方图的所有选项。您也可以尝试使用
NonlinearModeFit
进行拟合。在这两种情况下,最好有自己的初始参数值,这样才有可能最终获得全局最佳拟合。在 V7 中没有
HistogramList
但您可以使用 这个:可以按如下方式使用(来自我之前的回答):
当然,您仍然可以使用
BinCounts
,但您会错过 MMA 的自动分箱算法。您必须提供自己的分箱:如您所见,拟合参数可能在很大程度上取决于关于您的分箱选择。特别是我称为
s
的参数主要取决于 bin 的数量。 bin 越多,单个 bin 计数越少,s
的值也越低。If you have MMA V8 you could use the new
DistributionFitTest
It can fit other distributions too.
Another useful V8 function is
HistogramList
, which provides you withHistogram
's binning data. It takes about all ofHistogram
's options too.You could also try
NonlinearModeFit
for fitting. In both cases it is good to come with your own initial parameter values to have the best chances that you end up with a globally optimal fit.In V7 there is no
HistogramList
but you could get the same list using this:This can be used as follows (from my earlier answer):
Of course, you can still use
BinCounts
but the you miss MMA's automatic binning algorithms. You have to provide a binning of your own:As you can see the fit parameters may depend quite a bit on your binning choice. Particularly the parameter I called
s
depends critically on the amount of bins. The more bins, the lower the individual bin counts and the lower the value ofs
will be.