[英]R: Finding the begin of a (exponential?) decay?
How to find the index indicated by the red vlin in the following example: 在以下示例中,如何查找红色vlin指示的索引:
# Get the data as "tmpData"
source("http://pastie.org/pastes/9350691/download")
# Plot
plot(tmpData,type="l")
abline(v=49,col="red")
The following approach is promising, but how to find the peak maximum? 以下方法很有希望,但是如何找到最大峰值?
library(RcppRoll)
n <- 10
smoothedTmpData <- roll_mean(tmpData,n)
plot(-diff(smoothedTmpData),type="l")
abline(v=49,col="red")
which.max(-diff(smoothedTmpData))
gives you the index of the maximum. which.max(-diff(smoothedTmpData))
为您提供最大值的索引。
http://www.inside-r.org/r-doc/base/which.max http://www.inside-r.org/r-doc/base/which.max
I'm unsure if this is your actual question... 我不确定这是否是您的实际问题...
Where there is a single peak in the gradient, as in your example dataset, then gwieshammer is correct: you can just use which.max
to find it. 如示例数据集中那样,在梯度中只有一个峰的地方,则gwieshammer是正确的:您可以使用
which.max
来找到它。
For the case where there are multiple possible peaks, you need a more sophisticated approach. 对于可能出现多个峰的情况,您需要一种更复杂的方法。 R has lots of peak finding functions (of varying quality).
R具有许多峰发现功能(质量不同)。 One that works for this data is
wavCWTPeaks
in wmtsa
. wavCWTPeaks
中的wmtsa
可以处理这些数据。
library(RcppRoll)
library(wmtsa)
source("http://pastie.org/pastes/9350691/download")
n <- 10
smoothedTmpData <- roll_mean(tmpData, n)
gradient <- -diff(smoothedTmpData)
cwt <- wavCWT(gradient)
tree <- wavCWTTree(cwt)
(peaks <- wavCWTPeaks(tree))
## $x
## [1] 4 52
##
## $y
## [1] 302.6718 5844.3172
##
## attr(,"peaks")
## branch itime iscale time scale extrema iendtime
## 1 1 5 2 5 2 16620.58 4
## 2 2 57 26 57 30 20064.64 52
## attr(,"snr.min")
## [1] 3
## attr(,"scale.range")
## [1] 1 28
## attr(,"length.min")
## [1] 10
## attr(,"noise.span")
## [1] 5
## attr(,"noise.fun")
## [1] "quantile"
## attr(,"noise.min")
## 5%
## 4.121621
So the main peak close to 50 is correctly found, and the routine picks up another smaller peak at the start. 因此可以正确找到接近50的主峰,并且程序在开始时会拾取另一个较小的峰。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.