Visualising the Effect of Interaction Variables in Logistic Regression

A Learning Tool

Taiki Sakai
Top Secret Astronaut

Introduction

The purpose of this shiny app is to allow students to visualise the effect that an interaction term can have on a logistic regression. Interaction terms are often added to regression, but it can be difficult to understand exactly what they are doing. The app is intended as a learning tool to help students better understand how an interaction term will effect their regression model.

Basic Logistic Regression

plot of chunk unnamed-chunk-2

Recall that in basic logistic regression, our model takes the form of \(log(odds) = a + bx\). The graph on the left above shows the probability of a positive result when our model is \(log(odds) = 3+0.5x\). The graph on the right shows the result when our model is changed to \(log(odds) = -1 + 2x\). The result of this change is easy for students to understand because it is the same as the change when graphing a regular line. Increasing the x coefficient increases the slope, and changing the intercept term shifts the graph.

Logistic Regression with an Interaction Term

plot of chunk unnamed-chunk-3

What happens if we add an interaction term, \(z\)? Now our function is \(log(odds) = 3-0.5z+x(0.5+z)\). This is the same as the function used on the left graph in the previous slide with an interaction term, \(z\), added. It is not as obvious what the coefficients of -0.5 and 1 mean, and of course the graph also depends on the value of \(z\). Here we see the same function with \(z\) values of 1 and -1.

The App

The shiny app will help students better understand the coefficients of the interaction term \(z\) by allowing them to adjust the parameters and see the result of the change in real time. By playing around with different combinations of variable changes, students can get a better sense of how each piece affects the graph as a whole.