# 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 , asbio , BayesFactor , beeswarm , car , coin , effectsize , emmeans , ez , DTK , dunn.test , ggplot2 , ggthemes , ggstatsplot , granova , gridExtra , gt , KScorrect , knitr , lattice lawstat , lmPerm , lsr multcomp , multtest , mutoss , nortest , outliers , pgirmess , plotrix , plyr , psych , pwr , rcompanion , Rmisc (Hope, 2013,) sciplot , sjstats , userfriendlyscience , WRS2 , dplyr

## 1.1 A note on R version and package installations.

At the point in time that this document was created, the transition to R version 4.0 is ongoing and some packages have not been revised to work with R4.0. Installing source files rather than binaries can be a work around for some packages. 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/

Two packages that 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.