age | outdoor_time | social_int | routine | wellbeing | location | steps_k |
---|---|---|---|---|---|---|
28 | 12 | 13 | 1 | 36 | rural | 21.6 |
56 | 5 | 15 | 1 | 41 | rural | 12.3 |
25 | 19 | 11 | 1 | 35 | rural | 49.8 |
60 | 25 | 15 | 0 | 35 | rural | NA |
19 | 9 | 18 | 1 | 32 | rural | 48.1 |
34 | 18 | 13 | 1 | 34 | rural | 67.3 |
Interactions I: Num x Cat
Learning Objectives
At the end of this lab, you will:
- Understand the concept of an interaction.
- Be able to interpret the meaning of a numeric \(\times\) categorical interaction.
- Visualize and probe interactions.
What You Need
- Be up to date with lectures
- Have completed all labs from Semester 1 Block 1 (Weeks 1 - 5)
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
- patchwork
- 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/wellbeing_rural.csv.
Study Overview
Research Question
Does the association between number of social interactions and wellbeing differ between rural and non-rural residents?
Researchers were specifically interested in how the number of social interactions might influence mental health and wellbeing differently for those living in rural communities compared to those in cities and suburbs. They want to assess whether the effect of social interactions on wellbeing is moderated by (depends upon) whether or not a person lives in a rural area.
To investigate how the association between the number of social interactions and mental wellbeing might be different for those living in rural communities, the researchers conducted a study, where they collected data from 200 randomly selected residents of the Edinburgh & Lothian postcodes.
Setup
- Create a new RMarkdown file
- Load the required package(s)
- Read the wellbeing_rural dataset into R, assigning it to an object named
wrdata
Exercises
Formally state:
- a linear model to investigate if the association between wellbeing and social interactions differs among rural and non-rural residents
- your chosen significance level
- the null and alternative hypotheses
“Except in special circumstances, a model including a product term for interaction between two explanatory variables should also include terms with each of the explanatory variables individually, even though their coefficients may not be significantly different from zero. Following this rule avoids the logical inconsistency of saying that the effect of \(X_1\) depends on the level of \(X_2\) but that there is no effect of \(X_1\).”
— Ramsey and Schafer (2012)
Check coding of variables (e.g., that categorical variables are coded as factors).
Note that the “location” variable currently has three levels (Rural/Suburb/City). In order to address the research question, we only want two (Rural/Not Rural) locations - you will need to fix this.
Specify ‘not rural’ as your reference group.
Visualise your data, and interpret your plots.
In particular:
- Explore the associations among the variables included in your analysis
- Produce a visualisation of the association between weekly number of social interactions and well-being, with separate facets for rural vs non-rural respondents OR with different colours for each level of the
isRural
variable.
Fit your model using lm()
, and assign it as an object with the name “rural_mod”.
Look at the parameter estimates from your model, and write a description of what each one corresponds to on the plot shown in Figure 1 (it may help to sketch out the plot yourself and annotate it).
Mean center the continuous IV(s), and re-run your model with mean centered variable(s).
Note any differences between the summary()
output between the “rural_mod” and “rural_mod1” models. Pay particular attention to your coefficients and their significance values. Why do you think these differences have been observed?
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.
Provide key model results in a formatted table.
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.
“The best method of communicating findings about the presence of a significant interaction may be to present a table or graph of the estimated means at various combinations of the interacting variables.”
— Ramsey and Schafer (2012)