Modify Whole Table or Plot - Avoid Showing Outputs with Small Sample Sizes

From Q
Jump to: navigation, search

This rule prevents tables and charts from being shown if any of the questions have less than the specified number of observations.

Example

Output not shown because it is based on less than 10 observations.

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

let stat_name = table.getTranslation("Base n");
if (table.availableStatistics.indexOf('Base n') == -1)
    form.ruleNotApplicable('this format only applies to tables with the ' + stat_name +
			   ' statistic');
 
// Set up controls for user input.
form.setHeading('Avoid Showing Tables with Small Sample Sizes:');
form.setSummary('Avoid showing tables with small sample sizes:');
let description = form.newLabel('Suppress the table output if the sample size is too small.');
description.lineBreakAfter = true;
let label = form.newLabel('Minimum ' + stat_name + ':');
let 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]);
let min_n = numeric_up_down.requireValue();
form.setSummary('Avoid showing tables with small sample sizes < ' + min_n);  

let base_ns = table.get('Base n');// Get the 'Base n' statistic values for each cell.
 
// The message to show instead of the real table.
let message = 'Output not shown because it is based on less than ' + min_n + ' observations.\n';
 
// If any of the 'Base n' values are less than min_n, suppress the
// output with a message explaining why.
for (let row = 0; row < table.numberRows; row++)
   for (let column = 0; column < table.numberColumns; column++)
       if (base_ns[row][column] < min_n)
           table.suppressOutput(message);

See also