隨機價格係數的巧克力模型
好了,現在要對 chocolate 資料擬合分層模型。先從先前用來估計非分層選擇模型的程式碼開始,並加以修改,讓 Price 參數服從常態分配。chocolate 資料已經載入。
本練習屬於課程
R 的行銷選擇模型
練習說明
- 分層模型需要知道是誰做了每一次選擇。請將
Subject欄加入dfidx()的第一個索引,讓每一道選擇題都能連結到作答者。 - 在
mlogit()中加入rpar輸入。它應設為c(Price = "n"),表示你要Price的係數服從常態分配。 - 在
mlogit()中加入panel = TRUE,表示假設每位Subject都有自己專屬的Price係數。 - 透過輸入
plot(choc_m6)繪製分層模型。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# add Subject to the first index of dfidx()
chocolate <- dfidx(chocolate, idx = list(c("chid", ____), "Alt"),
choice = "Selection")
# add rpar and panel inputs to mlogit call
choc_m6 <- mlogit(Selection ~ 0 + Brand + Type + Price, data = chocolate,
____, ____)
# plot the model