I'm trying to find the best model based on AIC using the stepwise (direction = both
) model selection in R using the stepAIC in MASS package.
This is the script i used:
stepAIC (glmer(decision ~ as.factor(Age) + as.factor(Educ) + as.factor(Child), family=binomial, data=RShifting), direction="both")
however I got this error result:
Error in lmerFactorList(formula, fr, 0L, 0L) :
No random effects terms specified in formula
I tried to add (1|town)
to the formula since town is the random effect (where the respondents are nested) and ran this script):
stepAIC (glmer(decision ~ as.factor(Age) + as.factor(Educ) + as.factor(Child) + (1|town), family=binomial, data=RShifting), direction="both")
The result is this:
Error in x$terms : $ operator not defined for this S4 class
I hope you could help me figure out how to solve this problem. Thanks a lot.