Tables - Multiway Table

From Q
Jump to: navigation, search

Creates a table with multiple categorical variables and, optionally, a numeric variable. Similar to a Pivot Table in Excel.

Creates a table with multiple categorical variables and, optionally, a numeric variable. Similar to a Pivot Table in Excel.

How to Create a Multiway Table

  1. Add the object:
    1. In Displayr: Insert > More > Tables > Multiway Table
    2. In Q: Create > Tables > Multiway Table
  2. Select the variables to use as the rows in Inputs > Rows.
  3. Optionally, use Inputs > Columns to specify the variables to use as the columns of the table.
  4. Selet the optional numeric variable with Inputs > Numeric variable.

Example

The table below uses Occupation and Work Status as the rows, with Gender as the columns, and Average monthly bill as the numeric variable.

Options

The options in the Object Inspector are organized into two tabs: Inputs and Properties.

Inputs

Rows The variables to appear in the rows, as categories.

Columns (Optional) The variables to appear in the columns, as categories.

Numeric variable (Optional) A variable to analyzing in the cells of the table.

Statistic The statistic to compute (e.g., mean, sum), when specifying both Columns and Numeric variable.

Mean
Minimum
Maximum
Sum

Hide empty rows Removes rows from the table that contain no data.

Hide empty columns Removes columns from the table that contain no data.

Filter The data is automatically filtered using any filters prior to estimating the model.

Weight Where a weight has been set for the R Output, the calibrated weight is used. See Weights in R.

Properties

This tab contains options for formatting the size of the object, as well as the underlying R code used to create the visualization, and the JavaScript code use to customize the Object Inspector itself (see Object Inspector for more details about these options). Additional options are available by editing the code.

More Information

Creating tables with multiple variables (filters and multiway tables)

Code

form.setHeading('Multiway Table');
form.dropBox({label: "Rows", 
            types:["Variable: Numeric, Date, Money, Categorical, OrderedCategorical"], 
            name: "formRows",
            multi:true})
var columns = form.dropBox({label: "Columns",
            types:["Variable: Numeric, Date, Money, Categorical, OrderedCategorical"], 
            name: "formColumns",
            multi: true, 
            required: false})
form.dropBox({label: "Numeric",
            types:["Variable: Numeric, Date, Money, Categorical, OrderedCategorical"], 
            name: "formNumeric",
            multi: false, 
            required: false})
form.comboBox({label: "Statistic", 
            alternatives: ["Mean", "Minimum", "Maximum", "Sum"], 
            name: "formStatistic", 
            default_value: "Mean"})
form.checkBox({label: "Hide empty rows", name: "formHideRows", default_value: true})
form.checkBox({label: "Hide empty columns", name: "formHideColumns", default_value: true})
library(flipStatistics)
multiway<- Multiway(formRows, 
    if (length(formColumns) == 0) NULL else formColumns,
    if (length(formNumeric) == 1) NULL else formNumeric,
    numeric.statistic = formStatistic,
    hide.empty.rows = formHideRows,
    hide.empty.columns = formHideColumns,
    subset = QFilter,
    weights = QPopulationWeight)