计算直方图或密度函数中的峰 [英] Calculating peaks in histograms or density functions

查看:127
本文介绍了计算直方图或密度函数中的峰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎已经有很多密度函数中的峰值"线程,但是我看不到专门解决这一点的线程.如果我错过了,很抱歉重复.

There seem to be a lot of "peaks in density function" threads already, but I don't see one addressing this point specifically. Sorry to duplicate if I missed it.

我的问题:给定一个包含1000个值的向量(附有样本),我想识别数据的直方图或密度函数中的峰.从下面的示例数据的图像中,我可以看到直方图中的峰,分别位于〜0、6200和8400.但是,我需要获得这些峰的确切值,最好是通过简单的过程,因为我有数千个这样的矢量进行处理.

My problem: Given a vector of 1000 values (sample attached), I would like to identify the peaks in the histogram or density function of the data. From the image of the sample data below , I can see peaks in the histogram at ~0, 6200, and 8400. But I need the obtain the exact values of these peaks, preferably in a simple procedure as I have several thousand of these vectors to process.

我最初开始使用直方图输出本身,但是无法获得任何峰值查找命令以使其正常工作(例如,根本没有).我什至不确定如何从 splus2R 包中获取 peaks()命令以在直方图对象或密度对象上工作.这仍然是我的偏爱,因为我想确定每个峰的最大频率的确切数据值(与密度函数值(略有不同)相对),但是我也无法确定.

I originally started working with the histogram outputs themselves, but couldn't get any peak-finding command to work properly (like, not at all). I'm not even sure how it would get the peaks() command from the splus2R package to work on histogram object or on a density object. This would still be my preference, as I would like to identify the exact data value of the max frequency of each peak (as opposed to the density function value, which is slightly different), but I can't figure that one out either.

我会自己发布示例数据,但是在这里看不到一种方法(对不起,如果我只是想丢失它的话).

I would post the sample data themselves, but I can't see a way to do that on here (sorry if I'm just missing it).

推荐答案

如果您的y值是平滑的(例如在示例图中),那么应该可以很容易地找到这些峰:

If your y values are smooth (like in your sample plot), this should find the peaks pretty repeatably:

peakx <- x[which(diff(sign(diff(y)))==-2)]

这篇关于计算直方图或密度函数中的峰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆