Modify Footers - Add Footer Showing Smallest Sample Size on Table

From Q
Jump to navigation Jump to search


This rule adds a footer showing the smallest sample size on the table (using Column n).

Example

Smallest sample size: 15 observations.

Technical detail

Prior to 3 September 2014, this rule shows the smallest [n] on a table.

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();

if (table.availableStatistics.indexOf('Column n') === -1)
{
    let statistic_name = inDisplayr() ? 'Sample Size' : 'n';
    form.ruleNotApplicable('This rule only applies to tables with the Column ' + statistic_name + ' statistic');
}
//Create form
form.setSummary('Add a footer with the smallest sample size on the table');
form.setHeading('Add Footer Showing Smallest Sample Size on Table');
let stat_name = table.getTranslation('Column n');
let description = form.newLabel('Adds a footer showing the smallest smaple size on the table (using ' + stat_name + ')');
form.setInputControls([description]);

//Apply rule
let column_ns = table.get('Column n');// Get the Column N statistics.

let smallest_size = column_ns [0][0];// Keep track of the smallest size.
for (let row = 0; row < table.numberRows; row++)
   for (let col = 0; col < table.numberColumns; col++)
        smallest_size = Math.min(smallest_size, column_ns [row][col]);
table.extraFooters = ['Smallest sample size: ' + smallest_size + ' observations.'];

See also