[R] ts startdate

Dirk Eddelbuettel edd at debian.org
Fri Dec 6 16:08:03 CET 2002


> I am facing a trivial problem when trying to parameterise the start date
> of a time series object. I am working with monthly data (104) performing
> n-steps-ahead (6) forecasts and using a fixed window size (36). At the
> end of calculations I have a list  that contains 69 forecasts.
> I have no problems in fixing the window size by parametrization, e.g.
> 
> k<- control variable in a for loop
> my.length<-36
> past<-window(X,start=c(1980,k - my.length + 1),end=c(1980,k))
> 
> The integer defining the month number can be arbitrary set to: 6,16,46
> etc and it always works. This, however, does not work when I try to
> parameterise the start date of the result list
> 
> my.forecasts<-unlist(my.result.list) 
> my.forecast.results<-ts(my.forecasts,start=c(1980,my.length+6),frequency
> =12)
> 
> The message I recive is:
> 
> Error in ts(my.frecasts, start = c(1980, my.length + 6), frequency = 12)
> : 
>         invalid start
> 
> It seems that it works only for month integer up to 12. Does someone
> know how to overcome this problem?

I typically use offsets relative to tsp() output which is already in the
fractional format of year + 1/12*(months-1) whereas using the c(year,month)
notation has wrap-around issues.

The following (contrived) example works:

> Zbase<-ts(rnorm(110),start=c(1993,1),frequency=12)
> tsp(Zbase)
[1] 1993.000 2002.083   12.000
> for (i in 1:24) Zfcast<-ts(rnorm(110),start=tsp(Zbase)[2]+i/12,frequency=12)
> 

With that construct you can go any number of month past, or prior, a given
date.

Hope this helps,  Dirk

-- 
According to the latest figures, 43% of all signatures are totally worthless.




More information about the R-help mailing list