[R] acf lag1 value

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jan 17 09:56:53 CET 2008


Please re-check your time-series books.  The acf at lag 1 is _not_ the 
correlation between x and lag(x).  For one thing, the variance of x is 
computed from the whole series, and not from the series with either the 
first or last value removed -- there is also the question of the divisor.

See MASS p.390 for the formulae used.


On Thu, 17 Jan 2008, Shubha Vishwanath Karanth wrote:

> Hi R,
>
>
>
> I have doubt.
>
>
>
>> x= c(4,5,6,3,2,4,5)
>
>> acf(x,plot=F,lag.max=1)
>
>
>
> Autocorrelations of series 'x', by lag
>
>
>
>    0     1
>
> 1.000 0.182
>
>
>
> But if I actually calculate the autocorrelation at lag1 I get,

Not the right formula.

>
>
>> cor(x[-1],x[-length(x)])
>
> [1] 0.1921538
>
>
>
> Even in excel I get 0.1921538 value. So, I want to know what the 'acf'
> function is calculating here....
>
>
>
> Thanks in advance,
>
> Shubha Karanth
>
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list