If interactions are not important, replace the asterisk with a plus sign (+).ĭata.ex2=read.table(datafilename,header=T) #read the data into a tableĪov.ex2 = aov(Alertness~Gender*Dosage,data=data.ex2) #do the analysis of variance The asterisk indicates to R that the interaction between the two factors is interesting and should be analyzed. Notice that there are two independent variables in this example, separated by an asterisk *. Thus, this is a 2X2 design with the factors being Gender and Dosage. Two way - between subject analysis of varianceĭata are from an experiment in which alertness level of male and female subjects was measured after they had been given one of two possible dosages of a drug. > print(model.tables(aov.ex1,"means"),digits=3) #report the means and the number of subjects/cell > aov.ex1 = aov(Alertness~Dosage,data=data.ex1) #do the analysis of variance > data.ex1=read.table(datafilename,header=T) #read the data into a table Print(model.tables(aov.ex1,"means"),digits=3) #report the means and the number of subjects/cellīoxplot(Alertness~Dosage,data=data.ex1) #graphical summary The results of the ANOVA can be seen with the summary command:ĭata.ex1=read.table(datafilename,header=T) #read the data into a tableĪov.ex1 = aov(Alertness~Dosage,data=data.ex1) #do the analysis of variance
This general format will hold true for all ANOVAs you will conduct. aov.ex1 is the name of the structure you want the analysis to store.
The final argument for aov is the name of the data structure that is being analyzed. It is followed by the tilde symbol (~) and the independent variable(s). The first argument is always the dependent variable (Alertness ). It is important to note the order of the arguments. Do descriptive statistics on the groups, and then do a one way analysis of variance. One Way Analysis of VarianceĮxample 1: Three levels of drug were administered to 18 subjects. For this discussion, I assume that appropriate data files have been created in a text editor and saved in a subjects x variables table.
The last three examples discuss how to reorganize the data from a standard data frame into one appropriate for within subject analyses. For more detail on data entry consult that guide. The first 5 examples are adapted from the guide to S+ developed by TAs for Roger Ratcliff. In psychological research this usually reflects experimental design where the independent variables are multiple levels of some experimental manipulation (e.g., drug administration, recall instructions, etc.) A special case of the linear model is the situation where the predictor variables are categorical.