Segments - Segment Comparison Table

From Q
Jump to: navigation, search


Example

Options

Segmentation A nominal or ordinal variable. The categories of the variable will make up the columns of this table.

Profiling variables One or more variable or variable sets. These can be of any type except text.

Show index values Show column percentages as a proportion of the total for the row. This is the same as shown in Q tables.

Color cell fill conditional on cell values Color cells to reflect the values in the cells. Standardized values which are higher than average will be shown in blue, whereas standardized values lower than average will be shown in red. Numeric values are standardized by dividing by 2 * standard deviation as suggested by Gelman (2007). Column percentages are divided by row totals (i.e. they are the index values).

Color cell text conditional on significance Color the text in the cells based on whether the average or column percentage is significantly different from the value for observations not in that segment (i.e. column).

Non-significant font color The text in cells which are not significant will be shown in this color instead of the font color.

Use non-parametric test For numeric variables, use the ranks instead of the numeric values to conduct the t-test. This is the same as using a non-parametric test in the statistical assumptions for a Q Table.

False discovery rate correction Adjust p-values to account for the multiple tests conducted in the table.

Confidence level Threshold used in the test to determine significance.

Rows to hide Specify rows to hide as a comma separated list. Row names which are not used in the table will be ignored. Use double quotes to escape row names containing commas.

Decimals shown for percentages Number of decimals shown for categoric variables.

Decimals shown for numeric data Number of decimals shown for numeric variables.

Font family The font family for all text in the table

Font size The font size of all text in the table.

Font units The units in which the font size is specified. This can be either "px" or "pt".

Row height The height of a row in the table (with no word wrap). This value will be specified in terms of font units. By default it is 5 + font size.

Column widths A column separated list of values (including units, e.g. "px", "pt", "%") specifying the widths of the column. Each value will be a single column starting from the left. The remaining columns with no specified widths will be equally sized to fill the remaining space.

Column header fill The color of the column header cells.

Row header fill The color of the row header cells containing the names of the profiling variables.

Summary rows fill The color of the cells in the first two rows showing the breakdown of the segmentation variable.

Cell fill The color of the cells (excluding row/column headers) and cells colored by conditional formatting.

Border color The color of the border.

Border width The width of the border in pixels.

Code

form.dropBox({label: "Segmentation",
            types:["Variable: Categorical, OrderedCategorical"],
            prompt: "Categorical grouping variable used to predict the outcome variables",
            name: "formSegmentation"})

form.dropBox({label: "Profiling variables", name: "formVariables",
            types:["Questions:!Text", "Variables:!Text"], multi: true});

form.group({label: "Display", expanded: true});
form.checkBox({name: "formIndexValues", label: "Show index values", default_value: false,
    prompt: "Show column percentages as a ratio to the row total"});
var condFill = form.checkBox({name: "formCondFill", label: "Color cell fill conditional on cell values", default_value: true,
    prompt: "Values which are higher than the row mean are shown in blue, and values lower than the row mean are shown in red. Numeric values are scaled by 2 * standard deviation."});  
var condText = form.checkBox({name: "formCondText", label: "Color cell text conditional on significance testing", default_value: true,
    prompt: "Grey out values which are not significantly different from the row mean"});
if (condText.getValue())
{
    form.colorPicker({name: "formCondTextColor", label: "Non-significant font color", default_value: "#999999"});
    form.checkBox({name: "formNonparametric", label: "Use non-parametric test", default_value: false, 
                  prompt: "Convert numeric variables to ranks before performing significance tests"});   
    form.checkBox({name: "formFDR", label: "False discovery rate correction", default_value: false});
    form.numericUpDown({name: "formConfidenceLevel", label: "Confidence level", default_value: 0.95, minimum: 0.0, maximum: 1.0, increment: 0.01});
}
form.textBox({name: "formRowsHide", label: "Rows to hide", default_value: "NET, Total, SUM", prompt: "Specify rows to hide as a comma-separated list. Use double-quotes to escape commas", required: false})

form.page("Format");
form.group("Number formatting");
form.numericUpDown({name: "formDecimalsPercentage", label: "Decimals shown for percentages", default_value:0});
form.numericUpDown({name: "formDecimalsNumeric", label: "Decimals shown for numeric data", default_value: 1});

form.group("Font");
var fontFamilies = font_families = ["Andale Mono", "Arial", "Arial Black", "Century Gothic", "Comic Sans MS",
                 "Courier New", "Georgia", "Impact", "Times New Roman", "Trebuchet MS", "Verdana"];
form.comboBox({name: "formFontFamily", label: "Font family", default_value: "Arial", alternatives: fontFamilies});
form.colorPicker({name: "formFontColor", label: "Font color", default_value: "#000000"});
var fontSize = form.numericUpDown({name: "formFontSize", label: "Font size", default_value: 8});
form.comboBox({name: "formFontUnits", label: "Font units", alternatives: ["pt", "px"], default_value: "pt"});


form.group("Spacing");
form.numericUpDown({name: "formRowHeight", label: "Row height", default_value: fontSize.getValue() + 5});
form.textBox({name: "formColumnWidths", label: "Column widths", required: false, default_value: "100px, 100px",
     prompt: "Comma separated values, e.g. '40px, 25%' or leave blank for equal widths"});

form.group("Borders and fill");
form.colorPicker({name: "formColHeadFill", label: "Column header fill", default_value: "#AEB7BA"});
form.colorPicker({name: "formRowHeadFill", label: "Row header fill", default_value: "#F1F3F4"});
form.colorPicker({name: "formSummaryFill", label: "Summary rows fill", default_value: "#D1D7D9"});
form.colorPicker({name: "formCellFill", label: "Cell fill", default_value: "#FFFFFF"});
form.colorPicker({name: "formBorderColor", label: "Border color", default_value: "#FFFFFF"});
form.numericUpDown({name: "formBorderWidth", label: "Border width", default_value: 1});
library(flipAnalysisOfVariance)
segment.table <- SegmentComparisonTable(formVariables, formSegmentation,
                       show.index.values = formIndexValues,
                       format.conditional.fill = formCondFill,
                       format.percentage.decimals = formDecimalsPercentage,
                       format.numeric.decimals = formDecimalsNumeric,    
                       font.color.set.if.nonsignificant = formCondText,
                       font.color.nonsignificant = formCondTextColor,
                       font.color.confidence = formConfidenceLevel,
                       font.color.FDRcorrection = formFDR,
                       font.color.nonparametric = formNonparametric,
                       row.names.to.remove = formRowsHide,
                       col.widths = formColumnWidths,
                       row.height = paste0(formRowHeight, formFontUnits), # set NULL for autofit
                       global.font.family = formFontFamily,
                       font.size = formFontSize,
                       font.color = formFontColor,
                       font.unit = formFontUnits,
                       col.header.fill = formColHeadFill,
                       row.header.fill = formRowHeadFill,
                       summary.cell.fill = formSummaryFill,
                       cell.fill = formCellFill,
                       border.color = formBorderColor,
                       border.width = formBorderWidth,
                       subset = QFilter,
                       weights = QPopulationWeight)