1

I want to conduct a two-way ANOVA with a mixed effect model using lme4. The trial detail is Factor A with 3 levels and Factor B with two levels (3x2) replicated on farms for two seasons. I assigned the two factors and their interaction as fixed effects, whereas farms and seasons are random factors. I tried:

fit <- lmer(reponse ~ A * B + (1 | farms) + (1 | season) , data = data)
anova(fit)

But it is not working for me. Can you suggest better R code? Can you give more tips on pairwise comparisons?

DrJerryTAO
  • 1,514
Workneh
  • 11
  • 2
  • 3
    Probably not working because you only have two seasons instead of a population of seasons from which two were randomly drawn. So start with making season fixed. – BenP Feb 17 '24 at 08:30
  • Even when you have farms and season as random effects instead of fixed effects, they might cause you to be overfitting the response. – Sextus Empiricus Feb 17 '24 at 09:37
  • 1
    How is it exactly not working? Can you share more details why it is not working. – Sextus Empiricus Feb 17 '24 at 09:38
  • A related question with overfitting is: https://stats.stackexchange.com/questions/628444/ – Sextus Empiricus Feb 17 '24 at 09:54
  • 1
    Use lmer(reponse ~ A * B * season + (1 | farms), data = data). Two levels of season is too small a panel size to allow random effects, and estimating seasonal differences should be insightful in farm studies. – DrJerryTAO Feb 17 '24 at 13:15

0 Answers0