Calculation - Maximum - Maximum

From Q
Jump to navigation Jump to search

Calculate the maximum of all elements for a single input or compute element-wise/case-wise maximum for multiple inputs This tool can be used to:

  1. Find the maximum value in a table.
  2. Find the elementwise maximum value among matching cells in two or more tables.
  3. Find the maximum value for each case among two or more variables.

Usage

Maximum Value in a Table

To find the largest value in a single table:

  1. Select the table on your page.
  2. Select Automate > Browse Online Library > Calculation > Maximum.
  3. Change options in the Object Inspector. These options are described below.

Elementwise Maximum Value in Two or More Tables

Multiple tables can be matched up based on common row and column labels, and the smallests values for each matching cell will be returned as a new table.

  1. Select all of the tables to include.
  2. Select Automate > Browse Online Library > Calculation > Maximum.
  3. Change options in the Object Inspector. These options are described below.

Maximum Value for Each Case

  1. Select the variables to include in the Variables and Questions tabunder Data Sets.
  2. Select Automate > Browse Online Library > Calculation > Maximum.
  3. Choose whether or not to compute the minimum for cases where some variables have missing data by toggling the option Calculate for observations with incomplete data. If you un-tick this option then any case for whom there are some missing values will be assigned a missing value.

Examples for Tables

When the input is a single table, the result will show the largest value in the table. For this table

Maxmimum gives the result

Note that the NET result of 100% has been excluded. You can choose which rows and columns of the input data will be included in the calculation.

When Maximum is used for two or more tables, it will match the tables by rows and columns and return the largest value for each matched cell. For example, these two tables show brand awareness for two different time periods:

When Maximum is used, the result looks like this:

Note that the brand Burger Chef is missing from the second table, but has been included in the final output. When items in a table do not match completely, you can choose to include or exclude them from the result.

Options

The output showing the results of the calculation has the following options available in the Object Inspector.

Input The tables to be used in the calculation.

Calculate for inputs with incomplete data A combo box with three options,

Yes (show warning) Any missing values in any of the inputs will be ignored in the calculation. If a missing value is present in the input then a warning that missing values being removed from the calculation will be presented to the user.
Yes The calculation will have the same behaviour as above, except the warning about missing values being removed from the calculation will not be given.
No Missing values are not removed before calculation and will propagate as missing values in the output.

Automatically match elements Only shown when there are multiple inputs to Input. This controls how and whether matching is done between the labels of the inputs. The default, "Yes - hide unmatched", will look for matching labels in the rows and columns of the inputs before proceeding with the calculation, and any rows/columns that are not contained in all the inputs will not be included in the output. See the Example. For a full description of the matching algorithm, see the Technical Details. "Yes - show unmatched" will also perform matching, but any unmatched rows (columns) will appear in the output as rows (columns) of all missing values. Selecting "No" for this option will cause any labels in the data to be ignored and not perform any matching. Selecting "Custom" will bring up two additional controls that allow for specifying the matching behavior for rows and columns separately.

Match rows Only shown if Automatically match elements is set to "Custom". Specifies the matching behavior when comparing row labels of the inputs. "Yes - show unmatched" and "Yes - hide unmatched" look for exact matches in the row labels in the inputs. "Fuzzy - show unmatched" and "Fuzzy - hide unmatched" perform fuzzy matching so that labels that differ only by a single character are considered to be a match.

Match columns Only shown if Automatically match elements is set to "Custom". The options are the same as Match rows, but control the matching between columns.

Rows to exclude Here you can type in row labels that should be excluded from the calculation.

Columns to exclude As above, but for columns.

Technical Details

When there are multiple inputs, inputs that contain only a single row (column) may be recycled to a matrix/table with the same number of rows (columns) as the other inputs. For example, if the supplied inputs are a table with three rows and two columns and another table with two rows and a single column, the single column will be expanded by rows into a table with three rows and two columns with each row identical to the original column.

When Automatically match elements is set to Yes - show unmatched or Yes - hide unmatched, both exact matches and fuzzy matches (as described above) are considered, and the order of elements may be permuted so that the names match. It also may transpose an input if, for example, the column names of one input match the row names of another input.

When Calculate for inputs with incomplete data is checked and the input to the calculation consists entirely of missing values, then the returned output value is set to missing data. Prior to 5th October, 2021 the returned output value was different in this situation. For example, consider the input into the calculation with the three values.

A B C
NaN NaN NaN

Then applying Maximum to this input would return the value of -Infinity before 5th October, 2021. After this date, the Maximum function returns the output value of NaN in this situation.

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

  • Copy the JavaScript shown on this page.
  • 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.

JavaScript

includeWeb('QScript Functions for Calculations');
includeWeb('QScript Functions to Generate Outputs');

applyCalculationOnSelections('Maximum');

See also