[R] ARIMA (seasonal) backcasting & interpolation

Gabor Grothendieck ggrothendieck at gmail.com
Sat Aug 27 05:25:33 CEST 2005


On 8/26/05, David James <djames at frontierassoc.com> wrote:
> Thanks for everyone's help with zoo -- I think I've got my data set
> ready.  (The data consists of surface weather temperatures, from 2002
> to 2005, one observation per hour.  Some values are missing... i.e. NA)
>
> I have three goals:
>
> GOAL #1:Get the data in proper time series form, preserving frequency
> information:
> > w4.ts <- as.ts( w3.zoo, frequency=(1/3600) )
> I hope that 1/3600 (0.0002778) is correct.  I chose it because my
> zooreg object reported that value.  This goes back to my choice of
> the ISOdatetime format, which required deltat=3600.

I will just address the zoo portion of this question.

In the ts class, a period is a unit so lets assume we want the
resulting series to have a day represented as a unit.  Then
we first create a zoo series such that the integer part of the index
is a day and then converting that is easy:

regts.day <- zoo(coredata(regts.zoo), as.numeric(time(regts.zoo))/(24*3600))
regts.ts <- as.ts(regts.day)

or convert it to chron first in which case its easy too:

library(chron)
regts.chron <- zoo(coredata(regts.zoo), as.chron(time(regts.zoo)))
regts.ts <- as.ts(regts.chron)

Of course had chron been used in the first place just the last line
would be needed.

Note that there are some issues as to which time zone is being used
during conversion which I won't address but you can avoid that by just
using chron right from the beginning.  If you do use chron right from the
beginning you won't have the problem with daylight savings time, you
won't have the problem that the POSIXct and ts representations are very
different and you won't have the problem of worrying about time zones.




More information about the R-help mailing list