Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Teste T Pareado | Testes Estatísticos
Aprendendo Estatística com Python

book
Teste T Pareado

A função a seguir realiza um teste t pareado:

python
ttest_rel(a, b, alternative='two-sided')

Este processo se assemelha ao utilizado para amostras independentes, mas aqui não é necessário verificar a homogeneidade de variância. O teste t pareado explicitamente não assume que as variâncias são iguais.

Lembre-se de que, para um teste t pareado, é fundamental que os tamanhos das amostras sejam iguais.

Com essas informações em mente, prossiga para a tarefa de realizar um teste t pareado.

Aqui, estão disponíveis dados sobre o número de downloads de um determinado aplicativo. Observe as amostras: os valores médios são quase idênticos.

import pandas as pd
import matplotlib.pyplot as plt

# Read the data
before = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/before.csv').squeeze()
after = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/after.csv').squeeze()
# Plot histograms
plt.hist(before, alpha=0.7)
plt.hist(after, alpha=0.7)
# Plot the means
plt.axvline(before.mean(), color='blue', linestyle='dashed')
plt.axvline(after.mean(), color='gold', linestyle='dashed')
123456789101112
import pandas as pd import matplotlib.pyplot as plt # Read the data before = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/before.csv').squeeze() after = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/after.csv').squeeze() # Plot histograms plt.hist(before, alpha=0.7) plt.hist(after, alpha=0.7) # Plot the means plt.axvline(before.mean(), color='blue', linestyle='dashed') plt.axvline(after.mean(), color='gold', linestyle='dashed')
copy
Tarefa

Swipe to start coding

As hipóteses são estabelecidas:

  • H₀: A média do número de downloads antes e depois das alterações é a mesma;
  • Hₐ: A média do número de downloads é maior após as modificações.

Realize um teste t pareado com esta hipótese alternativa, utilizando before e after como as amostras.

Solução

import scipy.stats as st
import pandas as pd

before = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/before.csv').squeeze()
after = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/after.csv').squeeze()

stats, pvalue = st.ttest_rel(after, before, alternative='greater')
# Check the null hypothesis
if pvalue > 0.05:
print("We support the null hypothesis, the mean values are equal")
# Check the alternative hypothesis
else:
print("We reject the null hypothesis, the mean values are different")
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 6. Capítulo 8
single

single

import scipy.stats as st
import pandas as pd

before = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/before.csv').squeeze()
after = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a849660e-ddfa-4033-80a6-94a1b7772e23/Testing2.0/after.csv').squeeze()

stats, pvalue = ___(___)
# Check the null hypothesis
if pvalue > 0.05:
print("We support the null hypothesis, the mean values are equal")
# Check the alternative hypothesis
else:
print("We reject the null hypothesis, the mean values are different")

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt