# Significance Testing in Tables - Row Comparisons Using Column %

Jump to: navigation, search

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

```// 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("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");

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

// Set up controls for user input.
form.setSummary('Row Comparisons using Column %');
var levels = ['90%','95%', '99%', '99.9%'];
form.setHeading('Row Comparisons using Column Percentages');
var lower_combobox = form.newComboBox('lowercase', levels);
lower_combobox.setDefault('90%');
var UPPER_combobox = form.newComboBox('UPPERCASE', levels);
UPPER_combobox.setDefault('95%');
var label_1 = form.newLabel('Lowercase confidence level:');
var label_2 = form.newLabel('UPPERCASE confidence level:');
var qs = [2.705543, 3.841459, 6.634897, 10.827566];
var lower_q = qs[levels.indexOf(lower_combobox.getValue())];
var UPPER_q = qs[levels.indexOf(UPPER_combobox.getValue())];
form.setInputControls([label_1, lower_combobox, label_2, UPPER_combobox]);

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

// Doing the testing
var 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'];
var 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'];
var net_rows = table.netRows;
for (var c = 0; c < table.numberColumns; c++) {
var effective_multipler = base_population[c] / effective_base[c];
for (var bottom_row = 1; bottom_row < table.numberRows; bottom_row++) {
for (var top_row = 0;  top_row < bottom_row;  top_row++) {
if (net_rows.indexOf(bottom_row) == -1 && net_rows.indexOf(top_row) == -1) {
var o_top = population[top_row][c] * effective_multipler;
var o_bottom = population[bottom_row][c] * effective_multipler;
var e = (o_top + o_bottom) / 2.0;
var 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
var row_labels = table.rowLabels;
for (var 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;
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.62928545,"math_prob":0.84138525,"size":6449,"snap":"2021-21-2021-25","text_gpt3_token_len":1614,"char_repetition_ratio":0.123816915,"word_repetition_ratio":0.08169597,"special_character_ratio":0.29151806,"punctuation_ratio":0.18204284,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97042817,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-22T20:51:37Z\",\"WARC-Record-ID\":\"<urn:uuid:815b3998-2d54-475a-b16a-73ba2a1af386>\",\"Content-Length\":\"52402\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ddf51dc3-9295-4c4f-a637-752ae95e796b>\",\"WARC-Concurrent-To\":\"<urn:uuid:b6c2169d-a328-4d3f-aaf6-c14476bc4dab>\",\"WARC-IP-Address\":\"20.62.191.84\",\"WARC-Target-URI\":\"https://wiki.q-researchsoftware.com/wiki/Significance_Testing_in_Tables_-_Row_Comparisons_Using_Column_%25\",\"WARC-Payload-Digest\":\"sha1:KRMBW5UYZULONLW3FCOONBQXH237IX32\",\"WARC-Block-Digest\":\"sha1:ZL3K7E6IFDYMMJB4RUVLJA2O36TPQ35S\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623488519735.70_warc_CC-MAIN-20210622190124-20210622220124-00258.warc.gz\"}"}