繁体   English   中英

R:找到(指数?)衰减的开始吗?

[英]R: Finding the begin of a (exponential?) decay?

在以下示例中,如何查找红色vlin指示的索引:

# Get the data as "tmpData"
source("http://pastie.org/pastes/9350691/download")

# Plot 
plot(tmpData,type="l")
abline(v=49,col="red")

第一图

以下方法很有希望,但是如何找到最大峰值?

library(RcppRoll)
n <- 10
smoothedTmpData <- roll_mean(tmpData,n)
plot(-diff(smoothedTmpData),type="l")
abline(v=49,col="red")

第二图

which.max(-diff(smoothedTmpData))为您提供最大值的索引。

http://www.inside-r.org/r-doc/base/which.max

我不确定这是否是您的实际问题...

如示例数据集中那样,在梯度中只有一个峰的地方,则gwieshammer是正确的:您可以使用which.max来找到它。

对于可能出现多个峰的情况,您需要一种更复杂的方法。 R具有许多峰发现功能(质量不同)。 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 

因此可以正确找到接近50的主峰,并且程序在开始时会拾取另一个较小的峰。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM