Effect of drugs on reaction time

For this module, we will use the package ‘ez,’ which is helpful for complicated analysis of variance problems where we have one or more factors and that are within (repeated measures).

# install.packages('ez')  # install if you don't have this on your computer
library(ez)               # invoke the package

The data for this study of the effects of drugs on reaction time are taken from Winer, B. J. (1971). Statistical Principles in Experimental Design (2nd ed.). New York: McGraw-Hill. (p. 268)

The data were collected so that each of 5 people were given each of 4 drugs and tested on their reaction times. There was sufficient time between drugs for the effects to wear off, and the order of drug administration was randomized. The randomization of order is very important because the order effect is not included in the model of the data. If there is an order effect, its impact is felt in the error term.

RT <- c(30, 14, 24, 38, 26, 28, 18, 20, 34, 28, 16, 10, 18, 20, 14, 34, 22, 30, 44, 30)
person <- c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
drug   <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4)
react <- data.frame(RT, person, drug)
react
##    RT person drug
## 1  30      1    1
## 2  14      2    1
## 3  24      3    1
## 4  38      4    1
## 5  26      5    1
## 6  28      1    2
## 7  18      2    2
## 8  20      3    2
## 9  34      4    2
## 10 28      5    2
## 11 16      1    3
## 12 10      2    3
## 13 18      3    3
## 14 20      4    3
## 15 14      5    3
## 16 34      1    4
## 17 22      2    4
## 18 30      3    4
## 19 44      4    4
## 20 30      5    4

The ‘ez’ ANOVA package expects to receive data in the long format. That means that each observation is a row. Note how person 1 is represented as 4 different rows, one for each drug. The other way of inputting data is the wide format, where each person is one row, and there is a different column for each level of the independent variable. Different programs have different preferences. You can always arrange your data to suit.

react$person <- as.factor(person) # set integer to factor for person
react$drug <- as.factor(drug)     # again for drug
one_way <- ezANOVA(data=react,
                  dv = RT,        # Dependent variable.
                  wid=person,     # within subject ID
                  within=drug,    # IV - within or repeated measure
                  detailed = T)   # a little extra printout
print(one_way)                    # ges = Generalized Effect Size; see help file for reference
## $ANOVA
##        Effect DFn DFd     SSn   SSd        F            p p<.05       ges
## 1 (Intercept)   1   4 12400.2 680.8 72.85664 1.033910e-03     * 0.9398505
## 2        drug   3  12   698.2 112.8 24.75887 1.992501e-05     * 0.4680252
## 
## $`Mauchly's Test for Sphericity`
##   Effect         W         p p<.05
## 2   drug 0.1864953 0.4957455      
## 
## $`Sphericity Corrections`
##   Effect      GGe        p[GG] p[GG]<.05      HFe        p[HF] p[HF]<.05
## 2   drug 0.604874 0.0006490326         * 1.078854 1.992501e-05         *

The uncorrected F value for drug (F=24.76) is the same as what is shown in the PowerPoint slideshow.

Within designs have some elaborate assumptions for the p values to be accurate. For this reason, many prefer to use MANOVA, which has a less restrictive set of assumptions, for this kind of design. The ezANOVA printout also includes output for the Greenhouse-Geyser correction and for a generalized effect size.

We can also take a look at the data using a graph.

boxplot(RT~drug, xlab='Drug', ylab='Reaction time')

The distribution of reaction times is often skewed because of a floor effect plus an unconstrained ceiling. The boxplots for this study aren’t bad, but you cannot tell a great deal about the distributions because there are only 5 observations per box. There are many other ways to represent the data. Note that this set of boxplots does not show the dependencies. We could plot each person as a profile (a line) connected between each of the drugs, for example.