Do I have to drop a random slope if I drop the fixed effect in mixed-models for model comparison? I'm performing a model comparison using the likelihood ratio test in R with two mixed models fitted with lme4.
My model is:
fit1 <- lmer(y ~ x * z + (z|id))

If I want to compare fit1 with a model without the effect z and then compare models with anova(fit1, fit0) should I need to remove also the random slope?
# Option 1

fit0 <- lmer(y ~ x + (1|id))

# Option 2

fit0 <- lmer(y ~ x + (z|id))

anova(fit1, fit0)


My idea is that when dropping a fixed effect I should also remove the random part. However, I guess that removing also the random slopes can somehow influence the test partially hiding the contribution of the fixed effect.
What should I do?

Your intuition is correct - you should remove the random slopes too.
You don't have to drop the random slope, but if you don't then you need to be extremely sure that the overall effect of that variable is zero. Recall that random effects are assumed to be normally distributed and can be interpreted as an offset to the global estimate for the relevant variable. So for example, with random intercepts the model will typically estimate a global intercept and then each group for which random intercepts are specified has their own offset from that global intercept. If you remove the global intercept from the model and just fit random intercepts you are saying that the individual intercepts for each group are clustered around zero with a normal distribution. With random slopes it is the same so if you remove the fixed effect without removing the random effect you are assuming that the overall effect for that variable is zero. Since this is hardly ever the case, this is typically not a good idea.
Also, try not to choose which variables you include in your regression model with a likelihood ratio test.
