tags:

views:

75

answers:

2

Hello,

I am trying to use xts as much as possible in my time series work as it seems to be the suggested way of doing things. However, I have getting a strange error.

CPI.NSA and INT are xts objects.

library(dynlm)
CPI.NSA.x <- CPI.NSA[dr1]
INT.x <- INT[dr1]

CPI.NSA.z <- as.zoo(CPI.NSA.x)
INT.z <- as.zoo(INT.x)

> dynlm(CPI.NSA.z ~ INT.z + L(CPI.NSA.z, 1))

Time series regression with "zoo" data:
Start = 1953-02-01, End = 1971-06-01

Call:
dynlm(formula = CPI.NSA.z ~ INT.z + L(CPI.NSA.z, 1))

Coefficients:
    (Intercept)            INT.z  L(CPI.NSA.z, 1)  
     -0.0006795        1.0440174       -0.0869050  


> dynlm(CPI.NSA.x ~ INT.x + L(CPI.NSA.x, 1))
Error in `[.xts`(a, match0(indexes, attr(a, "index")), , drop = FALSE) : 
  i is out of range

It was my understanding that whenever I have a function that takes zoo, I can pass it an xts and it should just work, but clearly that is not the case here.

What's going on?

Thanks for the help.

+1  A: 

You say

It was my understanding that whenever I have a function that takes zoo, I can pass it an xts and it should just work, but clearly that is not the case here.

and I am wondering if you think that zoo and xts are identical. They are not -- xts extends zoo in useful ways at the prices of limiting the index types to actual time or date objects (rather than arbitrary indices as for zoo).

Now, dynlm is written by Achim Zeileis who is one of the authors of zoo as I don't see why you can't keep your data in xts but then pass to zoo (via, e.g., as.zoo(foo)) when calling the dynlm functions.

There is no magic 'downcast'. But you can do it by hand. Which is what you are doing in the first part of your question. Ok?

Dirk Eddelbuettel
THanks for the clarification. That makes sense. I didn't think they were identical, but I wasn't clear on when they could or could not be interchanged.
stevejb
+1  A: 

the simple answer is that zoo and xts are not completely interchangeable, although sometimes they are.

This is a really good example of a time when they are not interchangeable.

JD Long