Um texto embutido e sem conjunto de caracteres especificado foi limpo... Nome: n?o dispon?vel Url: <https://stat.ethz.ch/pipermail/r-help/attachments/20121204/79784573/attachment.pl>
partial analisys of a time series
10 messages · R. Michael Weylandt, PIKAL Petr, arun +1 more
Hi
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Antonio Silva Sent: Tuesday, December 04, 2012 10:26 AM To: R-help at r-project.org Subject: [R] partial analisys of a time series Dear list members I want to analyze separately the months of a time series. In other words, I want to plot and fit models for each month separately. Taking the example of http://a-little-book-of-r-for-time- series.readthedocs.org/en/latest/src/timeseries.html births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat") birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) birthstimeseries plot.ts(birthstimeseries) birthstimeseriesHW <- HoltWinters(birthstimeseries) plot(birthstimeseriesHW) How to proceed the plotting and HoltWinters smoothing considereing only Januarys, Februarys, etc. separately.
Split your data by months to a list, use lapply. using zoo package blist <-split(birthstimeseries, months(as.Date(birthstimeseries))) l.blist <- lapply(blist, HoltWinters) Regards Petr
Thanks in advance. Antonio Olinto [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.
Um texto embutido e sem conjunto de caracteres especificado foi limpo... Nome: n?o dispon?vel Url: <https://stat.ethz.ch/pipermail/r-help/attachments/20121204/4fe85a06/attachment.pl>
Try period.apply() from the xts package. MW
On Tue, Dec 4, 2012 at 9:26 AM, Antonio Silva <aolinto.lst at gmail.com> wrote:
Dear list members I want to analyze separately the months of a time series. In other words, I want to plot and fit models for each month separately. Taking the example of http://a-little-book-of-r-for-time-series.readthedocs.org/en/latest/src/timeseries.html births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat") birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) birthstimeseries plot.ts(birthstimeseries) birthstimeseriesHW <- HoltWinters(birthstimeseries) plot(birthstimeseriesHW) How to proceed the plotting and HoltWinters smoothing considereing only Januarys, Februarys, etc. separately. Thanks in advance. Antonio Olinto [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121204/271b3142/attachment.pl>
HI, You can subset by: birthstimeseriesJan<-subset(birthstimeseries,cycle(birthstimeseries)==1) A.K. ----- Original Message ----- From: Antonio Silva <aolinto.lst at gmail.com> To: R-help at r-project.org Cc: Sent: Tuesday, December 4, 2012 4:26 AM Subject: [R] partial analisys of a time series Dear list members I want to analyze separately the months of a time series. In other words, I want to plot and fit models for each month separately. Taking the example of http://a-little-book-of-r-for-time-series.readthedocs.org/en/latest/src/timeseries.html births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat") birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) birthstimeseries plot.ts(birthstimeseries) birthstimeseriesHW <- HoltWinters(birthstimeseries) plot(birthstimeseriesHW) How to proceed the plotting and HoltWinters smoothing considereing only Januarys, Februarys, etc. separately. Thanks in advance. Antonio Olinto ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
HI, I am getting an error message: l.blist<-lapply(blist,HoltWinters) #Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : ?# time series has no or less than 2 periods A.K. ----- Original Message ----- From: PIKAL Petr <petr.pikal at precheza.cz> To: Antonio Silva <aolinto.lst at gmail.com>; "R-help at r-project.org" <R-help at r-project.org> Cc: Sent: Tuesday, December 4, 2012 5:07 AM Subject: Re: [R] partial analisys of a time series Hi
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Antonio Silva Sent: Tuesday, December 04, 2012 10:26 AM To: R-help at r-project.org Subject: [R] partial analisys of a time series Dear list members I want to analyze separately the months of a time series. In other words, I want to plot and fit models for each month separately. Taking the example of http://a-little-book-of-r-for-time- series.readthedocs.org/en/latest/src/timeseries.html births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat") birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) birthstimeseries plot.ts(birthstimeseries) birthstimeseriesHW <- HoltWinters(birthstimeseries) plot(birthstimeseriesHW) How to proceed the plotting and HoltWinters smoothing considereing only Januarys, Februarys, etc. separately.
Split your data by months to a list, use lapply. using zoo package blist <-split(birthstimeseries, months(as.Date(birthstimeseries))) l.blist <- lapply(blist, HoltWinters) Regards Petr
Thanks in advance. Antonio Olinto ??? [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi, If the frequency is >1, the error message will? be gone. For e.g. birthstimeseriesJanFeb<-subset(birthstimeseries,cycle(birthstimeseries)==c(1,2)) ?birthstimeseriesJanFeb1<-ts(birthstimeseriesJanFeb,frequency=2,start=c(1946,1)) ?plot.ts(birthstimeseriesJanFeb1) ?birthstimeseriesJanFebHW<-HoltWinters(birthstimeseriesJanFeb1) ?plot(birthstimeseriesJanFebHW) A.K. ----- Original Message ----- From: Antonio Silva <aolinto.lst at gmail.com> To: PIKAL Petr <petr.pikal at precheza.cz> Cc: "R-help at r-project.org" <R-help at r-project.org> Sent: Tuesday, December 4, 2012 5:50 AM Subject: Re: [R] partial analisys of a time series Thanks Petr I thought there might be an equivalent for birthstimeseries[,1] if it were a dataframe, but split function sounds great. I could not reproduce the second line of your suggestion "l.blist <- lapply(blist, HoltWinters)". I receive the message: Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time series has no or less than 2 periods What could be going wrong? Best regards Antonio 2012/12/4 PIKAL Petr <petr.pikal at precheza.cz>
Hi
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Antonio Silva Sent: Tuesday, December 04, 2012 10:26 AM To: R-help at r-project.org Subject: [R] partial analisys of a time series Dear list members I want to analyze separately the months of a time series. In other words, I want to plot and fit models for each month separately. Taking the example of http://a-little-book-of-r-for-time- series.readthedocs.org/en/latest/src/timeseries.html births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat") birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) birthstimeseries plot.ts(birthstimeseries) birthstimeseriesHW <- HoltWinters(birthstimeseries) plot(birthstimeseriesHW) How to proceed the plotting and HoltWinters smoothing considereing only Januarys, Februarys, etc. separately.
Split your data by months to a list, use lapply. using zoo package blist <-split(birthstimeseries, months(as.Date(birthstimeseries))) l.blist <- lapply(blist, HoltWinters) Regards Petr
Thanks in advance. Antonio Olinto ? ? ? [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.
Ant?nio Olinto ?vila da Silva Bi?logo / Ocean?grafo Instituto de Pesca (Fisheries Institute) S?o Paulo, Brasil ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Um texto embutido e sem conjunto de caracteres especificado foi limpo... Nome: n?o dispon?vel Url: <https://stat.ethz.ch/pipermail/r-help/attachments/20121204/ef54b9a9/attachment.pl>
Hi,
In addition, you can also subset using:
births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat")
birthstimeseries <- ts(births, frequency=12, start=c(1946,1))
library(xts)
birthstimeseriesxts<-as.xts(birthstimeseries)
birthstsJanFeb<-birthstimeseriesxts[format(time(birthstimeseriesxts),"%b")==c("Jan","Feb")]
birthstsJanFeb1<-ts(birthstsJanFeb,frequency=2,start=c(1946,1))
?plot.ts(birthstsJanFeb1)
birthstsJanFebHW<-HoltWinters(birthstsJanFeb1)
?plot(birthstsJanFebHW)
A.K.
From: Antonio Silva <aolinto.lst at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>; PIKAL Petr <petr.pikal at precheza.cz>
Sent: Tuesday, December 4, 2012 8:13 PM
Subject: Re: [R] partial analisys of a time series
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>; PIKAL Petr <petr.pikal at precheza.cz>
Sent: Tuesday, December 4, 2012 8:13 PM
Subject: Re: [R] partial analisys of a time series
Hi all Thanks for the attention and answers. I learned a lot I now I can go on my work. I also tryed to you de command window(). I thought it would be possible to select one column of an ts object, like we can do with a data.frame (plot(data[,2],data[,3]), to work. But as I saw we need to extract the values and create another ts. Thanks very much. All the best. Antonio 2012/12/4 arun <smartpink111 at yahoo.com> Hi, >If the frequency is >1, the error message will? be gone. >For e.g. >birthstimeseriesJanFeb<-subset(birthstimeseries,cycle(birthstimeseries)==c(1,2)) >?birthstimeseriesJanFeb1<-ts(birthstimeseriesJanFeb,frequency=2,start=c(1946,1)) >?plot.ts(birthstimeseriesJanFeb1) >?birthstimeseriesJanFebHW<-HoltWinters(birthstimeseriesJanFeb1) >?plot(birthstimeseriesJanFebHW) > >A.K. > > > > >----- Original Message ----- > >From: Antonio Silva <aolinto.lst at gmail.com> >To: PIKAL Petr <petr.pikal at precheza.cz> >Cc: "R-help at r-project.org" <R-help at r-project.org> >Sent: Tuesday, December 4, 2012 5:50 AM >Subject: Re: [R] partial analisys of a time series > >Thanks Petr > >I thought there might be an equivalent for birthstimeseries[,1] if it were >a dataframe, but split function sounds great. > >I could not reproduce the second line of your suggestion "l.blist <- >lapply(blist, HoltWinters)". I receive the message: Error in >decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time >series has no or less than 2 periods > >What could be going wrong? > >Best regards > >Antonio > > >2012/12/4 PIKAL Petr <petr.pikal at precheza.cz> > >> Hi >> >> > -----Original Message----- >> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- >> > project.org] On Behalf Of Antonio Silva >> > Sent: Tuesday, December 04, 2012 10:26 AM >> > To: R-help at r-project.org >> > Subject: [R] partial analisys of a time series >> > >> > Dear list members >> > >> > I want to analyze separately the months of a time series. In other >> > words, I want to plot and fit models for each month separately. >> > >> > Taking the example of >> > http://a-little-book-of-r-for-time- >> > series.readthedocs.org/en/latest/src/timeseries.html >> > >> > births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat";) >> > birthstimeseries <- ts(births, frequency=12, start=c(1946,1)) >> > birthstimeseries >> > plot.ts(birthstimeseries) >> > birthstimeseriesHW <- HoltWinters(birthstimeseries) >> > plot(birthstimeseriesHW) >> > >> > How to proceed the plotting and HoltWinters smoothing considereing only >> > Januarys, Februarys, etc. separately. >> >> Split your data by months to a list, use lapply. >> >> using zoo package >> >> blist <-split(birthstimeseries, months(as.Date(birthstimeseries))) >> l.blist <- lapply(blist, HoltWinters) >> >> Regards >> Petr >> >> >> >> >> >> > >> > Thanks in advance. >> > >> > Antonio Olinto >> > >> >? ? ? ?[[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help at r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide http://www.R-project.org/posting- >> > guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > > > >-- >Ant?nio Olinto ?vila da Silva >Bi?logo / Ocean?grafo >Instituto de Pesca (Fisheries Institute) >S?o Paulo, Brasil > >??? [[alternative HTML version deleted]] > > >______________________________________________ >R-help at r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. > >
Ant?nio Olinto ?vila da Silva Bi?logo / Ocean?grafo Instituto de Pesca (Fisheries Institute) S?o Paulo, Brasil