我想了解如何從零開始計算自相關函數R
。如果有人指導我如何使用cor(x=y, y=lag(x=y, k=2))
獲得ACF
時,將非常感謝y
是ts
對象。我已經嘗試了use
參數[use = "complete.obs" # c("everything", "all.obs", "complete.obs", "na.or.complete", "pairwise.complete.obs")
]的所有選擇。由於從頭開始計算自相關函數R
set.seed(1)
y <-ts(data = rnorm(20), start = c(2010, 1), frequency = 4)
y
# Qtr1 Qtr2 Qtr3 Qtr4
# 2010 0.91897737 0.78213630 0.07456498 -1.98935170
# 2011 0.61982575 -0.05612874 -0.15579551 -1.47075238
# 2012 -0.47815006 0.41794156 1.35867955 -0.10278773
# 2013 0.38767161 -0.05380504 -1.37705956 -0.41499456
# 2014 -0.39428995 -0.05931340 1.10002537 0.76317575
acf(x=y, plot=FALSE)
# Autocorrelations of series ‘y’, by lag
#
# 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25
# 1.000 -0.122 -0.185 -0.049 0.147 -0.283 -0.255 0.212 0.097 -0.120 -0.181 0.286 -0.063 0.094
cor(
x = y
, y = lag(x=y, k=2)
, use = "complete.obs" # c("everything", "all.obs", "complete.obs", "na.or.complete", "pairwise.complete.obs")
)
# [1] 1
http://stackoverflow.com/a/32570260/3573401 – Khashaa