简体   繁体   中英

Why ACF not plotting lags

Hi does anyone know why my ACF is not plotting my lag max when for my time series? You can use the airpassenger data in R for this question.

My code is:

acf(z.t, lag.max = 40, main = expression(paste("acf of Z"[t])))

and I'm getting

这个

but want have 1-40 on the x-axis.

The data is a time series by month. Forty lags spans a range of 40 months, or 3.33 years. The time unit on the x-axis is denominated in years and you're seeing lags of 0 to 40 months in the graph.

As another example, if you run acf(AirPassengers, lag.max=12) you can see that the x-axis has lags from 0 to 12 months and the axis is labeled from zero to 1 year.

在此处输入图片说明

You can relabel the axis if you wish. For example:

mx=40
acf(AirPassengers, lag.max=mx, xaxt="n", xlab="Lag (months)")
axis(1, at=0:mx/12, labels=0:mx)

在此处输入图片说明

That's because the units of the axis are in seasonal units (periods), not time units.

frequency(AirPassengers) gives 12, so monthly. The axis in your plot goes to ~3.33, which is precisely 40 / 12.

You can get the values to generate your own plot from acf with x = acf(AirPassengers, lag.max = 40) and getting x$acf and x$lag .

You can also do:

library(forecast)
Acf(AirPassengers, lag.max = 40)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM