Skip to main content

Documentation Index

Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-replace-private-preview-badge-man.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

varSamp

Introduced in: v1.1.0 Calculate the sample variance of a data set. The sample variance is calculated using the formula: Σ(xxˉ)2n1\frac{\Sigma{(x - \bar{x})^2}}{n-1}
Where:
  • xx is each individual data point in the data set
  • xˉ\bar{x} is the arithmetic mean of the data set
  • nn is the number of data points in the data set
The function assumes that the input data set represents a sample from a larger population. If you want to calculate the variance of the entire population (when you have the complete data set), you should use varPop instead.
This function uses a numerically unstable algorithm. If you need numerical stability in calculations, use the varSampStable function. It works slower but provides a lower computational error.
Syntax
varSamp(x)
Aliases: VAR_SAMP Arguments
  • x — The population for which you want to calculate the sample variance. (U)Int* or Float* or Decimal*
Returned value Returns the sample variance of the input data set x. Float64 Examples Computing sample variance
Query
DROP TABLE IF EXISTS test_data;
CREATE TABLE test_data
(
    x Float64
)
ENGINE = Memory;

INSERT INTO test_data VALUES (10.5), (12.3), (9.8), (11.2), (10.7);

SELECT round(varSamp(x),3) AS var_samp FROM test_data;
Response
┌─var_samp─┐
│    0.865 │
└──────────┘