5

Suppose we have 500 students nested in 20 classes (different classrooms), 25 students per class

student<-factor(1:500)
class<-rep(LETTERS[1:20],each=25)

They all take a test.

score<-rnorm(500,mean=80,sd=5)

The model below would tell you about the average scores and variability among students and classes

library(lme4)
lmer(score~(1|class))

Suppose further that a random 10 of the classrooms were painted red the other 10 were painted blue.

redvblue<-rep(0:1,each=250)

Is this a reasonable way to test for the effect of redvblue on test scores? And if it is reasonable, is there a better way?

lmer(score~redvblue+(1|class))

I'm wondering whether I should be concerned that redvblue was applied at the classroom level rather than the student level.

StasK
  • 29,235
  • 2
  • 80
  • 165
Thomas Levine
  • 3,001
  • 1
  • 16
  • 16

1 Answers1

2

Your approach is fine and appropriate. The power of mixed effects models is that they can be used to analyze data like yours or where treatments were at the individual level, or both.

Greg Snow
  • 46,563
  • 2
  • 90
  • 159