Visualizar el valor p
En este ejercicio, vas a visualizar el valor p, es decir, la probabilidad de que el efecto (o «velocidad») que estimamos sea resultado de la variación aleatoria de la muestra. Tu objetivo es representarlo como la fracción de puntos en la distribución del estadístico de prueba barajado que caen a la derecha de la media del estadístico de prueba ("effect size") calculado a partir de las muestras sin barajar.
Para empezar, hemos precargado group_duration_short, group_duration_long y las funciones compute_test_statistic(), shuffle_and_split() y plot_test_statistic_effect().
Este ejercicio forma parte del curso
Introducción al modelado lineal en Python
Instrucciones del ejercicio
- Usa
compute_test_statistic()para obtenertest_statistic_unshuffleda partir degroup_duration_shortygroup_duration_long; luego usanp.mean()para calcular el tamaño del efecto. - Usa
shuffle_and_split()para crearshuffle_half1yshuffle_half2, y usacompute_test_statistic()para calculartest_statistic_shuffled. - Crea una máscara booleana
conditiondonde los valores detest_statistic_shuffledsean mayores o iguales queeffect_size, y usa esta máscara para calcular elp_value. - Imprime el
p_valuey representa ambos estadísticos de prueba conplot_test_statistic_effect().
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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)