R/时间序列:自相关函数 (acf) 的滞后单位是多少? [英] R / Time Series: What's the lag unit for autocorrelation function (acf)?

查看:121
本文介绍了R/时间序列:自相关函数 (acf) 的滞后单位是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XTS 时间序列对象,它在四年内的每个月的第一天显示一个值(代表整个月的总和).

I have an XTS time series object which shows a value on the first of each month (representing an aggregated sum for the whole month) during four years.

当我在其上运行 stats::acf() 函数时,我得到一个滞后(x 轴)单位为数十万的图.如果我的时间序列中只有 48 个值,那怎么可能呢?如果是时间单位,那是哪个,怎么改?

When I run the stats::acf() function on it, I get a plot with lag (x axis) units in the hundreds of thousands. How can that be if I only have 48 values in my time series? If it is a time unit, then which one, and how can I change it?

示例代码:

library(dplyr)
library(lubridate)
library(xts)

set.seed(100)

test <- data.frame(y = c(rep(2012, 12), rep(2013, 12), rep(2014, 12), rep(2015, 12)),
                   m = rep(seq(1, 12, 1), 4), d = rep(1, 48), value = runif(48, 0, 100))

test <- test %>%
  mutate(date = ymd(paste(y, m, d, sep = "-"))) %>% 
  select(date, value)

test <- xts(test$value, test$date)

acf(test)

推荐答案

从源代码我们看到我们可以这样计算滞后:

From the source code we see that we can calculate the lags like this:

sampleT <- as.integer(nrow(test))
nser <- as.integer(ncol(test))
lag.max <- floor(10 * (log10(sampleT) - log10(nser)))
x.freq <- frequency(test)
lag <- outer(0:lag.max, 1/x.freq)
#         [,1]
# [1,]       0
# [2,]   86400
# [3,]  172800
# [4,]  259200
# [5,]  345600
# [6,]  432000
# [7,]  518400
# [8,]  604800
# [9,]  691200
#[10,]  777600
#[11,]  864000
#[12,]  950400
#[13,] 1036800
#[14,] 1123200
#[15,] 1209600
#[16,] 1296000
#[17,] 1382400

时间单位是频率单位的倒数.要了解该值是如何计算的,您需要深入研究 frequency.zoo 的源代码,它做了一些我第一眼难以理解的事情.

The time unit is the reciprocal of the frequency unit. To understand how that value is calculated you need to dive into the source code of frequency.zoo, which does something I find difficult to understand at a first glance.

这篇关于R/时间序列:自相关函数 (acf) 的滞后单位是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆