Categories
Research Technology (ResTech)
August 24, 2017
Tim Bock is back to help with all your data visualization needs in this week’s article on how to create an online choice simulator.
A choice simulator is an online app or an Excel workbook that allows users to specify different scenarios and get predictions. Here is an example of a choice simulator.
Choice simulators have many names: decision support systems, market simulators, preference simulators, desktop simulators, conjoint simulators, and choice model simulators.
In this post, I show how to create an online choice simulator, with the calculations done using R, and the simulator is hosted in Displayr.
First of all, choice simulators are based on models. So, the first step in building a choice simulator is to obtain the model results that are to be used in the simulator. For example, here I use respondent-level parameters from a latent class model, but there are many other types of data that could have been used (e.g., parameters from a GLM, draws from the posterior distribution, beta draws from a maximum simulated likelihood model).
If practical, it is usually a good idea to have model results at the case level (e.g., respondent level), as the resulting simulator can then be easily automatically weighted and/or filtered. If you have case level data, the model results should be imported into Displayr as a Data Set. See Introduction to Displayr 2: Getting your data into Displayr for an overview of ways of getting data into Displayr.
The table below shows estimated parameters of respondents from a discrete choice experiment of the market for eggs. You can work your way through the choice simulator example used in this post here (the link will first take you to a login page in Displayr and then to a document that contains the data in the variable set called Individual-Level Parameter Means for Segments 26-Jun-17 9:01:57 AM).
Variable sets are a novel and very useful aspect of Displayr. Variable sets are related variables that are grouped. We can simplify the calculations of a choice simulator by using the variable sets, with one variable set for each attribute.
Example A
In this step, we group the variables for each attribute into separate variable sets, so that they appear as shown at right (Example A). This is done as follows:
In my choice simulator, I have separate columns of controls (i.e., combo boxes) for each of the brands. The fast way to do this is to first create them for the first alternative (column), and then copy and paste them:
See also Adding a Combo Box to a Displayr Dashboard for an intro to creating combo boxes.
The code below can easily be modified for other models. A few key aspects of the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# Computing the utility for each alternative u1 = Weight[, Weight.1] + Organic[, Organic.1] + Charity[, Charity.1] + Quality[, Quality.1] + Uniformity[, Uniformity.1] + Feed[, Feed.1] + Price* as.numeric ( gsub ( "\\$" , "" , Price.1)) u2 = Weight[, Weight.2] + Organic[, Organic.2] + Charity[, Charity.2] + Quality[, Quality.2] + Uniformity[, Uniformity.2] + Feed[, Feed.2] + Price* as.numeric ( gsub ( "\\$" , "" , Price.2)) u3 = Weight[, Weight.3] + Organic[, Organic.3] + Charity[, Charity.3] + Quality[, Quality.3] + Uniformity[, Uniformity.3] + Feed[, Feed.1] + Price* as.numeric ( gsub ( "\\$" , "" , Price.3)) u4 = Weight[, Weight.4] + Organic[, Organic.4] + Charity[, Charity.4] + Quality[, Quality.4] + Uniformity[, Uniformity.4] + Feed[, Feed.1] + Price* as.numeric ( gsub ( "\\$" , "" , Price.4)) # Computing preference shares utilities = as.matrix ( cbind (u1, u2, u3, u4)) eutilities = exp (utilities) shares = prop.table (eutilities, 1) # Filtering the shares, if a filter is applied. shares = shares[QFilter, ] # Filtering the weight variable, if required. weight = if ( is.null (QPopulationWeight)) rep (1, length (u1)) else QPopulationWeight weight = weight[QFilter] # Computing shares for the total sample shares = sweep (shares, 1, weight, "*" ) shares = as.matrix ( apply (shares, 2, sum)) shares = 100 * prop.table (shares, 2)[1] |
If you wish, you can make your choice simulator prettier. The R Outputs and the controls all have formatting options. In my example, I got our designer, Nat, to create the pretty background screen, which she did in Photoshop, and then added using Insert > Image.
If you have stored the data as variable sets, you can quickly create filters. Note that the calculations will automatically update when the viewer selects the filters.
To share the dashboard, go to the Export tab in the ribbon (at the top of the screen), and click on the black triangle under the Web Page button. Next, check the option for Hide page navigation on exported page and then click Export… and follow the prompts.
Note, the URL for the choice simulator I am using in this example is https://app.displayr.com/Dashboard?id=21043f64-45d0-47af-9797-cd4180805849. This URL is public. You cannot guess or find this link by web-searching for security reasons. If, however, you give the URL to someone, then they can access the document. Alternatively, if you have an annual Displayr account, you can instead go into Settings for the document (the cog at the top-right of the screen) and press Disable Public URL. This will limit access to only people who are set up as users for your organization. You can set up people as users in the company’s Settings, accessible by clicking on the cog at the top-right of the screen. If you don’t see these settings, contact [email protected] to buy a license.
You can see the choice simulator in View Mode here (as an end-user will see it), or you can create your own choice simulator here (first log into Displayr and then edit or modify a copy of the document used to create this post).
Comments
Comments are moderated to ensure respect towards the author and to prevent spam or self-promotion. Your comment may be edited, rejected, or approved based on these criteria. By commenting, you accept these terms and take responsibility for your contributions.
Disclaimer
The views, opinions, data, and methodologies expressed above are those of the contributor(s) and do not necessarily reflect or represent the official policies, positions, or beliefs of Greenbook.
More from Tim Bock
Tim Bock on utilizing correspondence analysis.
Visualizations can summarize patterns that are commonly hidden in a simulator
Bad visuals stress the need for charts to be interpretable in seconds
Visualizing data can be made easier by utilizing small charts for comparison and analysis
Sign Up for
Updates
Get content that matters, written by top insights industry experts, delivered right to your inbox.
67k+ subscribers