Quartz | Level 8

I have a quick question about how the autocorrelation is computed in the ACF plot and I'm hoping someone can help.

I have this simple data set:

``````data test;
input a b;
datalines;
1 .
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
;
run;``````

Basically, the test data has variable A and B. Variable B has the lagged value of A.

I'm trying to calculate the autocorrelation of A at lag 1. I read that, by definition, the autocorrelation of A at lag 1 is just the correlation of A with its own lagged value (which is B).

So I did a Proc Corr on A and B:

``````proc corr data=test;
var a b;
run;``````

This gets me the correlation of 1 which makes perfect sense.

I then plot the ACF plot for A using Proc Timeseries:

``````proc timeseries data=test plots=acf;
var a;
run;``````

I looked at the second bar in the plot which shows the autocorrelation at lag 1 and it is showing something close to 0.7 instead:

Am I doing the plot incorrectly? How come the ACF plot show an autocorrelation of 0.7 when it should be just 1?

1 ACCEPTED SOLUTION

Accepted Solutions
Ammonite | Level 13

## Re: Question about ACF plot

Hi,

Autocorrelation calculation is different from pearson correlation coefficient. Below is the formula for autocorrelation.

data test;
input a b;
datalines;
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 .
;
run;

proc sql;
select mean(a) into :average from test;
quit;

data want;
set test;
a1 = (a-&average);
a2 = (b-&average);
a3 = a1*a2;
a4 = (a-&average)**2;
run;

proc means data=want sum;
var a1 a2 a3 a4;
run;

r1 =  sum(a3)/sum(a4) = 0.7

3 REPLIES 3
Super User

## Re: Question about ACF plot

``````data test;
input a b;
datalines;
1 .
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
;
run;
proc reg data=test;
model b=a/noint;
quit;``````
Quartz | Level 8

## Re: Question about ACF plot

Hi I ran your code but I don't seem to get the right answer.

My question is that I think the autocorrelation between A and B is 1 because B is just a lagged value of A.

However, on the ACF plot, the autocorrelation at lag 1 is showing something close to 0.7:

Do I have some misunderstanding on the definition of autocorrelation?

Ammonite | Level 13

## Re: Question about ACF plot

Hi,

Autocorrelation calculation is different from pearson correlation coefficient. Below is the formula for autocorrelation.

data test;
input a b;
datalines;
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 .
;
run;

proc sql;
select mean(a) into :average from test;
quit;

data want;
set test;
a1 = (a-&average);
a2 = (b-&average);
a3 = a1*a2;
a4 = (a-&average)**2;
run;

proc means data=want sum;
var a1 a2 a3 a4;
run;

r1 =  sum(a3)/sum(a4) = 0.7

Discussion stats
• 3 replies
• 5367 views
• 4 likes
• 3 in conversation