> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Calculate the sample variance of a data set. Unlike `varSamp` , this function uses a numerically stable algorithm. It works slower but provides a lower computational error.

# varSampStable

<h2 id="varSampStable">
  varSampStable
</h2>

Introduced in: v1.1.0

Calculate the sample variance of a data set. Unlike [`varSamp`](/reference/functions/aggregate-functions/varSamp), this function uses a [numerically stable](https://en.wikipedia.org/wiki/Numerical_stability) algorithm. It works slower but provides a lower computational error.

The sample variance is calculated using the same formula as [`varSamp`](/reference/functions/aggregate-functions/varSamp):

$$
\frac{\Sigma{(x - \bar{x})^2}}{n-1}
$$

<br />

Where:

* $x$ is each individual data point in the data set
* $\bar{x}$ is the arithmetic mean of the data set
* $n$ is the number of data points in the data set

**Syntax**

```sql theme={null}
varSampStable(x)
```

**Arguments**

* `x` — The population for which you want to calculate the sample variance. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal*`](/reference/data-types/decimal)

**Returned value**

Returns the sample variance of the input data set. [`Float64`](/reference/data-types/float)

**Examples**

**Computing stable sample variance**

```sql title=Query theme={null}
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;
```

```response title=Response theme={null}
┌─var_samp_stable─┐
│           0.865 │
└─────────────────┘
```
