Order of nested random effects in lme4 I just fit a model in lme4, and I'm wondering what the heck I fit...
I have individuals id, and each is measured pass/fail on items that can be described using two factors, f1 and f2. My theory says that id and f2 can interact. So I want to compare these models:
# f2 doesn't matter
m1 <- lmer(pass ~ f1 + (1|id), family="binomial")

# f2 is a fixed effect, doesn't interact with individuals
m2 <- lmer(pass ~ f1 + f2 + (1|id), family="binomial")

# f2 is a nested random effect, interacting with individuals
m3 <- lmer(pass ~ f1 + (1|f2/id), family="binomial")

First, am I right that there's a random effect of each level of f2, and each individual's level of f2 is partially pooled, depending on the number of observations for that individual?
Second, does it make sense to fit f2 as a fixed effect with random individuals nested within each level of f2? How does one write that?
Third, what's this, with f2 and id reversed in the formula? I typed it by accident, but now I want to understand it.
m3weird <- lmer(pass ~ f1 + (1|id/f2), family="binomial")

 A: As all participants did see all levels of your factor f1, the factor is not nested within id. A factor is nested within another factor if each instantiation of the higher order factor does not see all instantiations of the lower order factor (e.g., a factor is nested within id if id1 saw levels A and B, but not levels C and D, whereas id2 saw C & D but not levels A & B).
If you have simple within-subject factors, you want to have random slopes for the within-subject factors (i.e., in addition to the random intercept per id, each id can also have idiosyncratic effects for each factor level). This is discussed extensively in Barr et al. (see also here):
Barr, D. J., Levy, R., Scheepers, C., & Tily, H. J. (2013). Random effects structure for confirmatory hypothesis testing: Keep it maximal. Journal of Memory and Language, 68(3), 255–278. doi:10.1016/j.jml.2012.11.001
I suggest you use function mixed from package afex to obtain the p-values for your data using parametric bootstrap.
If only f2 is within-subjects:
mixed(pass ~ f1 * f2 + (f2|id), family="binomial", args.test = list(nsim = 10), method = "PB")

If both f1 and f2 are within-subject factors:
mixed(pass ~ f1 * f2 + (f1*f2|id), family="binomial", args.test = list(nsim = 10), method = "PB")

Note that you want to set nsim to high values for real applications (high means $> 1000$), but this usually takes time.
