[R] time series questions?

Spencer Graves spencer.graves at pdf.com
Fri Feb 11 03:08:23 CET 2005


      Two time series questions: 

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(DF$x[-1], NA))
          ar1  intercept  c(DF$x[-1], NA)
      -0.3943    -0.2155           0.1185
s.e.   0.3454     0.8024           0.2464
sigma^2 estimated as 0.4889:  log likelihood = -10.7,  aic = 29.39
 > arima(DF$y, c(1,0,0), xreg=c(DF$x[-(1:2)], NA, NA))
          ar1  intercept  c(DF$x[-(1:2)], NA, NA)
      -0.2385    -0.6430                   0.2472
s.e.   0.3073     0.8592                   0.2485
sigma^2 estimated as 0.491:  log likelihood = -9.6,  aic = 27.2

      Is there a better way? 

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