Find the two most commonly occurring values in a multimodal distribution of numbers.
5 次查看(过去 30 天)
显示 更早的评论
My data looks like this, when plotted:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1629716/image.jpeg)
(x axis is just index number)
looking at this, I know the values I'm looking for are ~0 and ~-3. I need Matlab to find this automatically.
There is a distribution-like clustering around these values (so the actual values aren't all the same, so using something like mode doesn't help, among other reasons).
Here is a zoomed in picture of the above for clarity on what the "distribution" looks like.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1629721/image.jpeg)
I tried using fitdist but it will not work with negative numbers. And sometimes my numbers are symmetric around zero, so I dont want to just take the absolute value.
It seems like it should be a simple thing, but I'm stumped.
0 个评论
回答(1 个)
Jeff Miller
2024-2-28
It would be more informative to see a histogram of your y values since they aren't related to x per se. If that histogram looks approximately like a mixture of three normals, then you could use
GMModel1 = fitgmdist(y,3);
The output will give you "component proportions" for the three components, and you could then use the mu's of the two components with the highest proportions, if those mu's fit your idea of the "most common" scores (given the slight variations among similar scores).
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!