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

> covarSamp와 유사하지만, 연산 오차는 더 적은 대신 더 느리게 작동합니다.

# covarSampStable

<h2 id="covarSampStable">
  covarSampStable
</h2>

도입 버전: v1.1.0

표본 공분산을 계산합니다:

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

<br />

[`covarSamp`](/reference/functions/aggregate-functions/covarSamp)와 유사하지만 수치적으로 안정적인 알고리즘을 사용합니다.
따라서 `covarSampStable`은 `covarSamp`보다 느리지만 연산 오차가 더 작습니다.

**구문**

```sql theme={null}
covarSampStable(x, y)
```

**인수**

* `x` — 첫 번째 변수. [`(U)Int*`](/reference/data-types/int-uint) 또는 [`Float*`](/reference/data-types/float) 또는 [`Decimal`](/reference/data-types/decimal)
* `y` — 두 번째 변수. [`(U)Int*`](/reference/data-types/int-uint) 또는 [`Float*`](/reference/data-types/float) 또는 [`Decimal`](/reference/data-types/decimal)

**반환 값**

`x`와 `y` 사이의 표본 공분산을 반환합니다. `n <= 1`인 경우 `inf`를 반환합니다. [`Float64`](/reference/data-types/float)

**예시**

**안정적인 알고리즘을 사용한 기본 표본 공분산 계산**

```sql title=Query theme={null}
DROP TABLE IF EXISTS series;
CREATE TABLE series(i UInt32, x_value Float64, y_value Float64) ENGINE = Memory;
INSERT INTO series(i, x_value, y_value) VALUES (1, 5.6,-4.4),(2, -9.6,3),(3, -1.3,-4),(4, 5.3,9.7),(5, 4.4,0.037),(6, -8.6,-7.8),(7, 5.1,9.3),(8, 7.9,-3.6),(9, -8.2,0.62),(10, -3,7.3);

SELECT covarSampStable(x_value, y_value)
FROM
(
    SELECT
        x_value,
        y_value
    FROM series
);
```

```response title=Response theme={null}
┌─covarSampStable(x_value, y_value)─┐
│                 7.206275555555556 │
└───────────────────────────────────┘
```

**단일 값에서 inf 반환**

```sql title=Query theme={null}
SELECT covarSampStable(x_value, y_value)
FROM
(
    SELECT
        x_value,
        y_value
    FROM series LIMIT 1
);
```

```response title=Response theme={null}
┌─covarSampStable(x_value, y_value)─┐
│                               inf │
└───────────────────────────────────┘
```
