LM analysis workflow (Block 4)

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. Useful packages you might need:
    • 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)
    • effects (for plotting model-estimated values for logistic regression 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.
  • Based on the outcome variable, decide whether to use regular regression or logistic regression.
  • If logistic regression, set up the outcome variable so that desired level will be modelled as “success”.
  • 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() or glm() as appropriate.

Phase 3: After model fitting

3a: Check assumptions and diagnostics

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