Visualizando o valor de p
Neste exercício, você vai visualizar o valor de p, a chance de que o efeito (ou "velocidade") que estimamos seja resultado de variação aleatória na amostra. Seu objetivo é visualizar isso como a fração de pontos na distribuição do teste embaralhado que ficam à direita da média do teste estatístico ("tamanho do efeito") calculado a partir das amostras não embaralhadas.
Para começar, já carregamos group_duration_short e group_duration_long e as funções compute_test_statistic(), shuffle_and_split() e plot_test_statistic_effect()
Este exercicio faz parte do curso
Introdução à Modelagem Linear em Python
Instruções do exercicio
- Use
compute_test_statistic()para obtertest_statistic_unshuffleda partir degroup_duration_shortegroup_duration_long; depois usenp.mean()para calcular o tamanho do efeito. - Use
shuffle_and_split()para criarshuffle_half1eshuffle_half2, e usecompute_test_statistic()para calculartest_statistic_shuffled. - Crie uma máscara booleana
conditionem que os valores detest_statistic_shuffledsejam maiores ou iguais aeffect_size, depois use essa máscara para calcular op_value. - Imprima o
p_valuee plote ambos os testes estatísticos usandoplot_test_statistic_effect().
exercicio interativo prático
Tente este exercicio completando este código de exemplo.
# Compute the test stat distribution and effect size for two population groups
test_statistic_unshuffled = compute_test_statistic(____, ____)
effect_size = np.mean(____)
# Randomize the two populations, and recompute the test stat distribution
shuffled_half1, ____ = shuffle_and_split(group_duration_short, ____)
test_statistic_shuffled = compute_test_statistic(shuffled_half1, ____)
# Compute the p-value as the proportion of shuffled test stat values >= the effect size
condition = ____ >= ____
p_value = len(test_statistic_shuffled[____]) / len(test_statistic_shuffled)
# Print p-value and overplot the shuffled and unshuffled test statistic distributions
print("The p-value is = {}".format(____))
fig = plot_test_stats_and_pvalue(test_statistic_unshuffled, test_statistic_shuffled)