# [R] anova vs aov commands for anova with repeated measures

Frodo Jedi frodo.jedi at yahoo.com
Sat Jan 8 11:23:42 CET 2011

```Dear Bill,
many thanks for your answer. I got the point but still I would need an help
with a numeric example, as I haven´t fully understood how it works with R
(I had a look to proj() but I am not aware of how can be used correctly).

Could you please make an example?

For example, in attachment you find a .csv table resulting from an experiment,
you can access it by means of this command:

> scrd<-
>

The data are from an experiment where participants had to evaluate on a seven
point likert scale
the realism of some stimuli, which are presented both in condition "A" and in
condition "AH".

I need to perform the ANOVA by means of this command:

> aov1 = aov(response ~ stimulus*condition + Error(subject/(stimulus*condition)),
>data=scrd)

but the problem is that I cannot plot as usually do the qqnorm on the residuals
of the fit because
lm does not support the Error term present in aov.
I normally check normality through a plot (or a shapiro.test function). Now

illustrate me how will you be able to undestand from my data if they are
normally distributed?

Best regards

________________________________
From: "Bill.Venables at csiro.au" <Bill.Venables at csiro.au>
To: frodo.jedi at yahoo.com; r-help at r-project.org
Sent: Sat, January 8, 2011 4:01:41 AM
Subject: RE: [R] anova vs aov commands for anova with repeated measures

lm() and aov() are not fully equivalent.  They both fit linear models, but they
use different algorighms, and this allows aov, for example, to handle some
simple multistratum models.  The algorithm used by lm does not allow this, but
it has other advantages for simpler models.

If you want to fit a multistratum model, such as a repeated measures model, you
need to use aov.

When it comes to finding the residuals, you have to be explicit about which
residuals you mean, too.  You get residuals for each stratum in a multistratum
model.  Using plain old resid() will not work as that function can only be used
when there is only one kind of residuals vector defined.  (it could me made to
do something sensible, but that's another issue.  Right now, it doesn't.)

The function proj() can be used on a fitted model object to obtain the
projections, at each stratum, on to the subspaces defined by the terms in the
model, and includes the residuals (the projection onto the orthogonal complement
of the model space in R^n) as the final column of the matrix of projections.
These are easy to dig out and you can analyse away.

See ?proj for an example of its use, but you will need to dig out the
appropriate column yourself.

________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of
Frodo Jedi [frodo.jedi at yahoo.com]
Sent: 08 January 2011 01:51
To: r-help at r-project.org
Subject: [R] anova vs aov commands for anova with repeated measures

Dear all,
I need to understand a thing in the beheaviour of the two functions aov and
anova in the following case
involving an analysis of ANOVA with repeated measures:

If I use the folowing command I don´t get any problem:

>aov1 = aov(response ~ stimulus*condition + Error(subject/(stimulus*condition)),
>data=scrd)
> summary(aov1)

Instead if I try to fit the same model for the regression I get an error:
> fit1<- lm(response ~ stimulus*condition + Error(subject/(stimulus*condition)),
>data=scrd)
>
Error in eval(expr, envir, enclos) : could not find function "Error"

so I cannot run the command anova(fit1) afterwards.

I want to use fit1<- lm(response ~ stimulus*condition +
Error(subject/(stimulus*condition)), data=scrd)

because I want to analyse the residuals in order to check normality, and see if
the anova assumption of normality
still holds.