LoslegenKostenlos loslegen

Chocolate model with all coefficients random

Now that we have the effects coding stored with the chocolate data, we are ready to fit a model where all the coefficients are normally distributed. In order to do that, we need to create the rpar vector to input to mlogit(). That's a bit tricky, so I've written the code for you, but you should run it to see how it works. Then, you are going to write the call to mlogit().

Diese Übung ist Teil des Kurses

Choice Modeling for Marketing in R

Kurs anzeigen

Anleitung zur Übung

  • The first two inputs are the model formula Selection ~ 0 + Brand + Type + Price and the data chocolate.
  • The next input should be rpar = my_rpar which tells mlogit() which coefficients we want to be normally distributed.
  • The last input should be panel = TRUE.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# create my_rpar vector
choc_m2 <- mlogit(Selection ~ 0 + Brand + Type + Price, data=chocolate)
my_rpar <- rep("n", length(choc_m2$coef))
names(my_rpar) <- names(choc_m2$coef)
my_rpar

# fit model with random coefficients
choc_m7 <- mlogit(___)
Code bearbeiten und ausführen