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

> データセットの標本分散を計算します。

# varSamp

<h2 id="varSamp">
  varSamp
</h2>

導入バージョン: v1.1.0

データセットの標本分散を計算します。

標本分散は以下の式で計算されます：

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

<br />

ここで：

* $x$ はデータセット内の各データポイント
* $\bar{x}$ はデータセットの算術平均
* $n$ はデータセット内のデータポイント数

この関数は、入力データセットがより大きな母集団からのサンプルであることを前提としています。完全なデータセットが手元にあり、母集団全体の分散を計算したい場合は、代わりに [`varPop`](/reference/functions/aggregate-functions/varPop) を使用してください。

<Note>
  この関数は数値的に不安定なアルゴリズムを使用しています。計算において[数値安定性](https://en.wikipedia.org/wiki/Numerical_stability)が必要な場合は、[`varSampStable`](/reference/functions/aggregate-functions/varSampStable) 関数を使用してください。処理速度は遅くなりますが、計算誤差が小さくなります。
</Note>

**構文**

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

**別名**: `VAR_SAMP`

**引数**

* `x` — 標本分散を計算する対象の母集団。[`(U)Int*`](/reference/data-types/int-uint)、[`Float*`](/reference/data-types/float)、または [`Decimal*`](/reference/data-types/decimal)

**戻り値**

入力データセット `x` の標本分散を返します。[`Float64`](/reference/data-types/float)

**例**

**標本分散の計算**

```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(varSamp(x),3) AS var_samp FROM test_data;
```

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