Chapter 1 Background and R Setup
The goal of this document is provision of a template for using R to evaluate data from a 1-factor design that is typically called a 1-way ANOVA problem. The completely randomized design used for the initial illustration here is a 3-group design. These initial data come from an exercise in the classic Hays textbook. Later chapters utilize other data sets that have more treatment conditions.
The standard R axiom that there are always multiple ways of performing any task is never more accurate than with the ANOVA models. Beginning with graphical depiction and extending to standard NHST inferences, contrast analysis and post hoc tests, and evaluation of assumptions, the document also includes some rudimentary Bayesian approaches to inference.
This document
- Is intended for use by APSY511 course at UAlbany, but can be more broadly used by data analysts.
- Is a fairly full one-way anova exposition for a 3-group design and a second illustration with a five group design.
- Implements graphical summaries, numerical descriptions.
- Approaches ANOVA as linear modeling and is supplemented with analytical contrasts, and multiple comparison tests.
- Implements trend analysis for quantitative IV’s.
- Includes graphical and inferential evaluation of assumptions.
- Includes sections on Bayesian Inference, Robust methods, and Resampling Methods
- It includes a section on sample size planning with power analysis.
The document is constantly under development:
- Additional work on effect size computations,
- implementation of some newer multiple comparison methods
- additional work on robust and resampling methods
One of the primary goals is to reproduce all the work we have accomplished with the SPSS REGRESSION, GLM, MANOVA and ONEWAY procedures (and then some).
Several R packages are required:
#if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install("Biobase", version = "3.8")
# load packages and import data
library(afex,quietly=TRUE, warn.conflicts=FALSE)
library(asbio,quietly=TRUE, warn.conflicts=FALSE)
library(BayesFactor,quietly=TRUE, warn.conflicts=FALSE)
library(beeswarm,quietly=TRUE, warn.conflicts=FALSE)
library(car,quietly=TRUE, warn.conflicts=FALSE)
library(coin,quietly=TRUE, warn.conflicts=FALSE)
library(dunn.test,quietly=TRUE, warn.conflicts=FALSE)
library(effectsize,quietly=TRUE, warn.conflicts=FALSE)
library(emmeans,quietly=TRUE, warn.conflicts=FALSE)
library(ez,quietly=TRUE, warn.conflicts=FALSE)
library(DTK,quietly=TRUE, warn.conflicts=FALSE)
library(ggplot2,quietly=TRUE, warn.conflicts=FALSE)
library(ggthemes,quietly=TRUE, warn.conflicts=FALSE)
library(ggstatsplot,quietly=TRUE, warn.conflicts=FALSE)
library(granova,quietly=TRUE, warn.conflicts=FALSE)
library(gridExtra,quietly=TRUE, warn.conflicts=FALSE)
library(gt,quietly=TRUE, warn.conflicts=FALSE)
library(KScorrect,quietly=TRUE, warn.conflicts=FALSE)
library(knitr,quietly=TRUE, warn.conflicts=FALSE)
library(lattice,quietly=TRUE, warn.conflicts=FALSE)
library(lawstat,quietly=TRUE, warn.conflicts=FALSE)
library(lmboot,quietly=TRUE, warn.conflicts=FALSE)
library(lmPerm,quietly=TRUE, warn.conflicts=FALSE)
library(lsr,quietly=TRUE, warn.conflicts=FALSE)
library(multcomp,quietly=TRUE, warn.conflicts=FALSE)
library(multtest,quietly=TRUE, warn.conflicts=FALSE)
library(mutoss,quietly=TRUE, warn.conflicts=FALSE)
library(nortest,quietly=TRUE, warn.conflicts=FALSE)
library(outliers,quietly=TRUE, warn.conflicts=FALSE)
library(pgirmess,quietly=TRUE, warn.conflicts=FALSE)
library(plotrix,quietly=TRUE, warn.conflicts=FALSE)
library(plyr,quietly=TRUE, warn.conflicts=FALSE)
library(psych,quietly=TRUE, warn.conflicts=FALSE)
library(pwr,quietly=TRUE, warn.conflicts=FALSE)
library(rcompanion,quietly=TRUE, warn.conflicts=FALSE)
library(Rmisc,quietly=TRUE, warn.conflicts=FALSE)
library(sciplot,quietly=TRUE, warn.conflicts=FALSE)
library(sjstats,quietly=TRUE, warn.conflicts=FALSE)
library(userfriendlyscience,quietly=TRUE, warn.conflicts=FALSE)
library(WRS2,quietly=TRUE, warn.conflicts=FALSE)
library(dplyr,quietly=TRUE, warn.conflicts=FALSE)
Package citations for packages loaded here (in the above order): afex (Singmann, Bolker, Westfall, & Aust, 2018), asbio (Aho, 2019), BayesFactor (Morey & Rouder, 2018), beeswarm (Eklund, 2016), car (Fox, Weisberg, & Price, 2018), coin (Hothorn, Hornik, van de Wiel, Winell, & Zeileis, 2017), effectsize (Ben-Shachar, Makowski, & Lüdecke, 2021), emmeans (Lenth, 2019), ez (Lawrence, 2016), DTK (Lau, 2013), dunn.test (Dinno, 2017), ggplot2 (Wickham et al., 2018), ggthemes (Arnold, 2018), ggstatsplot (Patil, 2021), granova (Pruzek & Helmreich, 2014), gridExtra (Auguie, 2017), gt (Iannone, Cheng, & Schloerke, 2019), KScorrect (Novack-Gottshall & Wang, 2018), knitr (Xie, 2018b), lattice (Sarkar, 2018) lawstat (Gastwirth et al., 2017), lmPerm (Wheeler & Torchiano, 2016), lsr (Navarro, 2015) multcomp (Hothorn, Bretz, & Westfall, 2017), multtest (Pollard, Gilbert, Ge, Taylor, & Dudoit, 2018), mutoss (Team et al., 2017), nortest (Gross & Ligges, 2015), outliers (Komsta, 2011), pgirmess (Giraudoux, 2018), plotrix (Lemon et al., 2018), plyr (Wickham, 2016), psych (Revelle, 2019), pwr (Champely, 2018), rcompanion (Mangiafico, 2019), Rmisc (Hope, 2013,) sciplot (Morales, R Development Core Team, R-help listserv community, & Duncan Murdoch., 2017), sjstats (Lüdecke, 2019), userfriendlyscience (Peters, 2017), WRS2 (Mair & Wilcox, 2018), dplyr (Wickham, François, Henry, & Müller, 2019)
1.1 A note on R version and package installations.
R packages are undergoing constant revision and some code here may be deprecated or slightly modified in more recent verisons of some packages. Users can always install the most recent versions of R packages with source files rather than binaries, when they are available. The general process is to download the appropriate source files from the repository (ending in “tar.gz”). Then use this function to install the package:
#install.packages(file.choose(), repos=NULL, type="source")
Note that Windows users will need to install the Rtools suite of tools before source package installation is attempted.
https://cran.r-project.org/bin/windows/Rtools/
Rstudiio may permit direct installation from source.
Two packages that are required for permutation tests and bootstrapping, lmPerm and lmboot, can be obtained from CRAN (search the package name).
Three packages come from the BioConductor suite of r packages and the core BioConductor installer should also be installed.
https://www.bioconductor.org/
Search for pages of each of these four to download and install the latest package source files. But by the time you read this the normal process of installing the binary files may work (see the BiocManager page)
BiocManager
Biobase
BioGenerics
multtest
1.2 Resources
The following list will provide a good start for those needing a broader background in ANOVA techniques and more detailed sources for the primary packages employed in this document.
- Salvatore S. Mangiafico’s R Companion: [https://rcompanion.org/rcompanion/d_05.html]
- Martin Schweinberger’s Blog: [http://www.martinschweinberger.de/blog/one-way-anova/]
- cwoods on RPub: [https://rpubs.com/cwoods/anova]
- Daniel Wollschläger’s R Examples Repository [http://dwoll.de/rexrepos/posts/anovaCRp.html]