Linear mixed effect model with years as random effect

I have to set up an LMM with just one independent variable and there is both monthly and yearly variation. I aim to get fixed effects coefficients (slope and intercept) for each month and year given as random effect.

can anyone suggest me how to code this? the below code just gives one intercept and different slope in fixed effects
summary(lmer(Y ∼ X+(1+month)+(1|year),data = dataset,REML="TRUE"))

Or should I give each month as a different dataset
summary(lmer(Y ∼ X+(1|year),data = June,REML="TRUE"))

according to the documentation :
to fit models with independent categorical effects, see dummy or the lmer_alt function from the afex package.)

I would guess the formula might be something like

Y ~ 1 + X + (dummy(month))+(1|year)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.