Author: “Emmanuel Kwame Tettey” date: “2024-12-12” output: html_document
As a part of the coursework requirements for *Pompea College of Business, University of New Haven this work was done to help apply knowledge from the Business Forecasting class. Emmanuel Kwame Tettey is the author and enjoy some tit bits highlighted in certain aspects of the US economy.
The economic outlook in every given region of the world is premised on the nature of some market players and indicators that also helps in the determination of future performances based on observable trends in these some elements and how they impact each other. This piece sought to create a diffusion index for the United States economy using some randomly chosen three economic indicators: Unemployment Rate (UNRATE), Consumer Price Index (CPIAUCSL), and Consumer Sentiment (UMCSENT).
Diffusion indexes are used to measure economic activities and aggregate diverse signals into a single value that helps in reading meaningful insights into observable trends and turning points.
Gathering the data used in this analysis from FRED (Federal Reserve Economic Data) https://fred.stlouisfed.org/ , the diffusion index created was based on:
The inspiration for selecting these three indexes is that, unemployment rates can influence one’s disposable income which also reflects in how much money a person is willing to spend or save based on the prevailing inflation rate of goods and services in a given market; all things being equal. The goal is to analyze and compare trends in the Chicago Fed National Activity Index (CFNAI) with the three other economic indicators mentioned earlier. The CFNAI, a composite measure of national economic activity, helps in identifying economic growth trends and potential recessions.
The data for the diffusion index was created using the following lines of code in R progaming.
#
options(digits = 3, scipen = 99999)
remove(list = ls())
graphics.off()
# Installing the neede packages
suppressWarnings({
suppressPackageStartupMessages({
library(markovchain)
library(tidyverse)
library(quantmod)
library(tsbox)
library(vars)
library(tsibble)
library(zoo)
})
})
# Load the necessary economic data
getSymbols(c("UNRATE", "CPIAUCSL", "UMCSENT", "CFNAIDIFF"),
freq = "monthly",
src = "FRED", return.class = 'xts',
index.class = 'Date',
from = "2010-01-01",
to = "2024-09-01",
periodicity = "monthly")
## [1] "UNRATE" "CPIAUCSL" "UMCSENT" "CFNAIDIFF"
# Extracting data
ur = UNRATE
cpi = CPIAUCSL
csi = UMCSENT
cfnaidiff = CFNAIDIFF
# Select the common date range
ur_s <- ur["2010-01-01/2024-09-01"] |> ts_ts()
cpi_s <- cpi["2010-01-01/2024-09-01"] |> ts_ts()
csi_s <- csi["2010-01-01/2024-09-01"] |> ts_ts()
cfnaidiff_s <- cfnaidiff["2010-01-01/2024-09-01"] |> ts_ts()
# Combine all the data into one data frame
mydata = cbind.data.frame(ur_s, cpi_s, csi_s, cfnaidiff_s)
head(mydata, 3)
## ur_s cpi_s csi_s cfnaidiff_s
## 1 9.8 217 74.4 0.05
## 2 9.8 217 73.6 -0.09
## 3 9.9 217 73.6 0.09
# Obtain first differences for the economic indicators
mydf = mydata %>%
mutate(urD1 = tsibble::difference(ur_s, differences = 1),
cpiD1 = tsibble::difference(cpi_s, differences = 1),
csiD1 = tsibble::difference(csi_s, differences = 1)) %>%
dplyr::select(c(urD1, cpiD1, csiD1)) |>
na.omit()
# Convert to up or down (1 for positive, -1 for negative)
mydf_df = ifelse(mydf > 0, 1, -1)
table(mydf_df)
## mydf_df
## -1 1
## 245 283
# Convert to up, down, or no change
mydf_mat = apply(mydf, 2, sign)
table(mydf_mat)
## mydf_mat
## -1 0 1
## 202 43 283
# Calculate the number of positive and negative changes
pos = apply(mydf_mat, 1, function(row) sum(row > 0))
neg = apply(mydf_mat, 1, function(row) sum(row < 0))
# Total changes
tot = pos + neg
# Calculate the Diffusion Index
index = (pos / tot - neg / tot) * 100
table(index)
## index
## -100 -33.3333333333333 0 33.3333333333333
## 8 50 21 61
## 100
## 36
# Apply a 7-month moving average to smooth the Diffusion Index
ma_index = zoo::rollmean(index, 7, align = "right")
length(index)
## [1] 176
# Plot the Diffusion Index with a rolling mean
plot(index[8:175], type = "l", main = "Diffusion Index for the US Economy",
xlab = "Months", ylab = "Diffusion Index", col = "darkblue")
abline(a = 0, b = 0, col = "darkred")
lines(ma_index, col = "darkred", lwd = 2.5)
The Diffusion Index for the US Economy shown in the graph demonstrates trends in economic activity over time. Here’s an interpretation of the index and the correlation with the Chicago Fed National Activity Index Diffusion Index (CFNAIDIFF):
The Diffusion Index (blue line) fluctuates significantly, with values oscillating between approximately -100 and 100. While the fluctuations are frequent, the red line (smoothed trend or moving average) reveals that the long-term average tends to hover near zero, indicating an overall balance between improving and weakening indicators over time. Periods where the index is positive indicate that a greater share of economic indicators are showing growth or improvement, whereas periods with negative values reflect broad-based economic weakness. The spikes and dips suggest volatility, signaling economic components performing unevenly.
# To sure that the `index` and `cfnaidiff_s` are aligned correctly.
# Ensure the length of both series matches by trimming the longer one or adjusting the indices
index_length <- length(index)
cfnaidiff_s_trimmed <- cfnaidiff_s[1:index_length] # Adjust CFNAIDIFF to match the length of the index
# Now, calculate the correlation coefficient
correlation <- cor(index, cfnaidiff_s_trimmed, use = "complete.obs")
# Print the correlation
correlation
## [1] -0.0223
The correlation coefficient between the Diffusion Index and the Chicago Fed National Activity Index Diffusion Index (CFNAIDIFF) is -0.0223. This value indicates a very weak negative correlation. Here’s what this means:
A correlation of -0.0223 is very close to zero, meaning there is essentially no meaningful linear relationship between the two indices. While both indices measure broad economic activity, their movements do not align consistently. For example: When the CFNAIDIFF rises or falls, the Diffusion Index does not show a predictable or consistent direction. The weak negative sign suggests a slight tendency for one index to fall when the other rises, but the effect is negligible.
# Create a data frame with both indices for plotting
Date = seq.Date(from = as.Date("2010-05-01"), length.out = index_length, by = "month")
comparison_data <- data.frame(Date = Date,
Index = index,
CFNAIDIFF = cfnaidiff_s_trimmed)
# Reshape the data into a long format for ggplot2
comparison_long <- comparison_data %>%
gather(key = "Series", value = "Value", Index, CFNAIDIFF)
# Create a ggplot with side-by-side comparison using facet_wrap
ggplot(comparison_long, aes(x = Date, y = Value, color = Series)) +
geom_line(size = 1) +
facet_wrap(~ Series, scales = "free_y", ncol = 2) + # Facet side by side
labs(title = "Comparison of Diffusion Index and CFNAIDIFF",
x = "Date",
y = "Index Value") +
scale_color_manual(name = "Index", values = c("blue", "red")) + # Color each series differently
theme_minimal() +
theme(axis.line.x = element_line(size = 0.75, colour = "black"),
axis.line.y = element_line(size = 0.75, colour = "black"))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
The two indices in the plot compare the Diffusion Index (in red, labeled “Index”) and the CFNAIDIFF (Chicago Fed National Activity Index Diffusion Index, in blue). Here’s what the graph suggests about the current situation (toward the right of the graph):
CFNAIDIFF (left plot in blue): The CFNAIDIFF shows negative values most recently (around 2024–2025). This indicates that economic activity has weakened or slowed down, as values below zero suggest below-trend growth. The downward movement toward the end reflects increased instability or slowing of the overall economic trends.
Diffusion Index (right plot in red): The Diffusion Index is also highly volatile with significant negative dips alongside frequent oscillations. This suggests that many indicators in the dataset may show inconsistent or worsening economic conditions. The negative shifts imply broad-based economic weaknesses in specific components, supporting the slowing signal seen in CFNAIDIFF.
The two indices might measure economic trends using different sets of data or methodologies, leading to this lack of alignment. Diffusion Index (Graph): Measures the proportion of economic indicators improving versus worsening, showing broad-based trends.
CFNAIDIFF: Measures economic activity relative to its historical trend, potentially capturing a different dimension of economic health. Short-term noise or volatility in the indices could also reduce the strength of the relationship, as seen by the sharp oscillations in the graph.
The three indicators fit very well into the analysis of the Diffusion Index. Their inclusion enhances the robustness of the index by covering labor markets, inflationary pressures, and consumer behavior—key drivers of the economy. However, it’s important to account for their limitations (example, lagging nature of unemployment data or noise in sentiment) and consider them alongside other indicators for a more comprehensive analysis.
The Diffusion Index for the US Economy suggests volatility but a long-term balance near zero. The weak negative correlation of -0.0223 with the CFNAIDIFF indicates that the two indices do not move together in any consistent pattern. This highlights that while both indices assess economic performance, they do so using different frameworks or data sets.
Both indices align in indicating a slowing economy or below-trend growth. The CFNAIDIFF consistently showing negative values suggests overall weakness, while the Diffusion Index’s volatility suggests economic uncertainty or mixed signals across various components.