Aggregated scripts (AskiaAnalyse)

Aggregated scripts allow you to access aggregated calculations for a given set of respondents, which you can then use as the basis of further calculations. The calculation types for which this is available include count, mean, median, standard deviation, min, max and sum. You can use aggregated scripts, for example, to define calculated variables, using the resulting variables as the basis for the likes of simplified mean difference tables and variables split into percentiles; if the underlying data is updated, the resulting figures will remain up to date when the variable is recalculated.

AskiaScript contains special keywords for calculating aggregate values. In this topic, we we will go though an example: using an aggregated script to calculate the median. Several further examples are available in our knowledge base. For full technical detail, you can download a guide to aggregated scripts and table definitions, which contains details of the all of the scripting language definitions that can be used in aggregate scripts.

To create an aggregated script, you simply create a calculated variable, select the appropriate variable type and enter the script syntax. The example below demonstrates how this works when you are creating a script to calculate the median, and further examples can be found at the end of this topic.

Example: using an aggregated script to calculate the median

The following script syntax gives us the unweighted median:

Q1.data.median(0)

The data object accesses the data for the question (in this case Q1), and we retrieve median by using .median(0). The parameter (in this case, zero) determines whether interpolation will be used when calculating the median. Q1.data.median(1) would use interpolation.

Note: Interpolation determines how the median is determined where there is an even number of data points, and thus where we have no middle value. For unweighted data, when interpolation is used, the mean of the two middle values is used; without interpolation, the higher of the two middle values is used. For weighted data, a weighted average calculation is carried out. For further details, see the following article: https://dev.askia.com/issues/6278
 Note: Aggregated scripts can be used in created variables, cleaning scripts and calculation arithmetic scripts.

Further examples in detail

An example of an aggregated script that displays an average time, based on the mean of a specific question, can be found in the following article: AskiaaAnalyse version 5.3.5.0 notes. A link to a portfolio and QES file containing the example tab template can be found in the article.

The knowledge base contains detailed examples of aggregated scripts, including example files:

Create your own Knowledge Base