Significance Testing in Tables - Color Significant Cells
Jump to navigation
Jump to search
Q Technical Reference
Q Technical Reference
Q Technical Reference > Creating And Modifying Tables
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > Table JavaScript and Plot JavaScript
Rule Online Library
Tests of Statistical Significance
This rule changes the color of the cells in the table when the results in the cells are found to be significant. This is equivalent to Q's standard Cell Comparisons, indicated by the arrows and font colors, except that the whole cell will be colored rather than just the fonts.
Example
Technical details
The results shown as significant will match the results shown by Q's standard Cell Comparisons testing, which is indicated by arrows and font colors. To remove the arrows or font colors (or both), make a selection from the Show significance menu above the table.
How to apply this rule
For the first time in a project
- Select the table(s)/chart(s) that you wish to apply the rule to.
- Start typing the name of the Rule into the Search features and data box in the top right of the Q window.
- Click on the Rule when it appears in the QScripts and Rules section of the search results.
OR
- Select Automate > Browse Online Library.
- Choose this rule from the list.
Additional applications of the rule
- Select a table or chart that has the rule and any table(s)/chart(s) that you wish to apply the rule to.
- Click on the Rules tab (bottom-left of the table/chart).
- Select the rule that you wish to apply.
- Click on the Apply drop-down and choose your desired option.
- Check New items to have it automatically applied to new items that you create. Use Edit > Project Options > Save as Template to create a new project template that automatically uses this rule.
Removing the rule
- Select the table(s)/chart(s) that you wish to remove the rule from.
- Press the Rules tab (bottom-right corner).
- Press Apply next to the rule you wish to remove and choose the appropriate option.
How to modify the rule
- Click on the Rules tab (bottom-left of the table/chart).
- Select the rule that you wish to modify.
- Click Edit Rule and make the desired changes. Alternatively, you can use the JavaScript below to make your own rule (see Customizing Rules).
JavaScript
includeWeb("Table JavaScript Utility Functions")
excludeRTables();
// Form for picking colors
form.setHeading("Color Significant Cells");
form.setSummary("Color significant cells");
let description = form.newLabel("Choose the colors for cells which are significantly high or low.");
description.lineBreakAfter = true;
let high_color_picker = form.newColorPicker("hcolor");
high_color_picker.setDefault("YellowGreen");
high_color_picker.lineBreakAfter = true;
let high_label = form.newLabel("Significantly high:");
let low_label = form.newLabel("Significantly low:");
let low_color_picker = form.newColorPicker("lcolor");
low_color_picker.setDefault("Orange");
form.setInputControls([description, high_label, high_color_picker, low_label, low_color_picker]);
let high_color = high_color_picker.getValue();
let low_color = low_color_picker.getValue();
// Color the cells
colorSignificantCells(table, high_color, low_color);
if (belowTableExists())
colorSignificantCells(below_table, high_color, low_color);
if (rightTableExists())
colorSignificantCells(right_table, high_color, low_color);
function colorSignificantCells(table_object, high_color, low_color) {
if (table_object.availableStatistics.indexOf('z-Statistic') > -1) {
// Existing colors in table
let colors = table_object.cellColors;
// To evaluate coloring
let significant = table_object.cellSignificance;
let zs = table_object.get('z-Statistic');
// Work out which cells to color
for (let row = 0; row < table_object.numberRows; row++) {
for (let col = 0; col < table_object.numberColumns; col++) {
if (significant[row][col]) {
if (zs[row][col] > 0)
colors[row][col] = high_color;
else
colors[row][col] = low_color;
}
}
}
table_object.cellColors = colors;
}
}
See also
- User Input for Rules for technical information on Rules.
- Rule Online Library for other examples of Rules.
- Table JavaScript and Plot JavaScript for the JavaScript that is used to write custom rules.
- JavaScript for information about the JavaScript programming language.
Q Technical Reference
Q Technical Reference
Q Technical Reference > Creating And Modifying Tables
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > Table JavaScript and Plot JavaScript
Rule Online Library
Tests of Statistical Significance