ComenzarEmpieza gratis

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

Ver curso

Instrucciones del ejercicio

  • Usa compute_test_statistic() para obtener test_statistic_unshuffled a partir de group_duration_short y group_duration_long; luego usa np.mean() para calcular el tamaño del efecto.
  • Usa shuffle_and_split() para crear shuffle_half1 y shuffle_half2, y usa compute_test_statistic() para calcular test_statistic_shuffled.
  • Crea una máscara booleana condition donde los valores de test_statistic_shuffled sean mayores o iguales que effect_size, y usa esta máscara para calcular el p_value.
  • Imprime el p_value y representa ambos estadísticos de prueba con plot_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)
Editar y ejecutar código