This function is used to quickly create lineup plots to check distributional assumptions using Q-Q plots. The null hypothesis is that the data follows the distribution specified by the dist argument. In the lineup protocol the plot of the real data is embedded amongst a field of plots of data generated to be consistent with some null hypothesis. If the observer can pick the real data as different from the others, this lends weight to the statistical significance of the structure in the plot. The protocol is described in Buja et al. (2009).

lineup_qq(
  data,
  variable,
  dist = NULL,
  params = NULL,
  color_points = "black",
  color_lines = "brown3",
  alpha_points = 0.5
)

Arguments

data

a data frame.

variable

the name of the variable that should be plotted.

dist

the null distribution name. One of: "beta", "cauchy", "chi-squared", "exponential", "f", "gamma", "geometric", "log-normal", "lognormal", "logistic", "negative binomial", "normal", "poisson", "t", "uniform", "weibull"

params

list of parameters of distribution. If NULL, will use fitdistr to estimate them if possible. For uniform and beta distributions, the parameters must be specified. See ?dunif and ?dbeta for parameter names.

color_points

the color used for points. Can be a name or a color HEX code.

color_lines

the color used for reference lines.

alpha_points

the alpha (opacity) used for points (between 0 and 1, where 1 is opaque).

Value

a ggplot

Details

19 null datasets are plotted together the the true data (randomly positioned) If you pick the real data as being noticeably different, then you have formally established that it is different to with p-value 0.05.

Run the decrypt message printed in the R Console to see which plot represents the true data.

References

Buja, Cook, Hofmann, Lawrence, Lee, Swayne, Wickham. (2009). Statistical inference for exploratory data analysis and model diagnostics, Phil. Trans. R. Soc. A, 367, 4361-4383.

See also

null_dist

Examples

data(tips)
lineup_qq(tips, "total_bill", dist = "normal") # Normal distribution
#> decrypt("DruT c2V2 AR LeOAVAeR 1G")

lineup_qq(tips, "total_bill", dist = "gamma") # Gamma distribution
#> decrypt("DruT c2V2 AR LeOAVAeR 4p")


# Some distributions require that the parameters be specified:
tips$proportion_tips <- tips$tip/(tips$total_bill+tips$tip)
lineup_qq(tips, "size", dist = "beta", params = list(shape1 = 0.1, shape2 = 0.2))
#> decrypt("DruT c2V2 AR LeOAVAeR 4p")


# Style the plot using color settings and ggplot2 functions:
lineup_qq(tips, "total_bill",
          dist = "gamma",
          color_points = "chocolate",
          color_lines = "cyan",
          alpha_points = 0.25) +
    ggplot2::theme_minimal()
#> decrypt("DruT c2V2 AR LeOAVAeR 4p")