# Significance Testing in Tables - Row Comparisons Using Column %

This rule creates row comparisons - the same as Column Comparisons, but for rows, comparing the Column % statistics, where each row in the table is assigned a letter. Note that if using this rule, you also need to:

• Select Edit > Table Options > Output Text and set the Override Text to Row Comparisons for Column Comparisons (this changes the wording that appears at the top-left of the table).
• Set Show significance to Compare columns in order for the results of this rule to be visible.

## Technical details

• Comparisons are performed using the Chi-Square Test for Compatibility of K Counts for each pair of rows within each column of the table.
• Other than design effects and weights, the specified Statistical Assumptions in Q are not taken into account by this test. That is, it will not take into account multiple comparison corrections, minimum sample size specifications, specified significance levels, etc. See also Modifying Significance Tests Using Rules.
• The levels of significance that are used can be modified by editing the rule. The default values are 0.1 and 0.05 (i.e., 90% and 95%).
• NET rows are automatically excluded from the testing.

## 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("QScript Utility Functions");

// Check the suitability of the table for the rule.
if (table.statistics.indexOf('Column %') == -1)
form.ruleNotApplicable("this rule requires that the table shows Column %");
if (table.blueQuestion.questionType != 'Pick One' && table.blueQuestion.questionType != 'Pick One - Multi')
form.ruleNotApplicable(correctTerminology("this rule is only applicable to tables with a Pick One or Pick One - Multi question in the rows."));
if (table.numberRows > 26)
form.ruleNotApplicable("this Rule only works with 26 or fewer rows");

let description_1 = form.newLabel("Conducts pairwise comparisons between the rows of the table using the Column %.");
description_1.lineBreakAfter = true;

// Get the relevant statistics and check the suitability of the table
let population = table.get('Population');
let base_population = table.get('Base Population');
let effective_base = table.get('Effective Base n');
let cc = table.get('Column Comparisons');

// Set up controls for user input.
form.setSummary('Compare the rows of the table using the Column %.');
let levels = ['90%','95%', '99%', '99.9%'];
let lower_combobox = form.newComboBox('lowercase', levels);
lower_combobox.setDefault('90%');
lower_combobox.lineBreakAfter = true;
let UPPER_combobox = form.newComboBox('UPPERCASE', levels);
UPPER_combobox.setDefault('95%');
let label_1 = form.newLabel('Lowercase confidence level:');
let label_2 = form.newLabel('Uppercase confidence level:');
let qs = [2.705543, 3.841459, 6.634897, 10.827566];
let lower_q = qs[levels.indexOf(lower_combobox.getValue())];
let UPPER_q = qs[levels.indexOf(UPPER_combobox.getValue())];
form.setInputControls([description_1, label_1, lower_combobox, label_2, UPPER_combobox]);

// Removing the current Column Comparisons.
for (let row = 0; row < table.numberRows; row++) {
for (let column = 0; column < table.numberColumns; column++) {
cc[row][column] = '';
}
}

// Doing the testing
let UPPER = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
let lower = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
let net_rows = table.netRows;
for (let c = 0; c < table.numberColumns; c++) {
let effective_multipler = base_population[0][c] / effective_base[0][c];
for (let bottom_row = 1; bottom_row < table.numberRows; bottom_row++) {
for (let top_row = 0;  top_row < bottom_row;  top_row++) {
if (net_rows.indexOf(bottom_row) == -1 && net_rows.indexOf(top_row) == -1) {
let o_top = population[top_row][c] * effective_multipler;
let o_bottom = population[bottom_row][c] * effective_multipler;
let e = (o_top + o_bottom) / 2.0;
let X2 = e > 0 && o_top != o_bottom ? (Math.pow(o_top - e, 2) + Math.pow(o_bottom - e, 2)) / e : 0.0;
if (X2 > UPPER_q) {
if (o_top > o_bottom) {
cc[top_row][c] += UPPER[bottom_row] + " ";
} else {
cc[bottom_row][c] += UPPER[top_row] + " ";
}
} else if (X2 > lower_q) {
if (o_top > o_bottom) {
cc[top_row][c] += lower[bottom_row] + " ";
} else {
cc[bottom_row][c] += lower[top_row] + " ";
}
}
}
}
}
}
// Updating the row labels
let row_labels = table.rowLabels;
for (let r = 0; r < table.numberRows; r++)
if (net_rows.indexOf(r) == -1)
row_labels[r] = row_labels[r] + ' [' + UPPER[r] + ']';
table.set('Column Comparisons', cc); //updating the column comparisons
table.rowLabels = row_labels;
form.setTranslation("Column Comparisons", "Row Comparisons");