소비자 물가지수 시계열 예측 (초급 R)

초급 정량 분석 economic r
예상 소요 시간 50분 (간소화)
사전 지식 없음. R 기초, 시계열 개념
표본 크기 기준 월간 데이터 60개 이상 (최소 조건)
통계 가정 정상성, 관측치 독립성
난이도: 초급 — 입문자를 위한 간략화된 설명입니다.

개요

소비자 물가지수(CPI) 시계열 데이터에 ARIMA 모형을 적합하고 향후 12개월을 예측한다. R의 forecast 패키지를 사용하여 모형을 자동 선택하고 잔차 검정을 수행한다.

분석 절차

1단계: 정상성 확인

ADF 검정으로 시계열이 정상성을 만족하는지 확인한다. 비정상이면 차분을 수행한다.

2단계: ARIMA 모형 선택

auto.arima() 함수가 AICc 기준으로 최적의 ARIMA(p,d,q) 모형을 자동 선택한다.

3단계: 잔차 검정

checkresiduals()로 잔차가 백색잡음(White Noise)인지 확인한다. Ljung-Box 검정의 p-value가 0.05 이상이면 잔차에 자기상관이 없다.

4단계: 예측

forecast() 함수로 향후 12개월 CPI를 예측하고, 80% 및 95% 신뢰구간과 함께 시각화한다.

코드 예제

library(forecast)
library(tseries)

# 시계열 객체 생성
cpi_ts <- ts(data$cpi, frequency=12, start=c(2015,1))

# 정상성 검정
adf.test(cpi_ts)

# 차분
cpi_diff <- diff(cpi_ts)
adf.test(cpi_diff)

# ARIMA 모형 자동 선택
auto_model <- auto.arima(cpi_ts)
summary(auto_model)

# 잔차 검정
checkresiduals(auto_model)

# 12개월 예측
forecast_12 <- forecast(auto_model, h=12)
plot(forecast_12)
autoplot(forecast_12) + theme_minimal()

참고문헌

Hyndman, R. J., & Athanasopoulos, G. (2018). Forecasting: Principles and Practice (2nd ed.). OTexts.

학습 팁

이 방법론은 초급 수준입니다. 먼저 기초 통계 개념을 익힌 후 진행하세요. SPSS나 R의 기본 조작법을 숙지하면 더 수월합니다.

코드 예제

R
library(forecast) library(tseries) # 시계열 객체 생성 cpi_ts <- ts(data$cpi, frequency=12, start=c(2015,1)) # 정상성 검정 adf.test(cpi_ts) # 차분 cpi_diff <- diff(cpi_ts) adf.test(cpi_diff) # ARIMA 모형 자동 선택 auto_model <- auto.arima(cpi_ts) summary(auto_model) # 잔차 검정 checkresiduals(auto_model) # 12개월 예측 forecast_12 <- forecast(auto_model, h=12) plot(forecast_12) autoplot(forecast_12) + theme_minimal()

참고문헌

Hyndman, R. J., & Athanasopoulos, G. (2018). Forecasting: Principles and Practice (2nd ed.). OTexts.

이 방법론과 연결된 콘텐츠