Copyright © Jeffrey A. Walker
keywords: q-q plot, model checking
knitr::opts_chunk$set(echo = TRUE,
message=FALSE,
warning = FALSE)
# import an messaging
library(here)
library(janitor)
library(readxl)
library(data.table)
# analysis
library(car) # qqPlot
library(qqplotr) # qq plot functions for ggplot
library(MASS) # rnegbin
# graphics and output
library(ggpubr) # qq plot functions
library(ggpubfigs) # palette
library(ggthemes) # themes and palettes including colorblind
library(ggforce)
library(cowplot)
here <- here::here
data_folder <- "content/data"
output_folder <- "content/output"
# Okabe & Ito palette
ito_seven <- friendly_pal("ito_seven") # ggpubfigs
pal_okabe_ito <- colorblind_pal()(8)[2:8] # ggthemes
Warning - This is a long, exploratory post on Q-Q plots motivated by the specific data set analyzed below and the code follows my stream of thinking this through. I have not gone back through to economize length. So yeh, some repeated code I’ve turned into functions and other repeated code is repeated.
This post is not about how to interpret a Q-Q plot but about which Q-Q plot? to interpret.
huh?
base R, ggpubr, ggplot2 compute the Q-Q line using the “quartiles” method - the line goes through the .25th and 0.75th quantiles. This line is a function of 2 of the n points.
qqPlot from the car package computes a “robust” Q-Q line using a robust regression through all points. At least the default qqPlot using a lm
object does this. If a vector of responses or residuals is input, then qqPlot defaults to the quartiles line. Regardless, a user can specify either.
ggpubr and ggplot2 (and base R?) compute a confidence band of the quartiles line using a parametric standard error.
qqPlot uses a parametric bootstrap to compute a confidence band if passing a lm
to the function. If a vector is passed, qqPlot uses a CI computed from a parametric SE. Again, a user can specify either.
To see this with qqPlot:
set.seed(1)
qqPlot(rnorm(20), id = FALSE) # quartiles
set.seed(1)
qqPlot(lm(rnorm(20) ~ 1), id = FALSE) # robust regression