1. Predicting shares with hierarchical models
The last thing I want to show you is how to predict shares with a hierarchical model. It is very similar to predicting shares with a non-hierarchical model, but requires one additional step.
2. Hierarchical model with correlations
I'm going to start by fitting one last model to the sportscar data. For this model, I'm including the extra input correlation = TRUE which indicates that I want to find a model where decision makers' parameters are potentially correlated. Our previous hierarchical models assumed preferences for different features are independent, which may not be true.
Once we have this model, we can look at the estimated correlations between parameters using the command cor-dot-mlogit(m10).
This prints out the matrix of correlations which tell us how preferences for the various features are related across decision makers. For example, one of the larger correlations is the one between transmanual and convertyes, which is -0-point-62. This tells us that people who prefer manual transmissions tend to dislike convertibles. This can be a useful insight when you are designing a set of sports cars to offer to the market. You probably shouldn't make a sports car with a convertible top and a manual. And this will be accounted for when we look at share predictions with model m10.
3. Products we want to predict shares for
So, how do we predict shares using m10? Let's predict share for the same pair of products we used in the previous chapter. Both are 2-seaters without convertible tops. One has a manual transmission at $35K and the other has an automatic at $30K.
Since we've switched to effects coding, I've effects-coded those products and saved them in prod-dot-coded.
4. Share prediction for hierarchical model
Now that I've got a model and a set of products I'm ready to predict shares. Let's walk through the code for doing that.
First, I extract the mean and covariance of the individual parameters from the model object and store them as mean-dot-coef and Sigma-dot-coef. These are the parameters of m10.
Then I follow the model structure we talked about before. The code loops over 1000 hypothetical decision makers. For each decision maker, we first draw their personal coefficients from a multivariate normal distribution with a mean of mean-dot-coef and a variance of Sigma-dot-coef. Then, once I have the individual's coefficients, I compute the utility for the two products by multiplying the coded product matrix by the individual coefficient vector coef. Then I compute the share for that person following the logit formula that we've seen a few times before. If you aren't familiar with matrix and vector operations in R, you may need to run the different pieces of this code and inspect the results to figure out exactly how it works.
Finally, if I average the shares for each person across all 1,000 people using colMeans(), I get my share prediction.
You can see that the share the first car is 12-point-3%. This prediction is a bit higher than what we got from the non-hierarchical model, which was 8-point-5%. This is typical for heterogeneous models. When we account for difference in preferences across consumers, we often find that niche products like this manual transmission sports car find a larger market. Shares for niche products tend to go up when we account for heterogeneity and shares for mainstream products tend to go down.
5. Let's practice!
Now it's your turn to predict shares for the chocolate data. And this will be your last exercise for this course!