A Rule governs how an output in Q, such as a chart or table, appears. The simplest rules are essentially identical to Conditional Formatting in Excel. For example, the chart below shades the bars proportional to the values. This example is created using Automate > Color Scale and modifying the color options (on the Rules tab, beneath the table).
Rules can also be used to manipulate the contents of outputs. In the example below, the sample size is inserted into each column heading. This uses Automate > Browse Online Library > Modify Headers > Add Sample Size to Column Labels.
In the next example, a traditional table has been over-written with results from a special form of regression, Shapley Driver Analysis. This example uses Regression - Legacy Driver Analysis - Table of Shapley Importance Scores, whereby a rule is added via QScript.
The process is as follows:
- The main table output is generated, which incorporates:
- Statistics selected by using the table context menu and the toolbar.
- Any changes to the row or column question's categories, including re-ordering, renaming, merging, etc. - any operation done via the table context menu and the toolbar.
- If there are any Statistics - Right selected, another table output is generated for the table on the right, which is merged with the main table output later.
- If there are any Statistics - Below selected, another table output is generated for the table below, which is merged with the main table output later.
- The multiple comparison correction is performed, generating the Corrected p and Multiple Comparison Adjustment statistics (which affect displays of significance).
- Cell significance is calculated, determining arrow length and font color.
- The sample size description (shown in the table's footer) is calculated from the table's cell statistics (n, Base n, etc.).
- If you apply a Rule to a basic non-R-based chart in Q or convert a table to this type of chart, the changes are effectively applied to the underlying table first and then carried over to the chart where applicable. The following chart types are the most compatible with Rules:
- Bar/Column/Line charts
- Stacked column/bar charts
- Grid of bars charts