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

> 对来自两个总体的样本应用 Mann-Whitney 秩检验。

# mannWhitneyUTest

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

引入版本：v21.1.0

对来自两个总体的样本应用 Mann-Whitney 秩检验。

两个样本的值都位于 `sample_data` 列中。
如果 `sample_index` 等于 0，则该行中的值属于第一个总体的样本。
否则，该值属于第二个总体的样本。
原假设是两个总体在随机意义上相等。
也可以检验单侧假设。
该检验不要求数据服从正态分布。

**语法**

```sql theme={null}
mannWhitneyUTest[(alternative[, continuity_correction])](sample_data, sample_index)
```

**参数**

* `alternative` — 可选。备择假设。'two-sided' (默认) ：两个总体在随机意义上不相同。'greater'：第一个样本在随机意义上大于第二个样本。'less'：第一个样本在随机意义上小于第二个样本。[`String`](/zh/reference/data-types/string)
* `continuity_correction` — 可选。如果不为 0，则在 p 值的正态近似中应用连续性校正。默认值为 1。[`UInt64`](/zh/reference/data-types/int-uint)

**Arguments**

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

**返回值**

返回一个包含两个元素的元组：计算得到的 U 统计量和 p 值。[`Tuple(Float64, Float64)`](/zh/reference/data-types/tuple)

**示例**

**Mann-Whitney U 检验示例**

```sql title=Query theme={null}
CREATE TABLE mww_ttest (sample_data Float64, sample_index UInt8) ENGINE = Memory;
INSERT INTO mww_ttest VALUES (10, 0), (11, 0), (12, 0), (1, 1), (2, 1), (3, 1);

SELECT mannWhitneyUTest('greater')(sample_data, sample_index) FROM mww_ttest;
```

```response title=Response theme={null}
┌─mannWhitneyUTest('greater')(sample_data, sample_index)─┐
│ (9,0.04042779918503192)                                │
└────────────────────────────────────────────────────────┘
```

**另请参阅**

* [Mann–Whitney U 检验](https://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U_test)
* [随机序](https://en.wikipedia.org/wiki/Stochastic_ordering)
