Modifying Tables or Plots - Ignore Missing Values In Column n In Statistics Below

From Q
Jump to: navigation, search

This rule modifies the Column n and Column Population statistics in the Statistics - Below for a crosstab so that they ignore any Missing Data in the question that is shown in the Blue drop-down. This has the effect of showing the sample sizes from the categories of the question in the Brown drop-down, taking into account any filters that are applied to the table. This rule is useful when you have a table with missing data and you want the column n to match with other tables that do not have missing data.

Example

The table below shows weekly cola consumption broken down by gender. There are 167 females in the sample, and 160 males. Due to respondents having Missing Data in the question Colas drunk in last week, the values of Column n reported at the bottom of the table for males and females are considerably smaller. The pattern of missing data can be seen by looking at the Column n in the cells.

When the rule is applied to the table, the Column n at the bottom of the table is adjusted to match the sample sizes of males and females from the question Q2. Gender.

ColumnNFromSummary1.PNG

Technical details

If a filter is applied to the table then the values of Column n and Column Population will be calculated using that filter.

This rule affects only the Column n and Column Population statistics in the Statistics - Below and has no effect on any other statistics in the table.

It is important to note that the Column % in the table is derived from the Column Population (equivalent to the Column n when the data is not weighted) for each cell of the table and does take into account Missing Data in the rows of the table. As a result, the values of the Column n and Column Population shown by this rule do not relate to the Column % when there is missing data in the rows of the table, and so care should be taken when reporting using these adjusted figures.

This rule is only applicable when a Pick One, Pick Any, or Pick Any - Compact question is selected in the Brown drop-down, and when the Column n is available in the Statistics - Below.

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.setSummary('Ignore Missing Values In Column n In Statistics Below');

var brown_question = table.brownQuestion;
var brown_type = brown_question.questionType;
var brown_allowed_types = ["Pick One", "Pick Any", "Pick Any - Compact"];

// Prevent rule from being run in inappropriate circumstances
if (!belowTableExists())
	form.ruleNotApplicable("the table does not have Statistics - Below");
if (below_table.availableStatistics.indexOf("Column n") == -1)
	form.ruleNotApplicable("the table does not have Column n in the Statistics - Below");
if (brown_allowed_types.indexOf(brown_type) == -1)
	form.ruleNotApplicable("the table does not have a Pick One, Pick Any or Pick Any - Compact question selected in the brown drop-down");

var temp_table = Q.calculateTable(brown_question, 'SUMMARY', ['!UseQFilters'], '!UseQWeight');

var summary_n = [temp_table.get('n').map(function (a) { return a[0]; } )];
var summary_population = [temp_table.get('Population').map(function (a) { return a[0]; } )];

setMarginalStatistic(below_table, "Column n", summary_n);
setMarginalStatistic(below_table, "Column Population", summary_population);

See also