I am estimating a random intercept and a random slope model using the following R code. My dependent and independent variable are both continuous.
randominterceptfixedslope<-lmer(y ~ x + (1|state),data=data,method="ML") # model with fixed slope but random intercept
randominterceptrandomslope<-lmer(y ~ x + (1+x|state),data=data,method="ML") # model with random slope and random intercept
anova(randominterceptfixedslope,randominterceptrandomslope)
Anova tells me that my randominterceptrandomslope model is a better fit on the data. So far good, please correct me if I am wrong.
My question is: If I have another independent variable $x_1$, can I put two independent variables in the above model i.e. can I have a randominterceptfixedslope and randominterceptrandomslope model with two independent variables. If yes, how do I do that? As in what the code should look like?
Thanks for your response. I got a second query. lets say my full model is this:
randominterceptrandomslope<-lmer(y ~ x1 + x2 + x3 + x4 (1+x1+x2+x3+x4|state),data=data,method="ML")
If some of my independent variables are correlated, what is the procedure of reducing the collinearity issue in a linear mixed effect model? I could spot collinerity using VIF and retain the most significant independent variables but I can do this for each factor level (levels of state) individually. But won't it result in retaining some independent variables in one factor level while deleting the same in other factor level? I guess the main question is how to spot collinearity in a mixed effect model and what to do with it when you have 5 or 6 independent variables?