Zooreg频率警告

Zooreg frequency warning

假设我有以下一组数据:

date <- structure(c(1986, 1986.08333333333, 1986.16666666667), class = "yearmon")

return <- structure(c(0.000827577426231287, 0.00386371801344005, 0.00382634819565989
), .Dim = 3L, .Dimnames = list(c("1986-01", "1986-02", "1986-03"
)))

我使用以下方法将 return array 转换为 zoo/zooreg 对象:

zooreg(return, order.by = date)

它提供了带有警告的正确输出:

 Jan 1986     Feb 1986     Mar 1986 
0.0008275774 0.0038637180 0.0038263482 

Warning message: In zoo(data, order.by, frequency) : “order.by” and “frequency” do not match: “frequency” ignored

该系列是严格规则的,order.byfrequency 应该匹配,但我仍然不明白为什么会有警告。

根据文档 (?yearmon):

The "yearmon" class is used to represent monthly data. Internally it holds the data as year plus 0 for January, 1/12 for February, 2/12 for March and so on in order that its internal representation is the same as ts class with frequency = 12.

通话中:

zooreg(return, order.by = date)

相当于调用

zoo(return, order.by = date, frequency = 1)

根据 Arguments::frequencyzoo 的文档:

If specified, it is checked whether order.by and frequency comply.

因此警告。要消除警告,请使用

z <- zooreg(return, order.by = date, frequency = 12)

z <- zoo(return, order.by = date, frequency = 12)

这两个都将 return class 的对象 zooreg:

str(z)
‘zooreg’ series from Jan 1986 to Mar 1986
  Data: Named num [1:3] 0.000828 0.003864 0.003826
 - attr(*, "names")= chr [1:3] "1986-01" "1986-02" "1986-03"
  Index: Class 'yearmon'  num [1:3] 1986 1986 1986
  Frequency: 12 

根据文档 (?zoo),

This is a subclass of "zoo" which relies on having a "zoo" series with an additional "frequency" attribute (which has to comply with the index of that series)

我相信这就是你想要的。

请注意,调用不匹配的 "order.by" 和 "frequency" 使用

z <- zooreg(return, order.by = date)

你只得到一个 zoo 对象:

str(z)
‘zoo’ series from Jan 1986 to Mar 1986
  Data: Named num [1:3] 0.000828 0.003864 0.003826
 - attr(*, "names")= chr [1:3] "1986-01" "1986-02" "1986-03"
  Index: Class 'yearmon'  num [1:3] 1986 1986 1986