开始使用免费开始使用

原假设

在本练习中,我们将原假设表述为:

短时间与长时间的持续时长对总行驶距离没有影响。

我们把"效应量为 0"的含义解释为:如果将短时和长时之间的样本打乱,使两个新样本各自都混合了短时和长时行程,然后计算检验统计量,那么其平均值将为 0。

在本练习中,您的目标是完成打乱和重采样。请从预先定义的未打乱分组 group_duration_shortgroup_duration_long 开始。

本练习是课程的一部分

Python 线性建模入门

查看课程

练习说明

  • 使用 np.concatenate() 合并两个总体,然后使用 np.random.shuffle() 打乱该容器内的数值。
  • shuffle_bucket 对半切片,并对每个 shuffle_half 使用 np.random.choice() 进行重采样。
  • 通过用 resample_half2 减去 resample_half1 来计算 test_statistic
  • effect_size 计算为 test_statisticnp.mean(),并打印结果。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Shuffle the time-ordered distances, then slice the result into two populations.
shuffle_bucket = np.____((group_duration_short, group_duration_long))
np.random.shuffle(____)
slice_index = len(shuffle_bucket)//2
shuffled_half1 = shuffle_bucket[0:____]
shuffled_half2 = shuffle_bucket[____:]

# Create new samples from each shuffled population, and compute the test statistic
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic = ____ - ____

# Compute and print the effect size
effect_size = np.mean(____)
print('Test Statistic, after shuffling, mean = {}'.format(____))
编辑并运行代码