Choice Modeling - Utilities Plot Extension

From Q
Jump to navigation Jump to search

Plots the utility of variables in a Choice Model.


How to Create

There are two possible ways to create a utilities plot:

  1. Using the menu options with Anything > Advanced Analysis > Choice Modeling > Utilities PlotAutomate > Browse Online Library > Choice Modeling > Utilities Plot and populate the plot with the desired input type (see possible input types in the Options section below). To do this, in the newly created Utilities plot, view the Inputs tab of the Object Inspectorobject inspector and select the desired choice model from the dropbox labeled Input in the INPUTS subsection.
  2. In the Object Inspectorobject inspector of a Choice Model output, click the Utilities plot extension button. This extension button can be found under Inputs > DIAGNOSTICS > Utilities plot. The extension button will create a new page with the Utilities plotR output with the Utilities plot in the same group (folder) where the choice model is contained.

Example


Output Example:

Input Example:
A choice model. The following LCA model creates the output above:

Options

Chart type The chart type that is used for the output. It can be one of Line, Column or Bar.

Input One of

A choice model such as Choice Modeling - Latent Class Analysislatent class analysis or Choice Modeling - Hierarchical Bayeshierarchical Bayes.
Multiple numeric variables that each contain respondent utilities for an attribute level. For example variables created using Choice Modeling - Save Variable(s) - Utilities (Min 0)Save utilities (min = 0).
A vector or list containing summary values for each attribute level. e.g c(`Feed: Grain` = 0.2, `Feed: Vegetables` = 0.1, `Weight: 55g` = 0.4, `Weight: 60g` = 0.5, `Weight: 75g` = 0.6) or list(Feed = c(Grain = 0.2, Vegetables = 0.1), Weight = c(`55g` = 0.4, `60g` = 0.5, `75g` = 0.6))

Attributes to exclude Attributes in the model to omit from the chart.

Scaling Whether the mean utility of each variable should be scaled or plotted as is. Options are

As is
Mean 0
Mean 0, Max range 100
Mean 0, Mean range 100
Min 0 (default)
Min 0, Max range 100
Min 0, Mean range 100

Order levels Whether the levels of each attribute should be order or plotted as is.

Attributes to exclude from ordering If levels are ordered, individual attributes can be omitted from sorting.

Zero line width Line width of the axis line at Utility = 0. Often you want to emphasize this line but it can also hidden by setting the width to zero.

Additional Properties

When using this feature you can obtain additional information that is stored by the R code which produces the output.

  1. To do so, select Create > R Output.
  2. In the R CODE, paste: item = YourReferenceName
  3. Replace YourReferenceName with the reference name of your item. Find this in the Report tree or by selecting the item and then going to Properties > General > Name from the object inspector on the right.
  4. Below the first line of code, you can paste in snippets from below or type in str(item) to see a list of available information.

For a more in depth discussion on extracting information from objects in R, checkout our blog post here.

Code

includeWeb("QScript R Output Functions");
if (Q.fileFormatVersion() <= 17.09) {
    alert("This Utilities plot button is not functional in this version of Q. " + 
          "You can create the same plot via the menus at Automate > Browse Online Library > Choice Modelling > Utilities Plot");
} else {

    // Separate selected item from the group/page
    var selected_items = project.report.selectedRaw();
    var selected_item = selected_items[0];
    var selected_group = selected_item.type == "ReportGroup" ? selected_item : selected_item.group;
    var is_displayr = (!!Q.isOnTheWeb && Q.isOnTheWeb());

    if (is_displayr) {
        try {
            var new_output = selected_group.group.appendPage("Title and Content");
        } catch(e) {
            var new_output = selected_group.group.appendPage("TitleOnly");
        }
        new_output.subItems[0].text = "Utilities Plot";
        new_output.name = "Utilities Plot";
        var component_plot = new_output.appendStandardR("Choice Modeling - Utilities Plot", { "formInput": selected_item.guid});
        selected_group.group.moveAfter(new_output, selected_group);
        project.report.setSelectedRaw([new_output]);
    } else {

        var component_plot = selected_group.appendStandardR("Choice Modeling - Utilities Plot", { "formInput": selected_item.guid});
        selected_group.moveAfter(component_plot, selected_item);
        project.report.setSelectedRaw([component_plot]);
    }
}