跳转到主内容
跳转到主内容

varSampStable

varSampStable

引入版本:v1.1

计算数据集的样本方差。与 varSamp 不同,该函数使用数值稳定算法。运行速度较慢,但计算误差更小。

样本方差的计算公式与 varSamp 相同:

Σ(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

Syntax

varSampStable(x)

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. Float64

Examples

Computing stable sample variance

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(varSampStable(x),3) AS var_samp_stable FROM test_data;
┌─var_samp_stable─┐
│           0.865 │
└─────────────────┘