BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kisumsam
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. 

 

temp1.png

 

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:

 

temp 2.png

 

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
stat_sas
Ammonite | Level 13

Hi,

 

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

 

Image result for autocorrelation formula

 

Please try this

 

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 

View solution in original post

3 REPLIES 3
Ksharp
Super User

this could approach your result.

 

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;
kisumsam
Quartz | Level 8

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:

 

temp 3.png

 

Do I have some misunderstanding on the definition of autocorrelation?

 

stat_sas
Ammonite | Level 13

Hi,

 

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

 

Image result for autocorrelation formula

 

Please try this

 

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 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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