Chocolate model with random price coefficient
Okay, we're ready to fit a hierarchical model to the chocolate
data. Let's start with the code we had before to estimate a non-hierarchical choice model and modify it to estimate a model where the Price
parameter is normally distributed. The chocolate
data is still loaded.
This exercise is part of the course
Choice Modeling for Marketing in R
Exercise instructions
- Add the input
id.var = "Subject"
tomlogit.data()
. This tellsmlogit.data()
which person answered each question. - Add the
rpar
input tomlogit()
. It should be equal toc(Price = "n")
to indicate that you want the coefficient forPrice
to be normally distributed. - Add the
panel = TRUE
input tomlogit()
to tell it that you want to assume eachSubject
has his or her ownPrice
coefficient. - Plot the the hierarchical model by typing
plot(choc_m6)
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# add id.var input to mlogit.data call
chocolate <- mlogit.data(chocolate, choice = "Selection", shape="long",
varying=6:8, alt.var = "Alt", ____)
# add rpar and panel inputs to mlogit call
choc_m6 <- mlogit(Selection ~ 0 + Brand + Type + Price, data = chocolate,
____, ____)
# plot the model