Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Re: Question about ACF plot

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-25-2017 03:45 AM
(5156 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

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

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

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

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

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

**Don't miss out on SAS Innovate - Register now for the FREE Livestream!**

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

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.