- Data for ANOVA are most readily entered from a text file using read.table. Here we have read the data from the text file vetjoh.txt into the variable vetjoh.
- R carries out an analysis of variance by fitting a linear model. This is done using the lm( ) command. A typical model has the form 'response ~ terms' where 'response' is the response variable and 'terms' are the explanatory variables. In this case we have specified the model as log(con)~trt. We then run the model and assign the results to a new variable: joh=lm(log(con)~trt,vetjoh). The typical ANOVA table is obtained using anova.lm(joh). Effect sizes are obtained using summary(joh).
- A short-cut to obtaining an ANOVA table is to use the function aov( ). Hence we enter summary(aov(log(con)~trt,vetjoh)) R describes 'aov' as providing a wrapper to 'lm' for fitting linear models to balanced or unbalanced experimental designs. Results are expressed in the traditional language of the analysis of variance rather than that of linear models. Effect sizes are obtained using summary.lm(aov(log(con)~trt,vetjoh))
- The default method used by R to give effect sizes is quite different from the traditional way (i.e. as the mean for each level of the explanatory variable). Instead R first gives the mean for the factor level that comes first in the alphabet (in this case trtA) - labelled as intercept. The other parameters given are the differences between the mean of each subsequent level and the first level. If we wish to get the mean for each level, we must first run the model subtracting 1 from 'trt' joh1=lm(log(con)~trt-1,vetjoh). We then get the required means and standard errors using summary(joh1).