dynlm 的 xts 问题
我尝试在时间序列工作中尽可能多地使用 xts,因为这似乎是建议的做事方式。但是,我遇到了一个奇怪的错误。
CPI.NSA 和 INT 是 xts 对象。
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
据我了解,每当我有一个需要 Zoo 的函数时,我都可以向它传递一个 xts,它应该可以正常工作,但显然这里的情况并非如此。
这是怎么回事?
感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你说
我想知道您是否认为
zoo
和xts
是相同的。它们不是 --xts
以有用的方式扩展了zoo
,但代价是将索引类型限制为实际时间或日期对象(而不是像zoo 那样的任意索引) )。
现在,
dynlm
是由 Achim Zeileis 编写的,他是zoo
的作者之一,因为我不明白为什么你不能将数据保存在xts< 中/code>,但在调用
dynlm
函数时传递给zoo
(例如,通过as.zoo(foo)
)。没有什么神奇的“沮丧”。但你可以手工完成。这就是您在问题的第一部分中所做的事情。好的?
You say
and I am wondering if you think that
zoo
andxts
are identical. They are not --xts
extendszoo
in useful ways at the prices of limiting the index types to actual time or date objects (rather than arbitrary indices as forzoo
).Now,
dynlm
is written by Achim Zeileis who is one of the authors ofzoo
as I don't see why you can't keep your data inxts
but then pass tozoo
(via, e.g.,as.zoo(foo)
) when calling thedynlm
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?
简单的答案是,zoo 和 xts 不能完全互换,尽管有时可以互换。
这是它们不可互换的时代的一个很好的例子。
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.