[R] time series questions (corrected)?

Spencer Graves spencer.graves at pdf.com
Fri Feb 11 03:18:19 CET 2005


## The following corrects what I believe to have been an error in my 
previous post:
####
      Two time series questions:

I.  FITTING TRANSFER FUNCTIONS WITH LAGS:  Consider the following toy 
example:

> dates <- paste(11:21, "/01/2005", sep="")
> Dates <- as.Date(dates, "%d/%m/%Y")
> set.seed(1)
> DF <- data.frame(date=Dates, y=rnorm(11), x=rnorm(11, 3))
> arima(DF$y, c(1,0,0), xreg=lag(DF$x, 1))
          ar1  intercept  lag(DF$x, 1)
      -0.3876    -1.1328        0.4280
s.e.   0.3556     0.6417        0.1945
sigma^2 estimated as 0.3807:  log likelihood = -10.38,  aic = 28.76
> arima(DF$y, c(1,0,0), xreg=lag(DF$x, 2))
          ar1  intercept  lag(DF$x, 2)
      -0.3876    -1.1328        0.4280
s.e.   0.3556     0.6417        0.1945
sigma^2 estimated as 0.3807:  log likelihood = -10.38,  aic = 28.76

****I NAIVELY THOUGHT THAT "lag" WOULD DO SOMETHING HERE.  Evidently, it
didn't.
****The following seems to work:

 > arima(DF$y, c(1,0,0), xreg=c(NA, DF$x[-11]))
           ar1  intercept  c(NA, DF$x[-11])
       -0.3994     0.3837           -0.0215
s.e.   0.3107     0.7366            0.2259
sigma^2 estimated as 0.5356:  log likelihood = -11.15,  aic = 30.31
 > arima(DF$y, c(1,0,0), xreg=c(NA, NA, DF$x[-(10:11)]))
           ar1  intercept  c(NA, NA, DF$x[-(10:11)])
       -0.5703     0.9180                    -0.1794
s.e.   0.3374     0.6685                     0.2115
sigma^2 estimated as 0.4871:  log likelihood = -9.73,  aic = 27.46

      Is there a better way?

II.  ASSOCIATING A CALENDAR DATE WITH A 'ts' OBJECT

      In the previous example, I'd like to convert x and y into "ts"
objects, retaining "Dates".  Is there a way to do this?  The following
did not work:

> ts(DF$y, start=Dates[1])
Error in Math.difftime((end - start) * frequency + 1.01) :
    floor not defined for difftime objects

      Thanks,
      spencer graves




More information about the R-help mailing list