LM analysis workflow (Block 3)
You do not need to memorise these steps. This page is here so you can refer to it while working through analyses using linear models.
You won’t need to use every step below for every analysis, and they don’t need to be in this specific order either. This is just the order Elizabeth usually uses 😊
Think of these steps like a buffet to pick and choose from, depending on what your analysis needs.
Phase 1: Before model fitting
1a: Set up your code and data
- Load the required R packages. You’ll probably need at least:
tidyverse(for managing and wrangling data)psych(for descriptives)sjPlot(for nice regression tables and plots)kableExtra(for nicely-formatted tables)patchwork(for combining multiple plots into one graphic)car(for assumption/diagnostic checks)interactions(for probing and plotting interaction models)
- Read in your data.
- Tidy data (e.g., any missingness, any implausible values? are data types set correctly?).
1b: Set up the variables you’ll model
- Based on the RQ, decide whether you’ll test your hypotheses using coefficient significance tests or model comparison.
- Based on the RQ, decide whether your model requires an interaction between predictors.
- Based on the RQ, identify your outcome variable and the predictors.
- Set up categorical predictors. (e.g., factor levels? which contrast coding scheme?)
- Set up continuous predictors. (e.g., any transformations?)
- Explore patterns in the data by plotting outcome and predictor variables together. (It’s most reader-friendly to plot the transformed version of the data, the version that you’ll also be modelling.)
- Make a nice descriptives table of all relevant variables for the write-up.
Phase 2: Model fitting
- Write the mathematical model formulation for your model(s).
- Explicitly define the hypotheses that your RQ is aiming to test.
- Fit your model(s) using
lm().
Phase 3: After model fitting
3a: Check assumptions and diagnostics
- Check model assumptions.
- If model assumptions about normality/equal variance of errors are violated, consider why; if you’re confident the issue is not due to model misspecification, then bootstrap model estimates.
- Run diagnostics for multicollinearity.
- Run diagnostics for influential observations.
- If you find extreme influential observations: run sensitivity analysis.
3b: Plot and interpret model estimates
- Interpret the coefficient estimates (if appropriate for your RQ).
- Generate a nicely-formatted regression table (if appropriate for your RQ).
- Compare models and interpret model comparison statistics (if appropriate for your RQ).
- Plot model-fitted values and/or simple slopes/simple effects (if appropriate for your RQ).
3c: Write up methods and results
- Write up your analysis and results.