This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How To Determine The Location Of A Peak In A List Of Numbers

hello all, I have some numbers, these numbers can be plot and we can found there is a peak, at first this ploted line was increasing, then decreasing, I want to get the peak point among these number, but this line is not absolute increasing and decreasing, there are some small "up" and "drop", it's a sawtooth line. Is there is a R package or perl module would be great helpful to me, could somebody help me?

for example, these number:

1, 2 ,4, 3, 5, 7, 5, 8, 10, 9, 7, 8, 5, 6, 4, 2, 3, 1

I want to get "10".

Add: there are not only one peak, sometimes two or more peak, such as:

1, 2 ,4, 3, 5, 7, 5, 8, 10, 9, 7, 8, 5, 6, 4, 2, 3, 1, 0, 0, 0, 0, 0, 2, 4, 3, 5, 8, 7, 6, 2, 3, 1

I want to get 10 and 8

statistics perl r

2 answers

The concept of a "peak" is a lot more complicated than that.

First and foremost it requires a careful definition of what you wish to call a peak - peaks are easy to see by eye while forgetting that our brains have awesome pattern matching capabilities and what we can easily see as a peak may be more difficult to describe in an algorithmic fashion.

What is easy to define is the concept of local maxima: a value that has smaller values on both of its sides. If that fits your purpose then the code is near trivial. More likely however it does not. In that case the simplest approach is to apply a data smoothing process - and then again look for local maxima. Your peak prediction then becomes a choice of data smoothing.

Within R:

> v <- c(1, 2 ,4, 3, 5, 7, 5, 8, 10, 9, 7, 8, 5, 6, 4, 2, 3, 1)
> max(v)
[1] 10

thanks, I found I had described the issue incompletely, there are two or more peaks in my data.

Log in to answer this question.