Calculation - Standard Deviation - Standard Deviation

From Q
Jump to navigation Jump to search


This tool can be used to compute the standard deviation of the numbers in a table or variable, the standard deviation of matching elements of several tables, or the case-wise standard deviation of several variables in your data set. The result will depend on which items in your document you select before using this tool:

  1. If a single table is selected, the result will show the standard deviation of the numbers in that table.
  2. If two or more tables are selected, the result will show the standard deviation of the matching parts of those tables. Matching is done based on common row and column labels.
  3. If a single variable is selected, the result will show the standard deviation of the numbers of the variable.
  4. If two or more variables are selected, this tool will create a new variable that contains the standard deviation of those variables for each case.

Usage

  1. Select one or more tables on your page, two or more variables in the Variables and Questions tabunder Data Sets, or a single variable set in the Variables and Questions tabunder Data Sets
  2. From the toolbar, select Automate > Browse Online Library > Calculation > Standard Deviation > Standard Deviation

Example

You can use this tool to compute the standard deviation of the numbers in a single table. For example, this table shows the average number of orders per month that people placed at a selection of restaurants.

The result of applying Standard Deviation is:

Note that by default, the standard deviation calculation will exclude any SUM or NET rows or columns in the table, and you can control which rows or columns to exclude in the options (see below).

If you have many tables that share common row and column labels, then you can use this tool to compute the standard deviation for each element that matches between those tables. For example, these tables show the average orders placed at a selection of restaurants. They have common row labels, although a mistake has led the rows of the last table to be out of order:

Applying Standard Deviation to these tables produces a new table that contains the standard deviation of each matching item among the four tables:

Note that the tool has correctly matched up all of the common rows, despite the rows in the last table being out of order.

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 If this option is checked, than any missing values in any of the inputs will be ignored in the calculation. If unchecked, then missing values are not removed before calculation and will propagate as missing values in the output.

Variance formula / Standard Deviation formula This option allows you to choose whether the Population or Sample formula is used to compute the Variance or Standard Deviation (see below).

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

The default option is to compute the variance or standard deviation using the sample variance formula rather than the population variance formula. You have the option to choose between these two formulas so that you can apply whichever is relevant to your calculation. If you are a Q user, or are comparing results to those obtained in Q, please note that this default is different to Q's Insert Ready-Made Formulas > Variance and Insert Ready-Made Formulas > Standard Deviation which always use the population formula. In both cases, the standard deviation is the square root of the variance, and the two variance formulas are:

Sample Variance

[math]\displaystyle{ \sigma_{sample}^2=\frac{\sum^n_{i=1}(x_i -\frac{\sum^n_{i=1}x_i }{n})^2}{n-1} }[/math]

Population Variance

[math]\displaystyle{ \sigma_{population}^2=\frac{\sum^n_{i=1}(x_i -\frac{\sum^n_{i=1}x_i }{n})^2}{n} }[/math]

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.

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

applyCalculationOnSelections('Standard Deviation');

See also