Modifying the Whole Table or Plot - Hide Rows and Columns with Small Sample Sizes

From Q
Jump to: navigation, search

This rule hides any rows and columns in the table in which all of the cells have a sample size that is smaller than a certain value. The sample size for a cell is taken to be the Column n if available, and the Base n when the Column n is not available. You can choose the minimum sample size to keep in the table.

Example

The table below shows a cross tab between an Aided awareness question and Gender, and the rule has been applied to remove rows and columns with sample size less than 40. In this case, many respondents were not show the brand Optus due to the questionnaire logic, resulting in small sample sizes (i.e. Column n values of 38 and 39 respectively). Hence Optus has been removed. In many cases, small sample sizes in the rows or columns will lead to small sample sizes for the NET, and in this example the NET has also been removed. The rule has an option to prevent the removal of the main NET row or column for cases where this is not desirable.

HideSmallSample.png

Technical details

The options for this rule allow you to:

  1. Choose the minimum sample size to allow. Only rows or columns where all the cells fall below this sample size will be removed.
  2. Choose whether or not to always keep the NET row or column.

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("Table JavaScript Utility Functions");
form.setHeading("Hide rows and columns with small sample size");
 
if (table.availableStatistics.indexOf("Column n") == -1 && table.availableStatistics.indexOf("Base n") == -1) {
	form.ruleNotApplicable('table does not have Column n or Base n');
}
 
// Create the form
var label = form.newLabel('Minimum Sample Size:');
var numeric_up_down  = form.newNumericUpDown('threshold');
numeric_up_down.setDefault(30);
numeric_up_down.setIncrement(1);
numeric_up_down.setMaximum(999999999);
form.setInputControls([label, numeric_up_down]);
form.setOutputControls([]);
var min_sample = numeric_up_down.requireValue();
form.setSummary('Remove rows or columns where the sample size of all cell is less than ' + min_sample);
 
var stat = table.availableStatistics.indexOf("Column n") > 0 ? "Column n" : "Base n";
 
var values = table.get(stat);
 
var columns_to_remove = [];
var rows_to_remove = [];
 
// Search rows and columns
 
for (var row = 0; row < table.numberRows; row++) {
	if (allValuesBelowMinimum(values[row], min_sample))
		rows_to_remove.push(row);
}
 
for (var col = 0; col < table.numberColumns; col++) {
	if (allValuesBelowMinimum(values.map(function (row_array) { return row_array[col]; }), min_sample))
		columns_to_remove.push(col);
}
 
var removed_columns = columns_to_remove.map(function (x) { return table.columnLabels[x]; });
var removed_rows = rows_to_remove.map(function (x) { return table.rowLabels[x]; });
 
// Remove rows and columns identified
var footers = table.extraFooters;
// Remove empty rows
if (rows_to_remove.length > 0) {
    for (var j = rows_to_remove.length - 1; j > -1; j--) {
        deleteRowComplete(rows_to_remove[j])
    }
    footers.push("Some rows with sample sizes less than " + min_sample + " have been removed")
}
 
// Remove empty columns
if (columns_to_remove.length > 0) {
    for (var j = columns_to_remove.length - 1; j > -1; j--) {
        deleteColumnComplete(columns_to_remove[j]);
    }
    footers.push("Some columns with sample sizes less than " + min_sample + " have been removed")
}
 
table.extraFooters = footers;
 
 
 
function allValuesBelowMinimum(array, minimum_value) {
	return array.every(function (x) { return x < minimum_value; });
}

See also

Personal tools
Namespaces

Variants
Actions
Navigation
Categories
Toolbox