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

> 对来自两个总体的样本执行 Welch t 检验。

# welchTTest

<div id="welchTTest">
  ## welchTTest
</div>

引入版本：v21.1.0

对两个总体的样本执行 [Welch t 检验](https://en.wikipedia.org/wiki/Welch%27s_t-test)。

两个样本的值都在 `sample_data` 列中。
如果 `sample_index` 等于 0，则该行中的值属于第一个总体的样本。
否则，该值属于第二个总体的样本。
零假设为两个总体的均值相等。
假定总体服从正态分布。
总体的方差可以不相等。

**语法**

```sql theme={null}
welchTTest([confidence_level])(sample_data, sample_index)
```

**参数**

* `confidence_level` — 可选。用于计算置信区间的置信水平。[`Float`](/zh/reference/data-types/float)

**实参**

* `sample_data` — 样本数据。[`Int*`](/zh/reference/data-types/int-uint) 或 [`UInt*`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float) 或 [`Decimal*`](/zh/reference/data-types/decimal)
* `sample_index` — 样本索引。[`Int*`](/zh/reference/data-types/int-uint) 或 [`UInt*`](/zh/reference/data-types/int-uint)

**返回值**

返回一个包含两个或四个元素的 Tuple (如果指定了可选的 `confidence_level`) ：计算得到的 t 统计量、p 值，以及可选的置信区间下限和置信区间上限。[`Tuple(Float64, Float64)`](/zh/reference/data-types/tuple) 或 [`Tuple(Float64, Float64, Float64, Float64)`](/zh/reference/data-types/tuple)

**示例**

**Welch t 检验基础示例**

```sql title=Query theme={null}
CREATE TABLE welch_ttest (sample_data Float64, sample_index UInt8) ENGINE = Memory;
INSERT INTO welch_ttest VALUES (20.3, 0), (22.1, 0), (21.9, 0), (18.9, 1), (20.3, 1), (19, 1);

SELECT welchTTest(sample_data, sample_index) FROM welch_ttest;
```

```response title=Response theme={null}
┌─welchTTest(sample_data, sample_index)──────┐
│ (2.7988719532211235, 0.051807360348581945) │
└────────────────────────────────────────────┘
```

**指定置信水平**

```sql title=Query theme={null}
SELECT welchTTest(0.95)(sample_data, sample_index) FROM welch_ttest;
```

```response title=Response theme={null}
┌─welchTTest(0.95)(sample_data, sample_index)─────────────────────────────────────────┐
│ (2.7988719532211235, 0.05180736034858519, -0.026294346671631885, 4.092961013338302) │
└─────────────────────────────────────────────────────────────────────────────────────┘
```

**另请参阅**

* [Welch t 检验](https://en.wikipedia.org/wiki/Welch%27s_t-test)
* [studentTTest 函数](/zh/reference/functions/aggregate-functions/studentTTest)
