Vizualizarea valorii p
În acest exercițiu, vei vizualiza valoarea p – probabilitatea ca efectul (sau „viteza") estimat să fie rezultatul variației aleatoare din eșantion. Scopul tău este să reprezinți grafic această valoare ca fracție a punctelor din distribuția statisticii de test amestecate care se află la dreapta mediei statisticii de test („dimensiunea efectului") calculată din eșantioanele neamestecate.
Pentru a te ajuta să începi, am preîncărcat group_duration_short și group_duration_long, precum și funcțiile compute_test_statistic(), shuffle_and_split() și plot_test_statistic_effect().
Acest exercițiu face parte din cursul
Introducere în modelarea liniară în Python
Instrucțiuni pentru exercițiu
- Folosește
compute_test_statistic()pentru a obținetest_statistic_unshuffleddingroup_duration_shortșigroup_duration_long; apoi foloseștenp.mean()pentru a calcula dimensiunea efectului. - Folosește
shuffle_and_split()pentru a creashuffle_half1șishuffle_half2, și foloseștecompute_test_statistic()pentru a calculatest_statistic_shuffled. - Creează o mască booleană
conditioncare verifică dacă valorile dintest_statistic_shuffledsunt mai mari sau egale cueffect_size, apoi folosește această mască pentru a calculap_value. - Afișează
p_valueși reprezintă grafic ambele statistici de test folosindplot_test_statistic_effect().
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
# 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)