Make Causation the Goal for your Next Data Science Project
By: Andrew Plummer
Tags: Economics, Machine Learning, Data Science, Statistics, Math

Make Causation the Goal for your Next Data Science Project

A case study with money and interest rates

Photo by Sharon McCutcheon on Unsplash

Preamble

Forecasting is the goal for most data science projects.

While this has lead to some interesting work, it has also led to a disincentive to:

Understand the mathematics behind the machine learning models, Fully appreciate all aspects of the data analysis process; and, Build understandable models

The purpose for this article is to encourage more aspiring (and current) data scientists to finish projects that have causality as their stated goal.

Why?

Because persuading the reader that there is a causal relationship between X and Y is oftentimes more difficult than persuading the reader that a certain ML model has a strong predictive power, the latter of which is usually accomplished by minimizing (or maximizing, in some cases) an opaque metric.

A data scientist must prove the following points to persuade the reader that two variables are causally related:

Establish a time order. That is, if X causes Y, then X must come before Y. Establish a relationship between the variables. Our variables must be related. The relationship must not result from some third, confounding variable. Establish a causal theory. The data scientist must explain the causal relationship with an existing (or new) theory.

Meeting these conditions benefit the data scientist’s education in several ways:

They force the data scientist to understand the mathematics behind his model. You can’t just slap random models together until you get the results you want. You must explain how your model will answer your research question.

You can’t just slap random models together until you get the results you want. You must explain how your model will answer your research question. They improve the data scientist’s communication skills .

. They incentivize the data scientist to gain domain knowledge. Oftentimes, employers require the job applicant to have knowledge in a specific industry, in addition to technical skills.

For the remainder of this article, I will (try) to prove a causal relationship between interest rates and the money supply.

Specifically, I test two hypotheses:

1. A positive shock to a country’s money supply lowers the interest rates 2. Lower interest rates expand the economy in the short run

The hope here is that my attempt to prove a causal relationship between the money supply and interest rates will show you how to structure your next “causality-focused” data science project.

The rest of the article is split into the following segments:

Relationship Between the Money Supply and Interest Rates Explanation of the Model Explanation of the Data Analysis Results Conclusion

Feel free to jump to the part you find most interesting.

Relationship Between the Money Supply and Interest Rates

Keynes (yes, that Keynes) argues that the quantity of money demanded by consumers depends on the prevailing interest rate. Specifically, a lower interest rate means that consumers will demand more money

Image by author

Two effects shift the demand for money: an income effect and a price-level effect.

The income effect states that the demand for money increases when consumer wealth rises. That is, people want to buy more stuff when they have a higher net worth; and they demand more cash with which to buy said stuff.

The income effect leads to the price-level effect. Prices rise when spending rises (inflation). Therefore, people demand more money to maintain the purchasing power they had prior to the price increase.

Notice that the money supply curve is a vertical line. The vertical line means that money supply is exogenous.

In other words, the money supply is unaffected by movements in the market for money.

The theory holds that interest rates fall when the money supply increases (it shifts right in the above graph).

Why?

If the supply of money increases, then the economy has an excess of money. Consumers invest this excess into the bond market (where it is safe). This increases the demand for bonds, which thus increases the price of bonds. When the price of bonds increase, the interest rate (or yield) on that bond falls.

Image by author

Thus, the increase in the money supply causes interest rates to fall through the bond market. This phenomenon is called the liquidity effect.

We can model economic output as:

Image by author

When interest rates fall, debt becomes cheaper. Thus, consumption, investment, and government expenditure all increase, thereby increasing economic output.

Model

In order to prove the above theory, I need to test, first, the relationships among several variables (money supply, interest rates, and economic output), and, second, show that one variable (money supply shocks) comes before the other variables (interest rates and changes in economic output).

Thus, the model I use must show the interactions between (and among) multiple variables, and it must allow for dynamic behavior (dynamic behavior is when a model allows values from previous time periods to effect values in future time periods).

The Vector Autoregression (VAR) model is perfect for this!

VAR

Our VAR model looks like this:

Image by author

where

yt is a vector of dependent variables

Ai is a matrix of coefficients

X_(t-k) is a vector of independent variables, including a lagged order of the dependent variable

ut is a vector of errors

k is the length of the lag order

The VAR model is the linear regression model done on each variable we are studying. Every independent variable in one linear regression model gets to be a dependent variable in another linear regression model.

Thus, the VAR:

shows us multiple relationships between (and among) our variables; and,

allows for dynamic behavior with lag operators

Perfect!

Data

I focus on Canada for this analysis. Feel free to experiment with a different country.

I use quarterly data between 1970 and 2019 from Statistics Canada and the St. Louis FED. There are 200 observations.

The variables of interest are:

the growth rate in M1 (M1 is a narrow definition of money supply that includes the amount of money in demand deposits and checking accounts)

the yield on three-month treasury bills (commonly used to model interest rates)

the growth rate in real GDP

I control for:

the consumer price index (CPI)

the inflation rate

All growth rates are calculated as year-over-year percentage changes. The quarterly CPI and the yield on three-month treasury bills are calculated from taking quarterly averages of Statistic Canada’s monthly series.

Analysis

Before diving into the VAR, let’s take care of some data visualizations.

Specifically, we want to know:

Do changes in the money supply occur before or after changes in the interest rate?

library(readxl)

library(ggplot2)

library(zoo) data <- read_excel(file.choose(), sheet = 'Data') # Set the time variable

data$qrtr <- as.yearqtr(1970 + seq(0,199)/4) # Make a new theme for ggplot to use.

new_theme <- theme_classic() + theme(text = element_text(color = "darkred")) + theme(legend.position="top") + theme(legend.title = element_text(color = "black"), legend.text = element_text(color = "black"))

theme_set(new_theme) # Create the graph

p <- ggplot(data, aes(x = qrtr)) + ylim(-5, 30) + geom_line(aes(y = narrowmg, color = "M1 Growth Rate")) + geom_line(aes(y = stir, color = "Interest Rate")) + labs(x = "Quarter", y = "Growth Rate (%)", title = "Was Keynes Right?", subtitle = "1970 - 2019", caption = "Source: Statistics Canada")

p + theme(legend.title = element_blank())

Image by author

Prior to the mid-1980s, the relationship between changes in the money supply and changes in the interest rate is consistent. The relationship, of course, is imperfect, which means that other variables effect the interest rate.

Starting at least as early as 2000, changes in the money supply seem to have little effect on the interest rate. Indeed, although the money supply fluctuates considerably in this period, the interest rate remains negatively sloped.

What about the relationship between the GDP growth rate and the interest rate?

Image by Author

This relationship seems more consistent throughout the period of study than was the relationship between the interest rate and the money supply. Generally, drops in interest rates lead to increases in the GDP growth rate, and vice-versa.

The above visualizations cast considerable doubt on if changes in the money supply occur before changes in the interest rate (indeed, the opposite may be true). However, it does appear that changes in the interest rate occur before changes in the economic growth rate.

Also, we’ve established a theoretical explanation for how our variables are related.

Finally, we have to establish that our variables are related. More specifically, we must confirm that the relationship is not the result of some third, confounding variable.

This is the most difficult condition to satisfy.

I find that all variables are stationary after first differencing.

library(VARS)

library(tseries)

library(lmtest) # Use VARselect to find the optimal lag length for which to test for stationarity. VARselect(data$stir, lag.max = 20, type = "const")

VARselect(data$gdpg, lag.max = 20, type = "const")

VARselect(data$narrowmg, lag.max = 20, type = "const")

VARselect(data$inf, lag.max = 20, type = "const") # Run Adjusted Dickey-Fuller to test for stationarity. We find that # some of our variables are non-stationary. However, our variables

# are stationary after first-differencing. adf.test(data$stir, alternative = "stationary", k = 2)

adf.test(data$gdpg, k = 14, alternative = "stationary")

adf.test(data$narrowmg, k = 18, alternative = "stationary")

adf.test(data$inf, k = 10, alternative = "stationary")



# Find optimal lag length again.



VARselect(diff(data$stir), lag.max = 20, type = "const")

VARselect(diff(data$gdpg), lag.max = 20, type = "const")

VARselect(diff(data$narrowmg), lag.max = 20, type = "const")

VARselect(diff(data$inf), lag.max = 20, type = "const")

VARselect(diff(data$xrusd), lag.max = 20, type = "const")

# Conduct ADF test again.

adf.test(diff(data$stir), k = 1, alternative = "stationary")

adf.test(diff(data$gdpg), k = 13, alternative = "stationary")

adf.test(diff(data$narrowmg), k = 16, alternative = "stationary")

adf.test(diff(data$inf), k = 9, alternative = "stationary")

Next, we create a new data frame that holds the stationary variables. We then pass this data frame into the VARselect function to get the optimal lag length for the VAR.

Finally, we pass the new dataframe and the optimal lag length into the VAR function.

newdata <- data.frame(diff(data$gdpg), diff(data$narrowmg), diff(data$inf), diff(data$stir), diff(data$xrusd))

VARselect(newdata, lag.max = 20, type = "const") # Find optimal lag

varmodel <- VAR(newdata, p = 4, type = "const") # optimal lag is 4

Results

Recall our hypotheses.

First, we want to test if increases in the money supply decrease the interest rates.

Looking at the coefficients where the interest rate (stir) is the dependent variable:

Narrowmg is the growth rate in M1. The L1…L4 are the lag lengths. Only lags 2 and 4 are negatively related to the interest rate; moreover, lag 4 is not statistically significant.

However, we want to know if the lag lengths are jointly statistically significant.

We can use a Granger Causality test to test for joint statistical significance. The null hypothesis is that the variables are not jointly significant; the alternative hypothesis is that they are.

causality(varmodel, cause = "diff.data.narrowmg.")$Granger

According to the Granger causality test, we cannot reject the null hypothesis that changes in the money supply have zero predictive power for changes in the interest rate (or the other variables).

Here are the results of the linear model with the GDP growth rate as the dependent variable:

Image by author

Lags 2 to 4 for the interest rate variable (stir) have a negative coefficient. Thus, increases in the interest rate decreases economic growth.

Check if the lags on the interest rate are jointly significant:

causality(varmodel, cause = "diff.data.stir.")$Granger

Image by author

We can reject the null hypothesis that changes in the interest rate do not cause changes in economic growth or the other variables.

Interestingly, because changes in the interest are also predictive of changes in the money supply, we cannot disprove that changes in the interest rate come before changes in the money supply.

We should be cautious of hypothesis testing, however; p-values are not perfect.

Nevertheless, because the data visualizations from earlier suggested that changes in money supply were having zero effect on the interest rate, at least in the post-2000s, we can assume that the Granger causality test is accurate.

Conclusion

Admittedly, there are a few problems with the above project. For one thing, M1 may not be an accurate measure of the money supply; as well, the VAR may not have been the best model to test the relationship between two variables in equilibrium (interest rates and money supply).

That’s fine. The purpose of this article is to show you its benefits to your development as a data science.

Hopefully, you also learned some interesting stuff about money and interest rates!