Significance Testing in Tables - Row Comparisons

From Q
Jump to navigation Jump to search


This rule creates row comparisons - the same as Column Comparisons, but for rows, comparing the Row % statistics, where each row in the table is assigned a letter. The comparisons are shown to the right of the first statistic in each cell. It is generally helpful to show Row % on the table.

Example

RowComparisonsRule.PNG

Technical details

The results obtained from this rule are identical to those obtained if swapping the rows and columns and displaying the Column Comparisons.

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");
includeWeb('Table JavaScript Utility Functions');

excludeRTables();


form.setHeading('Row Comparisons');
form.setSummary('Compare the rows of the table using the Row %');
table.requireOriginalRowsColumns();

let description_1 = form.newLabel("Compare between rows in the table using the Row %.")
description_1.lineBreakAfter = true;

form.setInputControls([description_1]);

let transposed;
try {
    // Run a crosstab of this table with the questions transposed.
    transposed = calculateTable(table.brown, table.blue, ['!UseQFilters'], '!UseQWeight');
} catch (e) {
    form.ruleNotApplicable("can't swap rows and columns - needs 2 categorical variables");
}
if ((transposed == null) || (transposed.availableStatistics.indexOf('Column Names') < 0) || (transposed.availableStatistics.indexOf('Column Comparisons') < 0))
    form.ruleNotApplicable("can't swap rows and columns - needs 2 categorical variables");

let blue_question_type = table.blueQuestion.questionType;
let brown_question_type = table.brownQuestion.questionType;

let two_d_types = ["Pick One - Multi", "Pick Any - Grid", "Number - Grid"];

if (two_d_types.indexOf(brown_question_type ) > -1 || (two_d_types.indexOf(blue_question_type) > -1 && table.brown != "SUMMARY"))
    form.ruleNotApplicable('cannot calculate row comparisons for cross-tabs with two dimensional questions ("Pick One - Multi", "Pick Any - Grid", and "Number - Grid")');



// For each row of this table...
let row_labels = table.rowLabels;
let cell_text = table.cellText;

for (let row = 0; row < table.numberRows; row++) {
    // Get the column letter of this row in the transposed table.
    let column_letter = transposed.get('Column Names')[0][row];
 
    // Change the row label to include the 'column' letter.
    row_labels[row] = row_labels[row] + ' [' + column_letter + ']';
 
    // Get the column comparisons from the transposed table.
    let column_comparisons = transposed.get('Column Comparisons');
 
    // Store the column comparisons next to the primary statistic.
    for (let column = 0; column < table.numberColumns; column++) {
        // Removing spaces between column letters.
        let text_without_spaces = column_comparisons[column][row].replace(/ /g,"");
        // Set the text for the cell.
        cell_text[row][column] = [' ' + text_without_spaces];
    }
}

table.rowLabels = row_labels;
table.cellText = cell_text;

form.setTranslation("Column Comparisons", "Row Comparisons");

See also