dynlm 的 xts 问题

发布于 2024-09-02 00:01:02 字数 796 浏览 4 评论 0原文

我尝试在时间序列工作中尽可能多地使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春庭雪 2024-09-09 00:01:02

你说

据我了解,每当
我有一个需要动物园的功能,我
可以给它一个 xts,它应该只是
工作,但显然情况并非如此
在这里。

我想知道您是否认为 zooxts 是相同的。它们不是 -- xts 以有用的方式扩展了 zoo,但代价是将索引类型限制为实际时间或日期对象(而不是像 zoo 那样的任意索引) )。

现在,dynlm 是由 Achim Zeileis 编写的,他是 zoo 的作者之一,因为我不明白为什么你不能将数据保存在 xts< 中/code>,但在调用 dynlm 函数时传递给 zoo(例如,通过 as.zoo(foo))。

没有什么神奇的“沮丧”。但你可以手工完成。这就是您在问题的第一部分中所做的事情。好的?

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?

宫墨修音 2024-09-09 00:01:02

简单的答案是,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文