添加一条适合 R 中绘图峰值的曲线?
如果给定两个向量及其图,是否有一个函数可以添加一条适合峰值的曲线? 例如,我有:
x=c(0:20)
x [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
y [1] 19.4 17.9 8.1 11.3 7.8 8.0 5.0 1.7 3.9 5.4 7.5 5.4 4.7 5.0 4.9 3.5 2.9 2.4 1.4 1.7
绘图(x,y,xlim=范围(x),ylim=范围(y))
最佳, 七海
Is there a function that adds a curve that fits the peaks if given two vectors and their plot?
For example, I have:
x= c(0:20)
x
[1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20y
[1] 19.4 17.9 8.1 11.3 7.8 8.0 5.0 1.7 3.9 5.4 7.5 5.4 4.7 5.0 4.9 3.5 2.9 2.4 1.4 1.7plot(x,y,xlim=range(x),ylim=range(y))
best,
Nanami
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从数学上来说,你的问题的定义非常不明确。您为 y 值提供一系列离散值,而不是函数。这意味着无法通过微分来找到局部最大值。
也就是说,这里有一些代码可能可以帮助您入门。它利用了一个名为
peaks
的函数,(归因于 Brian Ripley):问题是局部峰值的概念是定义不明确。你指的本地化程度如何?提供的峰值算法允许您修改
跨度
。玩一玩,看看是否有帮助。Mathematically speaking, your problem is very poorly defined. You supply a range of discrete values, not a function, for your y values. This means it can not be differentiated to find local maxima.
That said, here is a bit of code that might get you started. It makes use of a function called
peaks
, (attributed to Brian Ripley):The problem is that the concept of local peaks is poorly defined. How local do you mean? The peaks algorithm as supplied allows you to modify the
span
. Have a play and see whether it is helpful at all.