2021-02-08 12:58:27 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/aggregate-functions/reference/welchttest
2024-06-24 11:52:30 +00:00
sidebar_position: 212
2022-04-09 13:29:05 +00:00
sidebar_label: welchTTest
2021-02-08 12:58:27 +00:00
---
2022-06-02 10:55:18 +00:00
# welchTTest
2021-02-08 12:58:27 +00:00
2021-07-29 15:20:55 +00:00
Applies Welch's t-test to samples from two populations.
2021-02-08 12:58:27 +00:00
**Syntax**
``` sql
2022-01-01 06:37:18 +00:00
welchTTest([confidence_level])(sample_data, sample_index)
2021-02-08 12:58:27 +00:00
```
Values of both samples are in the `sample_data` column. If `sample_index` equals to 0 then the value in that row belongs to the sample from the first population. Otherwise it belongs to the sample from the second population.
The null hypothesis is that means of populations are equal. Normal distribution is assumed. Populations may have unequal variance.
2021-02-15 21:33:53 +00:00
**Arguments**
2021-02-08 12:58:27 +00:00
2023-04-19 15:55:29 +00:00
- `sample_data` — Sample data. [Integer ](../../../sql-reference/data-types/int-uint.md ), [Float ](../../../sql-reference/data-types/float.md ) or [Decimal ](../../../sql-reference/data-types/decimal.md ).
- `sample_index` — Sample index. [Integer ](../../../sql-reference/data-types/int-uint.md ).
2021-02-08 12:58:27 +00:00
2022-01-01 06:37:18 +00:00
**Parameters**
2023-04-19 15:55:29 +00:00
- `confidence_level` — Confidence level in order to calculate confidence intervals. [Float ](../../../sql-reference/data-types/float.md ).
2022-01-01 06:37:18 +00:00
2021-02-08 12:58:27 +00:00
**Returned values**
2022-02-16 08:59:49 +00:00
[Tuple ](../../../sql-reference/data-types/tuple.md ) with two or four elements (if the optional `confidence_level` is specified)
2021-02-12 19:52:02 +00:00
2023-04-19 15:55:29 +00:00
- calculated t-statistic. [Float64 ](../../../sql-reference/data-types/float.md ).
- calculated p-value. [Float64 ](../../../sql-reference/data-types/float.md ).
- calculated confidence-interval-low. [Float64 ](../../../sql-reference/data-types/float.md ).
- calculated confidence-interval-high. [Float64 ](../../../sql-reference/data-types/float.md ).
2021-02-08 12:58:27 +00:00
**Example**
Input table:
``` text
┌─sample_data─┬─sample_index─┐
│ 20.3 │ 0 │
│ 22.1 │ 0 │
│ 21.9 │ 0 │
│ 18.9 │ 1 │
│ 20.3 │ 1 │
│ 19 │ 1 │
└─────────────┴──────────────┘
```
Query:
``` sql
SELECT welchTTest(sample_data, sample_index) FROM welch_ttest;
```
Result:
``` text
┌─welchTTest(sample_data, sample_index)─────┐
│ (2.7988719532211235,0.051807360348581945) │
└───────────────────────────────────────────┘
```
**See Also**
2023-04-19 15:55:29 +00:00
- [Welch's t-test ](https://en.wikipedia.org/wiki/Welch%27s_t-test )
- [studentTTest function ](studentttest.md#studentttest )