This rule allows you to replace the default significance arrows and font colors on a standard table...
...with symbols that denote the level of significance based on the Corrected p value:
Technical Details
- This rule works by looking at the Corrected p values in the cells of the table and so takes into account the Multiple Comparison Correction setting for Cell Comparisons.
- When running the rule, you will be presented with two input boxes. Completing both boxes will add a new pair of input boxes. When you have completed all your p-value limits, click OK without filling out the final pair of input boxes.
- Ticking the box labeled Show as confidence will only change the table footer and will show the p-values as percentage confidence levels.
- It is not possible to align the numbers when this rule is applied (i.e., the numbers will move to the left to accommodate the symbols).
- When exported, values with a symbol will be rounded in Excel tables. If exporting an Excel chart, the symbol will be removed, but the footer will remain.
Application
To use this Rule in Displayr, see How to Add Symbols to Significant Cells in Tables
To use this Rule in Q, see How to Add Symbols to Significant Cells in Tables
See Also
Code
// Add specified symbols to cells for specific p values.
// Set form title
form.setHeading("Add Symbols to Significant Cells");
form.setSummary("Add symbols to significant cells");
let description = form.newLabel("Specify symbols to add to cells when the Corrected p falls below certain values");
description.lineBreakAfter = true;
// Define default values and dimension variables/arrays
let no_specified_value = 0;
let no_specified_symbol = "";
let controls = [description];
let last_index = 0;
let current_index = 0;
let specified_p = [];
let specified_s = [];
// Function to sort 2D array by value in a
// Thanks: http://stackoverflow.com/questions/16096872/how-to-sort-2-dimensional-array-by-column-value
function sortFunction(descending) {
descending = typeof descending !== 'undefined' ? descending : true;
return function(a, b) {
if (a[0] === b[0]) {
return 0;
}
else {
return (a[0] < b[0]) ? (descending ? 1 : -1) : (descending ? -1 : 1);
}
}
}
// Add Show as confidence control
let show_as_confidence = form.newCheckBox("showasconfidence", "Show as confidence");
show_as_confidence.setDefault(false);
show_as_confidence.lineBreakAfter = true;
controls.push(show_as_confidence);
footer_show_as_confidence = show_as_confidence.getValue();
// Add controls to form
while (true) {
// Create input field objects
let specify_p_value = form.newNumberBox('pvalue' + current_index);
let specify_symbol = form.newTextBox('symbol' + current_index);
// Set input to default values
specify_p_value.setDefault(no_specified_value);
specify_symbol.setDefault(no_specified_symbol);
specify_symbol.lineBreakAfter = true;
// Add controls to form first time through
controls.push(form.newLabel("Corrected p:"));
controls.push(specify_p_value);
controls.push(form.newLabel("Symbol:"));
controls.push(specify_symbol);
// Temporarily store entered values
selected_p_value = specify_p_value.getValue();
selected_symbol = specify_symbol.getValue();
// Only add new form controls if the preceding has input
if (selected_symbol == no_specified_symbol)
break;
// Check that input values are within permitted ranges
else if (selected_p_value > 1 || selected_p_value < 0) {
form.ruleNotApplicable("the Corrected p is greater than 0 or less than 1");
break;
}
else {
// Store input values in arrays
specified_p.push(selected_p_value);
specified_s.push(selected_symbol);
// Track last index value
last_index = current_index + 1;
}
// increment index
current_index++;
}
form.setInputControls(controls);
// Only continue if inputs provided
// alert(specified_s[0]);
if (specified_s[0] == no_specified_symbol)
form.ruleNotApplicable("you have not entered a symbol");
// ...and if there are ps to check
if (table.availableStatistics.indexOf('Corrected p') == -1)
form.ruleNotApplicable("there are no p-values available on this table");
// Process input data
// Create 2D array of information
let merged_values_array = [];
for (j = 0; j < specified_p.length; j++)
merged_values_array[j] = [specified_p[j],specified_s[j]];
// Sort 2D array ascending based on ps (first index position)
merged_values_array.sort(sortFunction(descending = false));
// Get array of ps from table
// Get table values for statistic and text
let table_p_values = table.get('Corrected p');
let cell_texts = table.cellText;
// For each cell...
for (rows = 0; rows < table.numberRows; rows++) {
for (columns = 0; columns < table.numberColumns; columns++) {
// ...and each specified p
for (i = 0; i < specified_p.length; i++) {
if (table_p_values[rows][columns] <= merged_values_array[i][0]) {
cell_texts[rows][columns] = [merged_values_array[i][1]];
break;
}
}
}
}
// Show as confidence levels in footer
if (footer_show_as_confidence)
merged_values_array.forEach(function (a) { a[0] = (1 - a[0]) * 100;});
merged_values_array.sort(sortFunction(descending = !footer_show_as_confidence));
// Create footer text
let final_footer_addition = " ";
let footers = table.extraFooters;
merged_values_array.forEach(function (a) {
if (footer_show_as_confidence)
footers.push(a[1] + " " + a[0] + "% confidence");
else
footers.push(a[1] + " p <= " + a[0]);
});
table.extraFooters = footers;
// Update the table
table.cellText = cell_texts;