Significance Testing - Row Comparisons

From Q
Jump to: navigation, 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

form.setSummary('Calculate Row Comparisons');
table.requireOriginalRowsColumns();

try {
    // Run a crosstab of this table with the questions transposed.
    var 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");

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

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

See also