Designing Experiments and Analyzing Data: A Model Comparison Perspective (3rd edition) by Maxwell, Delaney, & Kelley
Information about the book is available at https://designingexperiments.com
R Code and Instructions to Accompany Chapter 1
Here, we use the AMCP package that accompanies the book (Version 0.0.4 or greater) to load the data into the working directory with the data() function. Note that the data sets are organized using the chapter number and table number, each separated with an underscore (e.g., chapter_1_table_1; chapter_11_table_20, chapter_13_table_5, etc.). Similarly, for end-of-chapter exercises, the organization is such that “table” is replaced with “exercise”
(e.g., chapter_1_exercise_21; chapter_3_table_9, chapter_16_exercise_5, etc.). Additionally, abbreviated names can be used where “C” replaces “chapter” and “T” or “E” replaces “table” or “exercise,” respectively.
For example, C1T1 can be used to reference chapter_1_table_1 or C1E21 can be used to reference chapter_1_exercise_21, et cetera. There are a few special cases as well, such as tutorials, raw data (e.g., when summary information is provided in the book), and univariate format (long) vs. multivariate format (wide) is used.
For a list of data sets use data() with package=”AMCP” specified, specifically as data(package=”AMCP”). All of the details needed for each data set can be found via data(package=”AMCP”) Note also that the data sets are available as comma space delimited (CSV) files (as well as SPSS and SAS) on the DesigningExperiments.Com web site, which is our web site that accompanies the book.
To begin, we install the AMCP package (this only needs to happen once per system unless you update R or you want to install a newer version of AMCP (if applicable) into the R session using the library() function. The install.packages() function can be used as shown below. Note that you may need to select a mirror (select one near your location) to download the package. Note that number sign (also called a hash character or pound sign) is how to denote a comment within R code, as R does not reed what is to the right of a number sign.
# Only necessary once on current system for the current version of a package. Uncomment to install.
# install.packages(“AMCP”)
Next, we load the AMCP package into the current R session using the library() function. The AMCP package contains all of the data from the book.
library(AMCP)
This code depends on version 0.0.4 of AMCP. Ensure that version (or newer) is loaded.
if((getNamespaceVersion(“AMCP”) >= “0.0.4”)==FALSE) print(“Please install the most recent version of the R package ‘AMCP’.”)
Next, we load the relevant data set of interest via the data() function. For the Chapter 1, Table 1 data, we do the following.
data(chapter_1_table_1)
To return the data (i.e., see what it looks like) you can simply call upon it by typing (or copying code and then pasting it into the console) before hitting return. Notice here and elsewhere that R output is preceded by a two number signs (also called a hash character or pound sign). Note that hitting the up arrow a previously used command will be recalled and ready to be entered again.
chapter_1_table_1
## treat control week
## 1 28 32 1
## 2 31 25 1
## 3 25 15 1
## 4 23 25 1
## 5 28 16 1 ## 6 26 30 2 ## 7 36 24 2 ## 8 23 13 2 ## 9 23 25 2 ## 10 24 16 2
For larger data sets, you may only want to see the first part (using head()) or the last part (using tail()).
head(chapter_1_table_1)
## treat control week ## 1 28 32 1 ## 2 31 25 1 ## 3 25 15 1 ## 4 23 25 1 ## 5 28 16 1 ## 6 26 30 2
For larger data sets, you may only want to see the first part (using head()) or the last part (using tail()).
Chapter 1: The Logic of Experimental Design and Analysis
- R Code for Replication of Analyses
- Table 1
- SPSS Syntax (Randomization Tests: Instructions / Within Subjects / Between Subjects)