Witold Eryk Wolski
2002-Jul-26 13:45 UTC
[R] Is there a function for finding local extrema.
I have a vector with about 100.000 values representing a quite regular function (sinusoid like). I would like to find all local maxima of this function (should be about 4000). Is there a native routine for R? Thanks in advance Eryk. -- _|_ \|/ \|/ Eryk Witold Wolski tel :0049-(0)30-8413-1543 w w ?v? 'v? \'v'/ MPI Moleculare Genetik fax :0049-(0)30-8413-1139 | | /| |\/| |\ | | Mass Spectrometry Group http://www.molgen.mpg.de /.^.\ m m m m m m mail :wolski at molen.mpg.de /|\ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Assuming the first and last values in the vector y can't be determined to be local maxima, try max<-1+which(( y[2:(n-1)] > y[1:(n-2)]) & (y[2:(n-1)] > y [3:n])) max is now a vector of indicies of the local maxima, and y[max] are their values Witold Eryk Wolski wrote:> I have a vector with about 100.000 values representing a quite regular > function (sinusoid like). > I would like to find all local maxima of this function (should be > about 4000). Is there a native routine for R? > Thanks in advance > Eryk. >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Does anyone know if there is a function in R that fits a Parzen Window ? I have searched the mail archives and the packages to no avail. Perhaps it has a different name or implemented differently. I do not mind trying to write the codes but rather not waste time if one exists already. Many thanks in advance. Adai. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Philippe Grosjean
2002-Jul-26 15:23 UTC
[R] Is there a function for finding local extrema.
To find extrema, you have the turnpoints() function in the optional package
pastecs. Once pastecs is installed on your system, use:
library(pastecs)
example(turnpoints)
?turnpoints
For your particular problem, you can use:
X <- runif(100000)
extract(turnpoints(X), 100000, peak=1, pit=0)
Depending on what you are looking for, you may be interested by additional
statistics about extrema, which is provided by turnogram().
Best regards,
Philippe Grosjean
...........]<(({?<...............<?}))><...............................
( ( ( ( (
) ) ) ) ) Philippe Grosjean
( ( ( ( (
) ) ) ) ) IFREMER Nantes - DEL/AO
( ( ( ( ( rue de l'Ile d'Yeu, BP 21105, 44311 Nantes Cedex 3
) ) ) ) ) tel: (33) 02.40.37.42.29, fax: (33) 02.40.37.42.41
( ( ( ( (
) ) ) ) ) SciViews project coordinator (http://www.sciviews.org)
( ( ( ( ( e-mail: phgrosjean at sciviews.org
) ) ) ) )
( ( ( ( ( "I'm 100% confident that p is between 0 and 1"
) ) ) ) ) L. Gonick & W. Smith (1993)
.......................................................................
-----Message d'origine-----
De : owner-r-help at stat.math.ethz.ch
[mailto:owner-r-help at stat.math.ethz.ch]De la part de Witold Eryk Wolski
Envoy? : vendredi 26 juillet 2002 15:46
? : r-help at stat.math.ethz.ch
Objet : [R] Is there a function for finding local extrema.
I have a vector with about 100.000 values representing a quite regular
function (sinusoid like).
I would like to find all local maxima of this function (should be about
4000). Is there a native routine for R?
Thanks in advance
Eryk.
--
_|_ \|/ \|/ Eryk Witold Wolski tel :0049-(0)30-8413-1543 w w
?v? 'v? \'v'/ MPI Moleculare Genetik fax
:0049-(0)30-8413-1139 | |
/| |\/| |\ | | Mass Spectrometry Group http://www.molgen.mpg.de /.^.\
m m m m m m mail :wolski at molen.mpg.de /|\
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You could use either stop(), break, or return(), depending on what the
rest of your program looks like. For example:
x <- c(1:5, -6, 7:10) # say due to mis-typing
for (i in 1:10){
if(is.na(log(x[i]))==FALSE) print("OK")
else stop("Not OK check your values") }
}
-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng
On Sat, 27 Jul 2002, Adaikalavan Ramasamy wrote:
> This is probably some basic programming question. I am testing a
complicated
> and time consuming loops. I have also built in an internal check for the
> values, which prints something like OK or Not OK to the screen so that I
can
> see if anything has gone wrong.
>
> There errors are not logical errors so basically the loop runs to
> completion. Is there a way of forcing the loop to stop/exit immediately
when
> it first fails my internal check ?
>
> A simplified example follows:
>
> x <- c(1:5, -6, 7:10) # say due to mis-typing
>
> for (i in 1:10){
> { if(is.na(log(x[i]))==FALSE) print("OK")
> else print("Not OK check your values") }
> }
>
> The output of the above is "OK", .... , "Not OK check your
values", "OK",
> ...,"OK".
> So I want the loop to stop when the 6th value fails.
>
> This would save me a lot of time waiting for the loop to end just because I
> made an typing error.
> Many thanks.
>
> Adai.
>
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 26 Jul 2002 at 15:45, Witold Eryk Wolski wrote:> I have a vector with about 100.000 values representing a quite regular > function (sinusoid like). I would like to find all local maxima of > this function (should be about 4000). Is there a native routine for R? > Thanks in advance Eryk.function (series, span = 3) { z <- embed(series, span) s <- span%/%2 v <- max.col(z) == 1 + s result <- c(rep(FALSE, s), v) result <- result[1:(length(result) - s)] result } This function based on prof.Ripley's suggestion some time ago gives you logical vector identifying positions of peaks in time series (similar result like peaks in S+). It identifies as a peak a local maxima from n neighbour points where n is a span number.> > > -- > _|_ \|/ \|/ Eryk Witold Wolski tel :0049-(0)30-8413-1543 > w w ?v? 'v? \'v'/ MPI Moleculare Genetik fax > :0049-(0)30-8413-1139 | | > /| |\/| |\ | | Mass Spectrometry Group http://www.molgen.mpg.de > /.^.\ > m m m m m m mail :wolski at molen.mpg.de > /|\ > > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -.-.-.-.- r-help mailing list -- Read > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", > or "[un]subscribe" (in the "body", not the subject !) To: > r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _._._._._Petr Pikal petr.pikal at precheza.cz p.pik at volny.cz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._