开始使用免费开始使用

检验统计量与效应量

如何用自助法重采样来探索线性关系?继续上路吧!每条徒步对应一个点,您可以看到总路程与经过时间呈线性关系。若把总路程视为时间的"效应",我们就能进一步探究线性回归与统计推断之间的内在联系。

在本练习中,您将把数据分成两个人群(或"类别"):早期时间与晚期时间。接着,您将考察每个人群内总路程的差异。这个差异将作为"检验统计量",其分布用于检验按时间分组对路程的影响。

ch04_ex11_fig03.png

本练习是课程的一部分

Python 线性建模入门

查看课程

练习说明

  • 使用 numpy 的"逻辑索引",例如 sample_distances[sample_times < 5],将样本 distances 按时间分成早期与晚期两组。
  • 使用 np.random.choice() 且设置 replacement=True,为两个时间分箱各创建一个 resample
  • test_statistic 数组计算为 resample_long - resample_short,并使用 np.mean()np.std() 求出并打印效应量与不确定性。
  • 绘制 test_statistic 的分布,使用预定义的 fig = plot_test_statistic()

交互式实操练习

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

# Create two poulations, sample_distances for early and late sample_times.
# Then resample with replacement, taking 500 random draws from each population.
group_duration_short = sample_distances[____ < 5]
group_duration_long = sample_distances[____ > 5]
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)

# Difference the resamples to compute a test statistic distribution, then compute its mean and stdev
test_statistic = resample_long - resample_short
effect_size = np.mean(____)
standard_error = np.std(____)

# Print and plot the results
print('Test Statistic: mean={:0.2f}, stdev={:0.2f}'.format(____, ____))
fig = plot_test_statistic(____)
编辑并运行代码