# Modify Tables or Plots - Show Maximum Column Sample Size in Statistics Below

This rule modifies the Column n and Column Population shown in the Statistics - Below so that it always shows the largest value of Column n from each column (i.e., the highest sample size). Ordinarily, the value of Column n is determined from the NET row, and so can be smaller than expected when some cases have Missing Data. This Rule is one method for addressing situations where the Column n Is Too Small.

## Example

In the table on the left the Column n varies within each column due to the pattern of Missing Data, and the value of Column n shown at the bottom of the table is the number of respondents that have complete data for all the rows. The table on the right shows the result from applying this Rule - the value of the Column n has been replaced with the largest value within each column.

## Technical details

Changing the Column n that is shown has no effect on the calculation of other statistics in the 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();
const column_n_name = table.getTranslation("Column n");
const weighted_column_n_name = table.getTranslation("Column Population");
const web_mode = inDisplayr();
const stats_below_wording = web_mode ? "Statistics > Below" : "Statistics - Below";
form.setHeading("Show Maximum " + column_n_name + " in Statistics Below");
form.setSummary("Show the maximum " + column_n_name + " in statistics below");
let description = form.newLabel("Show the largest " + column_n_name + "/" + weighted_column_n_name +
" for each column in " + stats_below_wording + ".");
form.setInputControls([description]);
// Checking to see where column n is available
if (!belowTableExists())
form.ruleNotApplicable("this rule only works on tables with Statistics - Below available")
if (table.availableStatistics.indexOf('Column n') == -1)
form.ruleNotApplicable("this rule only works on tables with " + column_n_name +
" in Statistics - Cells");
if (below_table.availableStatistics.indexOf('Column n') == -1)
form.ruleNotApplicable("this rule only works on tables with " + column_n_name +
" in Statistics - Below");
let n_rows = table.numberRows;
let n_columns = table.numberColumns;
let cell_column_ns = table.get('Column n');
let cell_column_population = table.get('Column Population');
let below_column_n = below_table.get('Column n');
let below_column_population = below_table.get('Column n');
let below_is_transposed = below_column_n.length > 1;
for (var c = 0; c < n_columns; c++){
let new_column_n = 0;
let new_column_pop = 0;
for (var r = 0; r < n_rows; r++) {
let cell_column_n = cell_column_ns[r][c];
let cell_column_pop = cell_column_population[r][c];
if (!isNaN(cell_column_n) && cell_column_n > new_column_n)
new_column_n = cell_column_n;
if (!isNaN(cell_column_pop) && cell_column_pop > new_column_pop)
new_column_pop = cell_column_pop;
}
if (below_is_transposed) {
below_column_n[c][0] = new_column_n;
below_column_population[c][0] = new_column_pop;
} else {
below_column_n[0][c] = new_column_n;
below_column_population[0][c] = new_column_pop;
}
}
below_table.set('Column n', below_column_n);
below_table.set('Column Population', below_column_population);
```

## See also

- User Input for Rules for technical information on Rules.
- Rule Online Library for other examples of Rules.
- Table JavaScript and Plot JavaScript for the JavaScript that is used to write custom rules.
- JavaScript for information about the JavaScript programming language.

Q Technical Reference

Q Technical Reference

Q Technical Reference > Creating And Modifying Tables

Q Technical Reference > Setting Up Data > Creating New Variables

Q Technical Reference > Updating and Automation > Automation Online Library

Q Technical Reference > Updating and Automation > JavaScript > Table JavaScript and Plot JavaScript

Rule Online Library