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

> Aplica o teste t de Welch a amostras de duas populações.

# welchTTest

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

Introduzido em: v21.1.0

Aplica o [teste t de Welch](https://en.wikipedia.org/wiki/Welch%27s_t-test) a amostras de duas populações.

Os valores de ambas as amostras estão na coluna `sample_data`.
Se `sample_index` for igual a 0, o valor nessa linha pertence à amostra da primeira população.
Caso contrário, pertence à amostra da segunda população.
A hipótese nula é que as médias das populações são iguais.
Pressupõe-se uma distribuição normal.
As populações podem ter variâncias diferentes.

**Sintaxe**

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

**Parâmetros**

* `confidence_level` — Opcional. Nível de confiança para calcular os intervalos de confiança. [`Float`](/pt-BR/reference/data-types/float)

**Argumentos**

* `sample_data` — Dados da amostra. [`Int*`](/pt-BR/reference/data-types/int-uint) ou [`UInt*`](/pt-BR/reference/data-types/int-uint) ou [`Float*`](/pt-BR/reference/data-types/float) ou [`Decimal*`](/pt-BR/reference/data-types/decimal)
* `sample_index` — Índice da amostra. [`Int*`](/pt-BR/reference/data-types/int-uint) ou [`UInt*`](/pt-BR/reference/data-types/int-uint)

**Valor retornado**

Retorna um Tuple com dois ou quatro elementos (se o `confidence_level` opcional for especificado): a estatística t calculada, o valor p calculado e, opcionalmente, o limite inferior e o limite superior do intervalo de confiança calculado. [`Tuple(Float64, Float64)`](/pt-BR/reference/data-types/tuple) ou [`Tuple(Float64, Float64, Float64, Float64)`](/pt-BR/reference/data-types/tuple)

**Exemplos**

**Teste t de Welch básico**

```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) │
└────────────────────────────────────────────┘
```

**Com nível de confiança**

```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) │
└─────────────────────────────────────────────────────────────────────────────────────┘
```

**Veja também**

* [teste t de Welch](https://en.wikipedia.org/wiki/Welch%27s_t-test)
* [função studentTTest](/pt-BR/reference/functions/aggregate-functions/studentTTest)
