AutoCorrelation Function - ACF

Author

Dr. Cohen

In practical problems, we do not start with a model, but with observed data \((x_1, x_2, \ldots , x_n)\). To assess the degree of dependence in the data and to select a model for the data, one of the important tools we use is the sample autocorrelation function (Sample ACF). A few remarks:

# Load packages
library(itsmr)
library(tidyverse)
library(tsibble)
library(feasts)

Sample AutoCorrelation Function Examples

USA population from 1790 - 1990

pop = read.table("http://users.stat.umn.edu/~kb/classes/5932/data/uspop.txt", 
                 header = FALSE)
# get data to tsibble format
pop = pop %>% 
  mutate(Year=seq(1790,1990,10), V1=V1/10^6) %>%
  as_tsibble(index = Year) 

# plot the time series
pop %>%
  autoplot(V1) + 
  labs(y="Population in millions")

# plot the ACF
pop %>%
  ACF(V1, lag_max = 20) %>%  
  autoplot()

acf(pop$V1,lag.max = 20)

IID Noise

w = rnorm(100,mean=0,sd=1)
acf(rnorm(100,mean=0,sd=1),lag.max = 100)

w = w %>% 
  as_tibble() %>%
  mutate(t=(1:100)) %>%
  as_tsibble(index = t)

w %>%
  autoplot(value)

w %>%
  ACF(value, lag_max = 100) %>% 
  autoplot()

acf(rnorm(100,mean=0,sd=1),lag.max = 100)

Monthly totals of international airline passengers 1949-1960

A = read.table("http://users.stat.umn.edu//~kb/classes/5932/data/airpass.txt", header = FALSE)

A = A %>% 
  as_tibble() %>%
  mutate(mth = rep(yearmonth("1949 Jan")+0:143)) %>%
  as_tsibble()

A %>%
  autoplot(V1) +
  labs(y="Total International of Airline Passengers")

A %>%
  ACF(V1, lag_max = 50) %>% 
  autoplot()

Monthly beer production, Australia in Megalitres - Jan. 1956 - Feb 1991

B <- read.table("http://users.stat.umn.edu/~kb/classes/5932/data/beer.txt",
                header = FALSE)

B = B %>% 
  select(V3) %>%
  as_tibble() %>%
  mutate(mth = rep(yearmonth("1956 Jan")+0:421)) %>%
  as_tsibble()

B %>%
  autoplot(V3) +
  labs(y="Monthly beer production, Australia in Megalitres")

B %>%
  ACF(V3, lag_max = 144) %>% 
  autoplot()

Theoretical ACF for MA(1) Time Series Model

The Moving Average model of order one is given:

\[ X_t = \theta Z_{t-1} + Z_t \] where \(Z_t \sim WN(0, \sigma^2)\)

We can show that the ACF \(\rho(h)\) of an MA(1) is:

\[ \rho(h) = \theta/(1+\theta^2) \text{ if } \qquad h=+/-1 \]

Simulate MA(1) data with \(\theta=0.8\)

theta= 0.8
# generate ACF for MA(0.8)
ACF_Theory = ARMAacf(ar =theta, lag.max = 20)
ACF_Theory
         0          1          2          3          4          5          6 
1.00000000 0.80000000 0.64000000 0.51200000 0.40960000 0.32768000 0.26214400 
         7          8          9         10         11         12         13 
0.20971520 0.16777216 0.13421773 0.10737418 0.08589935 0.06871948 0.05497558 
        14         15         16         17         18         19         20 
0.04398047 0.03518437 0.02814750 0.02251800 0.01801440 0.01441152 0.01152922 
# Plot ACF
plot((0:20),ACF_Theory,type="h", xlab = "Lag")

#1. Specify the Model using this function
modelMA1=specify(ar=theta, sigma2 = 1)
#2. generate MA observations with
datasim=sim(modelMA1,n = 100)

# Plot ACF
a=acf(datasim)

a

Autocorrelations of series 'datasim', by lag

     0      1      2      3      4      5      6      7      8      9     10 
 1.000  0.818  0.681  0.552  0.444  0.365  0.342  0.297  0.267  0.234  0.139 
    11     12     13     14     15     16     17     18     19     20 
 0.048 -0.032 -0.070 -0.121 -0.122 -0.159 -0.175 -0.142 -0.128 -0.101