[R] Finding seasonal peaks in a time series....
Mulholland, Tom
Tom.Mulholland at dpi.wa.gov.au
Thu Jan 13 04:20:18 CET 2005
Sorry I didn't read the question properly. Please disregard, my mind was elsewhere.
Tom
> -----Original Message-----
> From: Mulholland, Tom
> Sent: Thursday, 13 January 2005 10:52 AM
> To: Dr Carbon; r-help at stat.math.ethz.ch
> Subject: RE: [R] Finding seasonal peaks in a time series....
>
>
> You might find breakpoints in strucchange helpful
>
> Tom
>
> > -----Original Message-----
> > From: Dr Carbon [mailto:drcarbon at gmail.com]
> > Sent: Thursday, 13 January 2005 6:19 AM
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] Finding seasonal peaks in a time series....
> >
> >
> > I have a seasonal time series. I want to calculate the annual mean
> > value of the time series at its peak
> >
> > (say the mean of the three values before the peak, the
> peak, and the
> > three values after the peak).
> >
> > The peak of the time series might change cycle slightly from
> > year to year.
> >
> > # E.g.,
> > nPts <- 254
> > foo <- sin((2 * pi * 1/24) * 1:nPts)
> > foo <- foo + rnorm(nPts, 0, 0.05)
> > bar <- ts(foo, start = c(1980,3), frequency = 24)
> > plot(bar)
> > start(bar)
> > end(bar)
> >
> > # I want to find the peak value from each year, and then
> get the mean
> > of the values on either side.
> > # So, if the peak value in the year 1981 is
> > max.in.1981 <- max(window(bar, start = c(1981,1), end = c(1981,24)))
> > # e.g, cycle 7 or 8
> > window(bar, start = c(1981,1), end = c(1981,24)) == max.in.1981
> > # E.g. if the highest value in 1981 is in cycle 8 I want
> > mean.in.1981 <- mean(window(bar, start = c(1981,5), end =
> c(1981,11)))
> > plot(bar)
> > points(ts(mean.in.1981, start = c(1981,8), frequency = 24), col =
> > "red", pch = "+")
> >
> >
> > Is there a way to "automate" this for each year.
> >
> > How can I return the cycle of the max value by year?
> >
> > Thanks in advance. -DC
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list