How to Compute Statistics for Variables (e.g., Average, Maximum, Number of Responses)
|Related Online Training modules|
|Generally it is best to access online training from within Q by selecting Help > Online Training|
Mathematical Functions (by Case) automatically creates a new variable that is a result of the function of the selected input variables. It can also be used to find specific values in the input variables. It consists of commonly used mathematical functions: Sum, Minimum, Maximum, Average, Standard Deviation, Variance and Count; as well as two logical functions: Any of and None of. New variables can be created by going to Variables and Questions tab, selecting the variables to be included in the function, right-clicking and selecting Insert Ready-Made Formula(s) > Mathematical Functions (by Case) > function.
Depending on values, Q might ask the user to confirm if the variable should be computed using incomplete data; if Yes, Q will compute the data using whatever data is available for each respondent. If No, Q returns missing data (NaN) for respondents with a missing value for any of the variables included in the calculation. The functions can be used with Numerical, Categorical and Money variable type. The resulting variable will contain the result of the mathematical function on respondent level. The resulting variable will be of the Numerical type for all mathematical functions, and of the Categorical type for logical function Any of and None of. The resulting variable type can be changed from Numerical to Categorical.
The user can pick from the following Mathematical Functions (by case):
The Sum function returns a numeric variable equal to the sum value of of selected variables. The function can be used to calculate the sum of selected variables. It can also be used to count the number of selected codes in Pick Any question type, assuming that selected values are coded as 1, and non selected values are coded as 0.
The Minimum function returns the smallest value from the set of selected variables.
The Maximum function returns the largest value from the set of selected variables.
The Average function returns the average value from the set of selected variables.
The Standard deviation function returns the standard deviation value form the set of selected variables. The standard deviation is a measure of how widely values are dispersed from the average value (the mean).
The Variance function returns the variance value from the set of selected variables. Variance is a measure of how far a set of numbers is spread out from their average value.
The Count function returns the number of occasions that a specific value(s) appears within the input variables. When used with Pick Any variables the function will return the count of the number of selected variables (e.g. value equal to 1). When used with Categorical variables (e.g. 5-point scale) or Money variable the will have to define which values(s) are to be counted. In the below example we are using the function with a Pick One - Multi variable to count how many of the presented audio formats a respondent is listening to at least daily.
To do that, we can add values 7 and 8 into the single value field and add them individually, or alternatively we can set-up a range. Note, that when setting up a range the function will count all the instances where at least one of the values within the range is found.
The result will be a Numeric variable which can be used to calculate the average number of music formats listened to daily. To analyse the frequency, change the question type from Numeric to Categorical > Pick One.
The Any of... function looks for a specific value(s), returning a categorical variable with values of 0 ‘Not selected’ when none of the values were found, or 1 ‘Selected’ when at least one of the values is found. Similar to the Count function it checks for the presence of the value but instead of the number of instances the value was found, it only returns the information if the value was found or not.
The None of… works in the opposite way to the Any of… function. It looks for a specific value(s) returning a categorical variable with values of 0 ‘Not selected’ when at least one of the values is found, and 1 ‘Selected’ when none of the values is found.
Editing of a variable constructed using Mathematical Functions (by Case)
Variables created can be copied and edited. To edit the variable right-click on the variable in the Variables and Questions tab > Edit Variable. A new Edit Java-Script Variable window will appear allowing the user to edit the variable. See our blog post to learn more about Java-Script Variables in Q.