Page tree

Release 8.7.1


Contents:

   

Computes the variance among all values in a column using the sample statistical method. Input column can be of Integer or Decimal. If no numeric values are detected in the input column, the function returns 0

The variance of a set of values attempts to measure the spread in values around the mean. A variance of zero means that all values are the same, and a small variance means that the values are closely bunched together. A high value for variance indicates that the numbers are spread out widely. Variance is always a positive value.

If a row contains a missing or null value, it is not factored into the calculation.

NOTE: This function applies to a sample of the entire population. More information is below.

Relevant terms:

Term Description
Population Population statistical functions are computed from all possible values. See https://en.wikipedia.org/wiki/Statistical_population.
Sample

Sample-based statistical functions are computed from a subset or sample of all values. See https://en.wikipedia.org/wiki/Sampling_(statistics).

These function names include SAMP in their name.

NOTE: Statistical sampling has no relationship to the samples taken within the product. When statistical functions are computed during job execution, they are applied across the entire dataset. Sample method calculations are computed at that time.

  • This function is calculated across a sample of all values.

  • For more information on a population version of this function, see VAR Function.

In the following computation, the sample method computes variances with N - 1 as the divisor.

Var(X) = [Sum ((X - mean(X))2)] / (Count(X) - 1)

The square root of variance is standard deviation, which is used to measure variance under the assumption of a bell curve distribution. See STDEV Function.

For a version of this function computed over a rolling window of rows, see ROLLINGVAR Function.

Wrangle vs. SQL: This function is part of Wrangle, a proprietary data transformation language. Wrangle is not SQL. For more information, see Wrangle Language.


Basic Usage

varsamp(myRating)

Output: Returns the variance of the group of values from the myRating column using the sample method of calculation.

Syntax and Arguments

<span>varsamp</span>(col_ref) [group:group_col_ref] [limit:limit_count]


ArgumentRequired?Data TypeDescription
function_col_refYstringName of column to which to apply the function

For more information on the group and limit parameters, see Pivot Transform.

For more information on syntax standards, see Language Documentation Syntax Notes.

col_ref

Name of the column whose values you wish to use in the calculation. Column must be a numeric (Integer or Decimal) type.

  • Literal values are not supported as inputs.
  • Multiple columns and wildcards are not supported.

Usage Notes:

Required?Data TypeExample Value
YesString (column reference)myValues


Examples


Tip: For additional examples, see Common Tasks.

This example shows some of the statistical functions that use the sample method of computation. These include:
  • STDEVSAMP - computes standard deviation using the sample method. See STDEVSAMP Function.
  • VARSAMP - computes variance using the sample method. See VARSAMP Function.
  • STDEVSAMPIF - computes standard deviation based on a condition and using the sample method. See STDEVSAMPIF Function.
  • VARSAMPIF - computes standard deviation based on a condition and using the sample method. See VARSAMPIF Function

Source:

Students took tests on three consecutive Saturdays:


StudentDateScore
Andrew11/9/1981
Bella11/9/1984
Christina11/9/1979
David11/9/1964
Ellen11/9/1961
Fred11/9/1963
Andrew11/16/1973
Bella11/16/1988
Christina11/16/1978
David11/16/1967
Ellen11/16/1987
Fred11/16/1990
Andrew11/23/1976
Bella11/23/1993
Christina11/23/1981
David11/23/1997
Ellen11/23/1997
Fred11/23/1991

Transformation:

You can use the following transformations to calculate standard deviation and variance across all dates using the sample method. Each computation has been rounded to three digits.

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula round(stdevsamp(Score), 3)
Parameter: New column name 'stdevSamp'

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula round(varsamp(Score), 3)
Parameter: New column name 'varSamp'

You can use the following to limit the previous statistical computations to the last two Saturdays of testing: 

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula round(stdevsampif(Score, Date != '11\/9\/2019'), 3)
Parameter: New column name 'stdevSampIf'

Transformation Name New formula
Parameter: Formula type Single row formula
Parameter: Formula round(varsampif(Score, Date != '11\/9\/2019'), 3)
Parameter: New column name 'varSampIf'

Results:


StudentDateScorevarSampIfstdevSampIfvarSampstdevSamp
Andrew11/9/198194.5159.722131.67311.475
Bella11/9/198494.5159.722131.67311.475
Christina11/9/197994.5159.722131.67311.475
David11/9/196494.5159.722131.67311.475
Ellen11/9/196194.5159.722131.67311.475
Fred11/9/196394.5159.722131.67311.475
Andrew11/16/197394.5159.722131.67311.475
Bella11/16/198894.5159.722131.67311.475
Christina11/16/197894.5159.722131.67311.475
David11/16/196794.5159.722131.67311.475
Ellen11/16/198794.5159.722131.67311.475
Fred11/16/199094.5159.722131.67311.475
Andrew11/23/197694.5159.722131.67311.475
Bella11/23/199394.5159.722131.67311.475
Christina11/23/198194.5159.722131.67311.475
David11/23/199794.5159.722131.67311.475
Ellen11/23/199794.5159.722131.67311.475
Fred11/23/199194.5159.722131.67311.475

 

This page has no comments.