[Rd] bug in acf (PR#9360)

aimcleod at uwo.ca aimcleod at uwo.ca
Mon Nov 13 16:30:14 CET 2006

Full_Name: Ian McLeod
Version: 2.3.1
OS: Windows
Submission from: (NULL) (

> There is a simple bug in acf as shown below:
> z <- 1
> acf(z,lag.max=1,plot=FALSE)
> Error in acf(z, lag.max = 1, plot = FALSE) :
>        'lag.max' must be at least 1
This is certainly a bug.

There are two problems:

(i) the error message is wrong since lag.max is set to 1.  Perhaps, if the
function acf can not be used for in this situaiton, a different error message
would be more appropriate.  I understand why this might be done but I don't
think it is the best approach.

(ii) Please look at the function GetB which is attached.  This is part a
computation for a fast algorithm for exact mle of mean.  Usually phi here are
the coefficients from a high order AR but when I tried for AR(1) I got the error
message.  So the workaround is given.  Notice that I use: 


so what I expect to get when p=length(phi)=1 is just phi^2.  This is what
happens in Mathematica with ListCorrelate[{phi},{phi}].  When you have
acf="correlation" and demean=TRUE then one gets 0/0 which should be defined as 1
in this situation.

Probably if the R authors just want to use acf for data analysis they may simply
choose to require length(x)>1 in acf(x,...) although I don't see the harm in my
suggestion either.

Ian McLeod

More information about the R-devel mailing list