skip to Main Content

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:
enter image description here

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):

enter image description here

5

Answers


  1. Try Acf (first letter is in upper-case) function in package “forecast”.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. Since you are using a tseries object, you need to pass coredata() to the ACF and PACF functions:

    acf(coredata(your_ts_object))
    pacf(coredata(your_ts_object))
    

    This will pass just the numerical values in the time series and won’t make a mess, giving you integer lags.

    Login or Signup to reply.
  4. I think you have to get the results from the acf() function then plot it in your own like this:

    storing acf results:

    a=acf(ts,plot = F)  #ts is an annual time series(frequency =12)
    

    plotting acf:

    plot(a$lag*12,a$acf,xlab="Lag",ylab="ACF",main="",type="h")
    

    note that you have to multiple the lag * frequency of your serie in this case 12.

    plotting horizontal lines:

    abline(h=c(-0.19,0,0.19),col=c("blue","black","blue"),lty=c(2,1,2))
    
    • h : to specify where to plot ths lines
    • col : for the colors of the lines
    • lty : to specify the type of the line

    that worked for me, i hope that’s what you locking for

    Login or Signup to reply.
  5. 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 set lag.max = 12*15.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search