ÎncepețiÎncepe gratuit

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

Vezi cursul

Instrucțiuni pentru exercițiu

  • Folosește compute_test_statistic() pentru a obține test_statistic_unshuffled din group_duration_short și group_duration_long; apoi folosește np.mean() pentru a calcula dimensiunea efectului.
  • Folosește shuffle_and_split() pentru a crea shuffle_half1 și shuffle_half2, și folosește compute_test_statistic() pentru a calcula test_statistic_shuffled.
  • Creează o mască booleană condition care verifică dacă valorile din test_statistic_shuffled sunt mai mari sau egale cu effect_size, apoi folosește această mască pentru a calcula p_value.
  • Afișează p_value și reprezintă grafic ambele statistici de test folosind plot_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)
Editează și rulează codul