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.