可视化检验统计量
在本练习中,您将通过两种不同方式得到的检验统计量的分布来接近原假设。
首先,您将考察按早期与晚期时间分组的两个"总体",并计算检验统计量的分布。其次,打乱这两个总体,使数据不再按时间排序,每个总体都混合了早期与晚期时间,然后重新计算检验统计量的分布。
为了便于开始,我们已预加载了两个时长分组 group_duration_short 和 group_duration_long,以及两个函数 shuffle_and_split() 和 plot_test_statistic()。
本练习是课程的一部分
Python 线性建模入门
练习说明
- 使用
np.random.choice()对group_duration_short和group_duration_long进行重采样,并对重采样结果取差以计算test_statistic_unshuffled。 - 对原始的
group_duration_short和group_duration_long(按此顺序)使用shuffle_and_split(),以创建两个新的混合总体。 - 对打乱后的总体进行重采样,并用
resample_long减去resample_short,计算新的test_statistic_shuffled。 - 使用
plot_test_statistic()绘制两个检验统计量分布,并进行可视化比较。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# From the unshuffled groups, compute the test statistic distribution
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)
test_statistic_unshuffled = ____ - ____
# Shuffle two populations, cut in half, and recompute the test statistic
shuffled_half1, shuffled_half2 = shuffle_and_split(____, ____)
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic_shuffled = resample_half2 - resample_half1
# Plot both the unshuffled and shuffled results and compare
fig = plot_test_statistic(____, label='Unshuffled')
fig = plot_test_statistic(____, label='Shuffled')