getSymbols ("CPIAUCSL" , src = "FRED" , auto.assign = TRUE )
cpi_data <- tibble (date = index (CPIAUCSL), CPI = as.numeric (CPIAUCSL[,1 ])) %>%
arrange (date) %>%
mutate (inflation = 100 * (CPI / lag (CPI) - 1 )) %>%
mutate (Quarter = yearquarter (date)) %>%
as_tsibble (index = date) %>%
index_by (Quarter) %>%
summarize (CPI = mean (CPI),
inflation = mean (inflation))
# Get US unemployment (monthly)
getSymbols ("UNRATE" , src = "FRED" , auto.assign = TRUE )
us_unemp <- data.frame (date = index (UNRATE),
Unemployment = as.numeric (UNRATE$ UNRATE)) %>%
as_tsibble (index = date) %>%
mutate (Quarter = yearquarter (date)) %>%
index_by (Quarter) %>%
summarize (Unemployment = mean (Unemployment))
# Get US GDP (quarterly) and merge
getSymbols ("GDP" , src = "FRED" , auto.assign = TRUE )
us_gdp <- data.frame (date = index (GDP), GDP = as.numeric (GDP$ GDP)) %>%
as_tsibble (index = date) %>%
mutate (Quarter = yearquarter (date))
combined_data <- us_gdp %>%
inner_join (us_unemp, by = "Quarter" ) %>%
inner_join (cpi_data, by = "Quarter" ) %>%
mutate (GDP_growth = 100 * (GDP / lag (GDP) - 1 )) %>%
dplyr:: select (Quarter, date, GDP, GDP_growth, Unemployment, CPI, inflation) %>%
drop_na ()
# View the combined data
head (combined_data) %>% knitr:: kable ()
1948 Q2
1948-04-01
272.567
2.5682805
3.666667
23.99333
0.9141472
1948 Q3
1948-07-01
279.196
2.4320626
3.766667
24.39667
0.2905382
1948 Q4
1948-10-01
280.366
0.4190604
3.833333
24.17333
-0.4258609
1949 Q1
1949-01-01
275.034
-1.9017998
4.666667
23.94333
-0.1942711
1949 Q2
1949-04-01
271.351
-1.3391072
5.866667
23.91667
0.0139470
1949 Q3
1949-07-01
272.889
0.5667936
6.700000
23.71667
-0.2362540
# Chow test for structural breaks
break_test <- Fstats (inflation ~ GDP_growth + Unemployment + CPI, data = combined_data)
plot (break_test) # Identify potential breakpoints
# Estimate breakpoint date(s)
bp <- breakpoints (inflation ~ GDP_growth + Unemployment + CPI, data = combined_data)
combined_data$ Quarter[bp$ breakpoints]
<yearquarter[1]>
[1] "1981 Q3"
# Year starts on: January
# Fit segmented regression
segmented_model <- lm (inflation ~ GDP_growth + Unemployment + CPI,
data = combined_data,
subset = breakpoints (bp)$ breakpoints)
# Get breakpoint indices
bp_indices <- bp$ breakpoints
# Split data into segments
segments <- split (combined_data,
findInterval (1 : nrow (combined_data),
vec = c (0 , bp_indices)))
# Fit models to each segment
segment_models <- lapply (segments, function (df) {
lm (inflation ~ GDP_growth + Unemployment + CPI, data = df)
})
# Plot segmented regressions
ggplot (combined_data, aes (y = inflation, x= Quarter)) +
geom_point () +
geom_smooth (data = segments[[1 ]], method = "lm" , se = FALSE , color = "red" ) +
geom_smooth (data = segments[[2 ]], method = "lm" , se = FALSE , color = "blue" ) +
labs (title = "Segmented Regression by Breakpoints" )
3. Model Analysis
# Compare ETS components across regimes
ets_models %>%
compact () %>% # Remove NULL entries
map (~ components (.x) %>% autoplot () + labs (title = "ETS Decomposition" ))
arima_models %>%
compact () %>% .[[1 ]] %>% gg_tsresiduals ()
arima_models %>%
compact () %>% .[[2 ]] %>% gg_tsresiduals ()
# Compare VAR relationships
var_models %>%
compact () %>%
map (~ {
tibble (
Causality_GDP = causality (.x, cause = "GDP_growth" )$ Granger$ p.value,
Causality_Unemp = causality (.x, cause = "Unemployment" )$ Granger$ p.value
)
}) %>% knitr:: kable ()
5.203468e-06
6.306067e-14
Q: (Group Activity) What do these models tell us about different economic regimes before/after the breakpoints?
ETS
A: The analysis reveals three key regime shifts:
Volatility Changes (ETS):
Pre-break: Higher \(\alpha=0.605\) (rapid adjustment to new data)
Post-break: Lower \(\alpha=0.102\) (smoother evolution)
Implication: Inflation became more stable post-breakpoint
b. ARIMA
Structural Shifts (ARIMA):
Pre-break: Requires differencing (\(d=1\) ) with seasonal MA components
Post-break: Stationary (\(d=0\) ) with seasonal AR component
Implication: Fundamental change in inflation dynamics requiring different stabilization approaches
VAR
Causal Relationships (VAR):
Pre-break: Moderate Granger-causality (GDP→inflation p=0.017; Unemp→inflation p=0.005)
Post-break: Stronger causal links (GDP→inflation p=5.2e-6; Unemp→inflation p=6.3e-14)
Implication: Post-break economic indicators became more interconnected/predictive of inflation