R语言真是博大精深
方法一
Acf(gold[,2], type = "correlation",lag.max = 100)
Acf(gold[,2], type = "partial")
方法二
library(ggfortify)
autoplot(acf(gold[,2], plot = FALSE))
方法三
bacf <- acf(gold[, 2], plot = FALSE)
bacfdf <- with(bacf, data.frame(lag, acf))
ggplot(data = bacfdf, mapping = aes(x = lag, y = acf)) +
geom_segment(mapping = aes(xend = lag, yend = 0)) +
geom_hline(aes(yintercept = 0.05), linetype = 2, color = 'darkblue')
# pacf
bpacf <- pacf(gold[, 2], plot = FALSE)
bpacf <- with(bpacf, data.frame(lag, acf))
ggplot(data = bpacf, mapping = aes(x = lag, y = acf)) +
geom_segment(mapping = aes(xend = lag, yend = 0)) +
geom_hline(aes(yintercept = 0.05), linetype = 2, color = 'darkblue')
方法四
library("forecast")
forecast::ggtsdisplay(gold[,2],lag.max=30)
方法五
ggAcf(gold[,2])
ggPacf(gold[,2])