I have a monthly time series. When I run the code acf(timeseries), the lags on the x axis show up as decimals instead of integers, as shown in the screenshot:
What is wrong? How could I have lags=c(1,2,3,4,5,6,etc) on the x-axis? I need something like this (photoshopped photo) (excuse the mis-alignment of values with ticks on the x-axis):
5
Answers
Try Acf (first letter is in upper-case) function in package “forecast”.
Perhaps it’s because you are using a non-desirable format for the acf/ccf function.
I faced the same problem and I solved it by changing the input vectors from time-series (ts) to numeric:
[variable]<-as.numeric([variable])
And it worked. I hope it helped.
Since you are using a
tseries
object, you need to passcoredata()
to the ACF and PACF functions:This will pass just the numerical values in the time series and won’t make a mess, giving you integer lags.
I think you have to get the results from the acf() function then plot it in your own like this:
storing acf results:
plotting acf:
note that you have to multiple the lag * frequency of your serie in this case 12.
plotting horizontal lines:
that worked for me, i hope that’s what you locking for
As the ts is monthly, so the yearly lag is divided into 12. The first figure is just a portion of the total ACF (i.e., for 1.5 years approx.). To have ACF for the full ts, use
acf(ts_object, lag.max = the max length of your ts_object)
. E.g., if you have 15 years monthly data, then setlag.max = 12*15
.