[Time Series] ACF/PACF 자기상관/부분자기상관함수

자기상관 함수(ACF), 부분 자기상관 함수(PACF)의 개념과 그들의 플롯을 활용하는 방법을 정리합니다.

ACF/PACF 플롯은 차분된 시계열에 남아있는 자기 상관을 수정하기 위한 AR항 혹은 MA항이 필요한 지 결정하는 데 사용된다. 자기상관과 부분자기상관 관련 개념을 정리하고 플롯을 어떻게 활용하는 지 정리해보자.

ACF plot (Autocorrelation function plot)

  • ACF : correlation of the series with itself at different lags
    • 시계열의 시차간의 자기상관 계수에 대한 막대 차트
    • 시차 k에서의 Y의 자기상관 즉, Y와 LAG(Y,k)의 상관계수를 파악할 수 있다.

ACF 메소드

import matplotlib.pyplot as plt
import statsmodels.api as sm
import statsmodels.graphics.tsaplots as sgt
sgt.plot_acf(df.value, unbiased = True, zero = False, lags = 40) 
plt.title("ACF for Prices", size - 20) 
plt.show()
  • statsmodels.graphics.tsaplots 라이브러리
  • plot_acf : 자기상관함수 그래프 메소드
    • unbiased : Determines whether to include or ignore the n lags defined later
    • zero : Determines whether to include the current period value in the plot
    • lags : How many lags 얼마 시차까지 그래프에 나타낼 것인지

PACF plot (Partial autocorrelation plot)

  • PACF : the amount of autocorrelation at lag k that is not explained by lower-order autocorrelations
    • 시계열의 시차간의 부분상관계수에 대한 막대 차트
    • $k$보다 작은 차수 자기상관으로 설명되지 않는 시차 $k$에서의 자기상관계수를 알 수 있다.

Partial AutoCorrelation 부분자기상관

Partial Correlation 부분상관관계

두 변수 간의 partial correlation "부분적" 상관관계는 다른 변수 집합과의 상호 상관관계로 설명되지 않는 두 변수 간의 순수한 상관관계를 의미한다.

  • 예를 들어, $X_1,X_2,X_3$ 변수를 변수 $Y$를 회귀하는 경우, $Y$와 $X_3$ 간의 부분상관은 $X_1,X_2$와의 공통 상관으로 설명되지 않는 상관관계의 양을 의미한다.
  • $Y$와 $X_3$ 간의 부분상관은 $Y~X_1,X_2$회귀에 $X_3$를 추가해 얻은 분산의 감소의 제곱근으로 계산할 수 있다. square root of the reduction in variance

Partial AutoCorrelation 부분자기상관

부분자기상관은 all lower-order lags 보다 낮은 시차로는 설명되지 않는 예측값과 해당 시차의 자기상관 양을 의미한다.

  • 시차 1에서 시계열 $Y$의 자기상관은 $Y_t, Y_{t-1}$간의 상관계수이고, $Y_{t-1}, Y_{t-2}$간의 상관계수이기도 하다. 둘 다 상관관계가 있는 경우 (시차2의 자기상관)$Y, Y_{t-2}$간의 상관관계도 존재할 것이다. 이렇듯 시차 1의 자기상관이 보다 높은 시차로 propagates 전파된다. 즉, 시차 2에서의 부분 자기상관은 시차 2에서의 자기상관과 시차 1에서의 상관 전파로 인한 상관 간의 차이이다.
  • 시차 1의 상관관계가 일정한 경우, 시차2에서의 상관계수는 시차1에서의 상관계수의 제곱일 것이다.
  • 모든 시차에서의 부분자기상관은 AR 모델 피팅 과정에서 계산할 수 있는데, 시차 $k$에서의 부분자기상관은 $k$항이 있는 자기회귀모델에서 추정된 $AR(k)$의 계수와 동일하다.

PACF 메소드

import statsmodels.graphics.tsaplots as sgt 
sgt.plot_pacf(df.value, lags= 40, alpha = 0.05, zero = False, method = ( 'ols')) 
plt.title("PACF for Prices", size = 20) 
plt.show() 
  • statsmodels.graphics.tsaplots 라이브러리
  • plot_pacf 부분자기상관함수 그래프 메소드
    • alpha : significance level
    • method : method for calculating the coefficients

ACF & PACF 그래프의 활용


Reference&Source
plot_acf