[R] Is there any R package that can find the maxima of a 1-D

(Ted Harding) Ted.Harding at manchester.ac.uk
Wed Mar 17 15:02:53 CET 2010


On 17-Mar-10 12:31:43, mauede at alice.it wrote:
> Is there any R package that can help me with digging out the
> maxima of a 1-D trajectory ?
> 
> I have 975 1-D  curves. They are only known as time series.
> That is a set of points ordered with respect to time. Some
> curves exhibit one only peak.
> We wish to find the number of peaks and their position along
> the time axis.
> Apparently it's a trivial problem solved looking at the zeros
> and the change of sign of the 1st derivative.
> In practice it is necessary to apply some criteria (which ones?)
> to discriminate between real peaks  and noise oscillations.
> Presumably I ought to define the noise level with respect to
> peaks height in this application ...
> Maybe wavelets can help ?
> Thank you in advance,
> Maura

Precisely. You need to define what you wish "peak" to mean.
Then you can implement your wish in code.

The most inclusive definition:
  (X[n] >= X[n-1])&(X[n] >= X[n+1])
will of course catch everything, including noisy fluctuations
(and as a result may hide real ("underlying") peaks hidden by
the noise).

You might extend the above:
(X[n]>=X[n-1])&(X[n-1]>=X[n-2])&(X[n]>=X[n+1])&(X[n+1]>=X[n+2])

or you might apply a smoother (possibly wavelets) to reduce the
noise and then find the peaks of that. And so on ... Apparently
you already have some notion of what you want "peak" to mean,
since you say "Others have two peaks of different height",
and you also recognise an effect of "noise".

But the possibilities are endless!

Sir Hector Munro's classic "Tables of the 3000-feet Mountains
of Scotland" (first published 1891) did not give a formal
definition "owing to the impossibility of deciding what should
be considered separate mountains." On the other hand, J. Rooke
Corbett's later "Scottish Mountains 2500 Feet And Under 3000 Feet
In Height With Re-Ascent Of 500 Feet On All Sides" did use
the "re-ascent" definition given in the title: it is a separate
mountain if you have to climb at least 500 feet from any other
peak to reach its summit.

However, a single mountain may have more than one peak. For
example, the mountain of Lochnagar (overlooking the Balmoral
Estate and the theme of a novel by Prince Charles) is held to
have two separate peaks, marked on the Ordnance Survey Map as
Cac Carn Beag and Cac Carn Mor (don't ask ... ), at 3789 feet
and 3768 feet respectively, separated by a ridge of about 1/4
mile which dips by about 100 feet.

They can be seen at the right-hand end of the photo of Lochnagar
shown in
  http://en.wikipedia.org/wiki/Lochnagar
(to the right of the notch just right of centre)

On the other hand, look at the photo of part of Cairngorm mountain
at
  http://www.scotclimb.org.uk/gallery.php?id=200
and ask: Is there a peak here, or is it all noise?

However, here:
  http://www.scotclimb.org.uk/gallery.php?id=126
you can rather clearly distinguish between peak and noise!

So we can (more or less) make the distinction when we look.
But how to define this sort of thing so that R can understand?
Up to you!

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 17-Mar-10                                       Time: 14:02:13
------------------------------ XFMail ------------------------------



More information about the R-help mailing list