You can choose the period to Compare and the period to compare against (Versus) in the settings for the new Question (see below). When placed in the Blue drop-down of a table with another Question in the Brown drop-down, the table will display results for the two columns of interest and the statistical testing in the table will reflect the comparison between the Compare period and the Versus period.
Example
This table shows the proportion of survey respondents who said they would consider eating from a set of different fast-food chains, by year:
The settings for statistical testing have been selected to highlight results that are significant compared to the previous period.
Using the Contrast Periods tool allows us to make a table which selects the period of interest, in this case 2017 and compare it to 2016:
.
Here, the test results are the same as the original table. However, if we instead wish to compare 2017 to 2015, a comparison which is not available in the original table except via the Column Comparisons statistic, we can change the Versus period to 2015, result in a table (or visualization) which shows these comparisons:
.
Usage
In Q:
- Select a Date question in the Variables and Questions tab.
- Select Automate > Browse Online Library > Create New Variables > Contrasts.
- To change the time periods that are being compared:
- Select the Contrasts Question in the Variables and Questions tab.
- Right-click and select Edit R Variable.
- Change the settings.
- Click Update R Variable.
In Displayr:
- Click the
to the right of the Contrasts Variable from the Data Sets tree.
- From the menu, select Ready-Made-New-Variables > Contrast Periods.
- To change the time periods that are being compared:
- Select the Contrasts Question in the Data Sets tree.
- In the Object Inspector, select Variable Sets > Properties > R CODE
- Change the settings.
- Click Calculate.
Settings
Date variable This is the variable that will be used to identify the periods to use in the contrast. Date aggregation Choose the level of aggregation for the periods you wish to compare. This can be Year, Quarter, Month, 4-Week, 2-Week, or Week. Compare This is the date period of interest to be shown in tables or charts. Versus This is the date period against which the results for Compare should be compared.
Technical details
The date periods available in the Compare and Versus menus are generated at the time you first use this tool. They are evaluated relative to the dates in your data set, and they are extended for a period of three years to allow you to continue to use the same Contrasts as you continue to update your data set with new data.
The Contrasts variable contains two categories, but only one of them is shown. Date values which are not in the Compare or Versus periods are assigned a missing value. The resulting statistical tests are then equivalent to a comparison between Compare and Versus.
How to apply this QScript
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Click on the QScript when it appears in the QScripts and Rules section of the search results.
OR
- Select Automate > Browse Online Library.
- Select this QScript from the list.
Customizing the QScript
This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.
Customizing QScripts in Q4.11 and more recent versions
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
- Press Edit a Copy (bottom-left corner of the preview).
- Modify the JavaScript (see QScripts for more detail on this).
- Either:
- Run the QScript, by pressing the blue triangle button.
- Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.
Customizing QScripts in older versions
- Contact support@q-researchsoftware.com to obtain a copy of the JavaScript code.
- Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
- Modify the JavaScript (see QScripts for more detail on this).
- Run the file using Automate > Run QScript (Macro) from File.
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.