Changing Table Name to Include Category Name With Lowest p-Value (Highest Confidence)

From Q
Jump to navigation Jump to search

This example uses table.calculateOutput() to calculate the table's statistics, then process them and extract the row heading that contains the lowest p-value statistic. It then changes the table's name in the report tree so that when exported, the title will include this information.

// Change the name of the table to include the category which has the lowest (most significant) p-value.
 
// Calculate the statistics.
var output = table.calculateOutput();
 
// Get the array of p-values.
var pvalues = output.get('p');
 
// Keep track of which row contains the lowest p-value.
var lowest_p;
var lowest_row;
 
for (var row = 0; row < output.numberRows; row++)
    for (var column = 0; column < output.numberColumns; column++) {
        var p = pvalues[row][column];
        if (row == 0 && column == 0) {
            lowest_p = p;
            lowest_row = row;
        } else {
            if (p < lowest_p) {
                lowest_p = p;
                lowest_row = row;
            }
        }
    }
 
// Now 'lowest_row' holds the number of the row with the lowest p value.
// Lets extract its label from the output.
var lowest_row_label = output.rowLabels[lowest_row];
 
// Change the name of the table to include the lowest row information.
table.name = table.name + ' (Most significant: ' + lowest_row_label + ', p = ' + lowest_p + ')';

See also