| variable | description |
|---|---|
| age | Age in years of respondent |
| outdoor_time | Self report estimated number of hours per week spent outdoors |
| social_int | Self report estimated number of social interactions per week (both online and in-person) |
| routine | Binary 1=Yes/0=No response to the question 'Do you follow a daily routine throughout the week?' |
| wellbeing | Warwick-Edinburgh Mental Wellbeing Scale (WEMWBS), a self-report measure of mental health and wellbeing. The scale is scored by summing responses to each item, with items answered on a 1 to 5 Likert scale. The minimum scale score is 14 and the maximum is 70 |
| location | Location of primary residence (City, Suburb, Rural) |
| steps_k | Average weekly number of steps in thousands (as given by activity tracker if available) |
04: Model comparison
This week, you’ll practice interpreting the F-test for model fit, as well as comparing different sorts of models to one another using incremental F-tests and AIC/BIC.
- Open RStudio.
- Create a new .Rmd file for this week’s exercises.
- Save it somewhere you can find it again.
- Give it a clear name (for example,
dapr2_lab04.Rmd). - In the first code chunk, load the packages you’ll need this week (and install them if you don’t have them already):
tidyverse
Data dictionary:
From the Edinburgh & Lothians, 100 city/suburb residences and 100 rural residences were chosen at random and contacted to participate in the study. The Warwick-Edinburgh Mental Wellbeing Scale (WEMWBS) was used to measure mental health and wellbeing.
Participants filled out a questionnaire including items concerning: estimated average number of hours spent outdoors each week, estimated average number of social interactions each week (whether on-line or in-person), whether a daily routine is followed (yes/no). For those respondents who had an activity tracker app or smart watch, they were asked to provide their average weekly number of steps.
Test a model’s fit
Read in the data from https://uoepsy.github.io/data/wellbeing_rural.csv and store it in a variable named mwdata (“mw” stands for “mental wellbeing”).
For this week’s lab, we’ll need to delete all observations that contain any NAs in the following columns:
wellbeingageoutdoor_timesocial_intsteps_k
Use the tidyverse function drop_na() and assign the outcome back to the variable name mwdata.
You’ll know you’ve done it right if mwdata now contains 134 observations, not 200.
Replace the ... with the actual variable names.
mwdata <- mwdata |>
drop_na(..., ..., ...)
Use the function lm() to fit the linear model represented by the mathematical model formulation below, and name the result m0.
\[ \text{wellbeing} = \beta_0 + (\beta_1 \cdot \text{outdoor\_time}) + (\beta_2 \cdot \text{social\_int}) + \epsilon \]
is m0 significantly better at predicting wellbeing than a model with no predictors, i.e., a null model?
Address this question using the F-test reported at the bottom of the model summary for m0. Report your answer using APA notation.
🗂️ See Assessing model fit > F-ratio flash card.
Compare nested models
RQ: Is wellbeing predicted by number of steps (steps_k) and hours outdoors (outdoor_time), over and above the impact of years of age (age) and number of social interactions (social_int)?
To address this RQ, you’ll need to compare two models.
Write out the formulae for both models, using either R notation or mathematical model notation, whichever you prefer.
Fit the two models you identified in Q4. Name the model with fewer predictors m1 and the model with more predictors m2.
🗂️ See Multiple regression > Fitting model flash card.
Use an incremental F-test to compare these two models.
Based on the results of the test, write a sentence that addresses the research question, and report the relevant statistical quantities using APA notation.
🗂️ See Comparing LMs > Incremental F-test flash card.
Compare non-nested models
RQ: Do number of steps (steps_k) and hours outdoors (outdoor_time) predict wellbeing better than years of age (age) and number of social interactions (social_int)?
To address this RQ, you’ll need to compare two models.
Write out the formulae for both models, using either R notation or mathematical model notation, whichever you prefer.
Fit the two models you identified in Q7. Name one model m3 and the other m4.
Use AIC and BIC to compare these two models.
Based on the results, write a sentence that addresses the research question, and report each model’s AIC and BIC using APA notation.
🗂️ See Comparing LMs > AIC & BIC flash card.
Identify nestedness of models
For each of the following pairs of models, state whether they are nested or not. Assume all models are fitted to the same dataset mwdata.
Pair 1:
wellbeing ~ social_intwellbeing ~ social_int + outdoor_time
Pair 2:
wellbeing ~ social_int + outdoor_timewellbeing ~ social_int + age
Pair 3:
wellbeing ~ social_intwellbeing ~ social_int + outdoor_time + age
Pair 4:
wellbeing ~ social_int + agewellbeing ~ outdoor_time + age + social_int + steps_k
Pair 5:
wellbeing ~ social_intwellbeing ~ outdoor_time
🗂️ See Comparing LMs > Nested vs. non-nested models flash card.