To fit a multinomial mixed model in R, we can use the mlogit package for model specification and lme4 package for model fitting.
Here's an example code:
main.r642 chars23 lines
In this example code, the Electricity dataset from the mlogit package is loaded and converted to wide format using mlogit.data(). We then specify the model formula using mlogit() function, indicating that choice is the dependent variable and price and income are the independent variables. A random intercept for each individual is included with the | 0 notation. The model is then fitted using glmer() function from lme4 package with binomial family. Finally, we can view the summary of model output using summary() function.
gistlibby LogSnag