Get startedGet started for free

Predicting shares

1. Predicting shares

Interpreting parameters of a multinomial logit model can be tricky. When I'm working with decision-makers - who are mostly not statisticians - I like to show them share predictions for specific sets of products. These share predictions represent our best guess about what people will choose if given a specific set of products.

2. Multinomial logit model

To understand how to predict shares, let's go back to the code for a simple multinomial logit model. Once we have estimated a model, we have guesses about what alpha and beta are. So, if we are given a set of three products each with a number of seats and a price, we can compute the v's by multiplying the coefficients by the attribute variables and then summing up. Then we can compute the p's following the logit formula. Those p's are the probabilities that a customer will choose each of the products and we can report them to decision makers as shares.

3. Data frame for new products

That bit of pseudocode gives you the idea, but now let's write code to compute shares for real. That starts by creating a data frame with the set of products we want to predict share for. To create this data frame, I make a vector of length two for each of the attributes. For instance, price is the vector, 35 30, indicating that the first sports car is $35,000 and the second is $30,000. For the other attributes, I also create vectors of length 2, but I make sure to store them as factors. The levels input to the factor() function tells R what all possible levels of the factor are. This is important and will allow us to use R's built-in tools for factor coding. I also create a vector for the segment, because I want to use the model we estimated that includes an interaction between price and segment. The segment variable should be the same for all the products in the set. Here, I've set it to the basic segment, so we will be predicting shares specifically for the basic segment. Finally, I put all those vectors together in a data frame. This data frame represents a new "market". The first sports car could be the one my company plans to offer and the second could be a competitor. You can predict shares for as few as two products up to a few dozen products.

4. Code for predicting shares

Now we can compute the market shares for prod. I've started by fitting model m5. Once I've got m5, I convert my new prod data frame from factors to numbers using the function model-dot-matrix(). Model matrix has two inputs: the first is a formula, which we extract from the m5 model object. The second is the prod data frame. This command produces a coded version of the prod data frame. Next, we compute the utilities using matrix multiplication. The symbol percentage-star-percentage means multiply each row in prod-dot-coded times the vector of coefficients from model m5. For these two products, the v values are about -9-point-21 and -6-point-85.

5. Code for predicting shares

Then, I compute shares according to the logit formula. This is done compactly for any number of alternatives using element-by-element vector division.

6. A function for share prediction

I've bundled this code up in a function, so that it is easy to use. We used this function before in Chapter 1, but now you can see the code inside it. The inputs are an mlogit model object and the data frame with the products. While writing functions is outside the scope of this course, I wanted to show you an example of how writing your own function can be handy.

7. Plotting shares

Using the function, we can compute share with a single line. And once we have those shares, we can plot them and share them with decision makers.

8. Let's predict some shares for sports cars and chocolate bars!

Let's predict some shares!