This page shows how you can plot statistical models and visualise the uncertainty inherent to them. To reproduce the analyses and plots, you’ll need R
. In addition you’ll need a couple of add-on packages.
To install a package, run install.packages()
, e.g.,:
# Load add-on packages
library(tidyverse) # for plotting and working with data
library(broom) # optional: for tidying model outputs
library(lme4) # for fitting frequentist mixed-effects models
library(brms) # for fitting Bayesian models
The following command just changes some aesthetic aspects of the plots:
Graphs are easier to grok than coefficient tables. Some numeric model outputs are uninterpretable without visualisation (e.g., nonlinear terms in generalised additive models). Others can, in principle, be interpreted, but are difficult to do so and liable to misinterpretation (e.g., interaction terms).
Visualising uncertainty could serve as an antidote to uncertainty laundring (i.e., “\(p < 0.05\), hence this is how the world works”): A range of patterns that are compatible with data and model is shown rather than just one estimate.
Most of what I’ll illustrate below can also, and more quickly, be accomplished using the effects
package (Fox 2003). But it’s good to know how to draw these plots yourself so that you can tweak them as needed and so that you know what these plots do and don’t show.
We’ll start with an example in which there is just one, linear predictor of a continuous outcome. The data stem from a study by DeKeyser et al. (2010) and were reanalysed by Vanhove (2013). The dataset can be downloaded from https://janhove.github.io/visualise_uncertainty/dekeyser2010.csv.
Each row in the dataset contains the data for a different participant for two variables:
AOA
contains the age at which the participant started learning Hebrew as a second language.GJT
contains their score in a 204-item grammaticality judgement task.The goal of the analysis was to characterise the relationship between these two variables.
# Read in the dataset
dekeyser <- read_csv("https://janhove.github.io/visualise_uncertainty/dekeyser2010.csv")
## Parsed with column specification:
## cols(
## AOA = col_double(),
## GJT = col_double()
## )