Significance Testing in Tables - Row Comparisons Using Column %
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
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.
Example
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[0][c] / effective_base[0][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;
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