Tam denklem şurada verilmiştir: Venables, WN ve Ripley, BD (2002) S. Fourth Edition ile Modern Uygulamalı İstatistik. Springer-Verlag. Size bir örnek vereceğim:
### simulate some data with AR(1) where rho = .75
xi <- 1:50
yi <- arima.sim(model=list(ar=.75), n=50)
### get residuals
res <- resid(lm(yi ~ xi))
### acf for lags 1 and 2
cor(res[1:49], res[2:50]) ### not quite how this is calculated by R
cor(res[1:48], res[3:50]) ### not quite how this is calculated by R
### how R calculates these
acf(res, lag.max=2, plot=F)
### how this is calculated by R
### note: mean(res) = 0 for this example, so technically not needed here
c0 <- 1/50 * sum( (res[1:50] - mean(res)) * (res[1:50] - mean(res)) )
c1 <- 1/50 * sum( (res[1:49] - mean(res)) * (res[2:50] - mean(res)) )
c2 <- 1/50 * sum( (res[1:48] - mean(res)) * (res[3:50] - mean(res)) )
c1/c0
c2/c0
Ve böyle devam (örn res[1:47]
ve res[4:50]
gecikme 3).
R
formülü daha da analiz edilir ve stats.stackexchange.com/questions/81754/… adresinde açıklanır .