Ryan Z Johnson
Ryan Z Johnson

Reputation: 91

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

this

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

Upvotes: 3

Views: 2666

Answers (2)

eipi10
eipi10

Reputation: 93811

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.

enter image description here

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)

enter image description here

Upvotes: 2

spinodal
spinodal

Reputation: 680

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)

Upvotes: 2

Related Questions