Interactions II: Num x Num

Learning Objectives

At the end of this lab, you will:

  1. Understand the concept of an interaction.
  2. Be able to interpret the meaning of a numeric \(\times\) numeric interaction.
  3. Understand the principle of marginality and why this impacts modelling choices with interactions.
  4. Visualize and probe interactions.

What You Need

  1. Be up to date with lectures
  2. Have completed previous lab exercises from Week 7

Required R Packages

Remember to load all packages within a code chunk at the start of your RMarkdown file using library(). If you do not have a package and need to install, do so within the console using install.packages(" "). For further guidance on installing/updating packages, see Section C here.

For this lab, you will need to load the following package(s):

  • tidyverse
  • psych
  • sjPlot
  • kableExtra
  • sandwich
  • interactions

Lab Data

You can download the data required for this lab here or read it in via this link https://uoepsy.github.io/data/scs_study.csv.

Study Overview

Research Question

Does the effect of social comparison on symptoms of depression, anxiety and stress vary depending on level of Neuroticism?

Previous research has identified an association between an individual’s perception of their social rank and symptoms of depression, anxiety and stress. We are interested in the individual differences in this association.

To investigate whether the effect of social comparison on symptoms of depression, anxiety and stress varies depending on level of Neuroticism, we will need to fit a multiple regression model with an interaction term. Before we think about fitting our model, it is important that we understand the data available - how many participants? What type (or class) of data will we be working with? What was the measurement scale? How were scales scored? Look at the social comparison study data codebook below.

Social Comparison Study data codebook

Setup

Setup
  1. Create a new RMarkdown file
  2. Load the required package(s)
  3. Read the scs_study dataset into R, assigning it to an object named scs_study

Solution

Exercises

Question 1

Formally state:

  • a linear model to investigate whether the effect of social comparison on symptoms of depression, anxiety and stress varies depending on level of Neuroticism
  • your chosen significance level
  • the null and alternative hypotheses

Solution


Question 2

Provide a table of descriptive statistics and visualise your data.

Remember to interpret these plots in the context of the study.

  1. The describe() function is from the psych package; and kable() and kable_styling() (which are used to make a nice table) from kableExtra would be useful to present your descriptive statistics.
  2. The pairs.panels() function from the psych package will plot all variables in a dataset against one another. This will save you the time you would have spent creating individual plots.

Solution


Question 3

Run the two code chunks below. It takes the dataset, and uses the cut() function to add a new variable called “zn_group”, which is the “zn” variable split into 4 groups.

scs_study <-
  scs_study %>%
  mutate(
    zn_group = cut(zn, 4)
  )

We can see how it has split the “zn” variable by plotting the two against one another (note that the levels of the new variable are named according to the cut-points):

ggplot(data = scs_study, aes(x = zn_group, y = zn)) + 
  geom_point()

Plot the association between scores on the SCS and scores on the DASS-21, for each group of the variable we just created.

How does the pattern differ across groups? Does it suggest an interaction?

Rather than creating four separate plots, you might want to map some feature of the plot to the variable we created in the data, or make use of facet_wrap()/facet_grid().

Remember that you can specify geom_smooth() to add a trend line

Solution


Visualising Interaction Terms

Cutting one of the explanatory variables up into groups essentially turns a numeric variable into a categorical one. We did this just to make it easier to visualise how an association differs across the values of another variable, because we can imagine a separate line for the association between SCS and DASS-21 scores for each of the groups of Neuroticism. However, in grouping a numeric variable like this we lose information. Neuroticism is measured on a continuous scale, and we want to capture how the association between SCS and DASS-21 differs across that continuum (rather than cutting it into chunks).

We could imagine cutting it into more and more chunks (see Figure 1), until what we end up with is an infinite number of lines - i.e., a three-dimensional plane/surface (recall that in for a multiple regression model with 2 explanatory variables, we can think of the model as having three-dimensions). The inclusion of the interaction term simply results in this surface no longer being necessarily flat. You can see this in Figure 2).

Figure 1: Separate regression lines DASS ~ SCS for Neuroticism when cut into 4 (left) or 6 (center) or 12 (right) groups.

Figure 2: 3D plot of regression surface with interaction. You can explore the plot in the figure below from different angles by moving it around with your mouse.


Question 4

Consider that Neuroticism has already been \(z\)-scored, but scs has not. To ensure that we can compare the effects of our estimates (and so they are both on meaningful scales), standardize the scs variable.

Recall the formula for the \(z\)-score: \[ z_x = \frac{x - \bar{x}}{s_x}, \qquad z_y = \frac{y - \bar{y}}{s_y} \]

Solution


Question 5

Fit your model (including the standardized variables) using lm(), and assign it as an object with the name “dass_mdl”.

When fitting a regression model in R with two explanatory variables A and B, and their interaction, these three are equivalent:

  • y ~ A + B + A:B
  • y ~ A + B + A*B
  • y ~ A*B

Solution


Question 6

Interpret your coefficients in the context of the study.

Solution


Question 7

Using the probe_interaction() function from the interactions package, visualise the interaction effects from your model.

Try to summarise the interaction effects in a short and concise sentence.

Because we are looking at a numeric x numeric interaction, we want to specify jnplot = T (see this weeks lecture, slides 17-21 for a worked example).

Remember to give your plot informative titles/labels. You, for example, likely want to give your plot:

  • a clear and concise title (specify main.title =)
  • axis labels with units or scale included (specify x.label = and y.label =)
  • a legend title (specify legend.main =)

Solution


Question 8

Conduct a simple slopes analysis.

If you wanted to see only the simple slopes or only the Johnson-Neyman plot, you could call $simslopes$slopes or simslopes$jnplot respectively from your object plt_dass_mdl.

Solution


Question 9

Provide key model results in a formatted table.

Use tab_model() from the sjPlot package.

Remember that you can rename your DV and IV labels by specifying dv.labels and pred.labels.

Solution


Question 10

Interpret your results in the context of the research question and report your model in full.

Make reference to the interaction plot and regression table.

Solution