Automatically Applying Weights to Some Categories in a Banner

From Q
Jump to: navigation, search

Refer to:

This example can be run using C:\Program Files\Q\Examples\Phone 1.Q (this file may be in a different place on your computer). Note in this example that:

  • The weight variable that is automatically applied is not tagged as a weight and is not available in the Weight drop-down menu.
  • This example only changes the values in the cells of the table. It will not update any statistics selected by Statistics - Below.

This script will cause significance results to be displayed incorrectly. Please read Caveats for Table JavaScript before using this script.

// Finds any columns in the span 'Gender' and applies the weight with variable name 'q4' to them.
var spans = table.columnSpans;
var columns = null;
for (var i=0; i<spans.length; i++)
  if (spans[i].label == 'Gender')
      columns = spans[i].indices;
var weighted_table = calculateTable(table.blue, table.brown,['!UseQFilters'], 'q4');
var stats = table.statistics; //gets the names of the statistics shown on the table
if (columns != null)
    for (var i = 0; i < columns.length; i++) {
        var column = columns[i];
        // Copy the weighted statistics for the column to the current table .
        for (var stat = 0; stat < stats.length; stat++) {
            var weighted_values = weighted_table.get(stats[stat]);
            var main_values = table.get(stats[stat]);
            for (var row = 0; row < table.numberRows; row++)
                main_values[row][column] = weighted_values[row][column];
            table.set(stats[stat], main_values);// Set the altered values to the main table.
        }
}

See also