Rtist
Rtist

Reputation: 4205

Specifying a one-way ANOVA in lme4, between subject and within subject

Using the lme4 package for mixed effect models in R, I am trying to figure out what is the difference in the way of modelling a one-way ANOVA within subject and a one-way ANOVA between subject.

Suppose first, that each subject see all three treatments (A, B and C). In each treatment, each subject gives me one measure (DV). I can model this within-subject design as follows:

lemr(DV ~ treatment + (1|subject), data = My_Data)

Now, suppose each subject sees only one treatment. What is the corresponding model? Would it be the same? If yes, how lemr() will know that it is a between subject design?

Upvotes: 1

Views: 1090

Answers (2)

mike
mike

Reputation: 173

The accepted answer is wrong!

If you drop the random intercept for subjects, you are no longer doing proper ANOVA unless you first compute subject means and then run lm(I assume you are using per trial data for lmer. If you are not, than there won't be any random variably for subjects, so you would get identical results with lm and lmer). In traditional ANOVA, subjects are always treated as random. This is achieved by averaging over subjects within each group first.

Now the right answer. When you use lemr, if treatment is a withing group factor, than you need a random intercept for your subjects. This is because you not only expect your subjects to introduce random variance to your DV in general (hence random intercept for your subject represented by digit 1 in 1|subjects), but also each subject might introduce random variance in each treatment condition (e.g. pre-test, post-test). So, the correct formula for ANOVA with a within subject design is (1+treatment|subject). In this case, you specify a random slope for each subject to account for possible viability within treatment conditions. Whereas, the correct formula for ANOVA with a between subject design is (1|subject).

Whether your model will converge with a random slope is question you can answer by running the model. However, even if it converges, the random slope might not be justified if there is not enough variability to account for. There ways to find this out. For example, likelihood ratio test can be used for nested models only (i.e. one model is a simplified version of the other).

Also, in order to interpret your lmer output as an ANOVA result, you need to have proper contrast coding for your categorical variable. For ANOVA style interpretation, you have to use a deviation coding. For example, if your factor has two levels, the contrasts are "-0.5,0.5". Look here for details --> http://talklab.psy.gla.ac.uk/tvw/catpred/

Upvotes: 3

Janelle Badger
Janelle Badger

Reputation: 94

If each subject only saw one treatment, you would no longer have the issue of repeated measures/nonindependence and you would not need a random effect of subject. So your model would be,

lmer(DV ~ treatment, data=My_Data)

Upvotes: 1

Related Questions