开始使用免费开始使用

用置换检验分析偏态数据

当不满足已知假设检验的前提条件时,置换检验会很有用。在本练习中,您将使用 statsmodels 包编写一个置换检验。

您想比较分析类公司与其他所有获得风险投资的公司之间,平均融资轮次数的差异。虽然可能会想用 t 检验,但可以确定融资轮次数并非正态分布。相反,大多数公司只有 1 轮,拥有 2 轮或更多轮次的公司数量会迅速下降。

已为您加载以下数据:

  • analytics_df —— 所有分析类公司的数据
  • non_analytics_df —— 所有其他非分析类公司的数据

本练习是课程的一部分

Python 推断基础

查看课程

练习说明

  • 定义一个统计量函数,给定两个样本 fundings_group_1fundings_group_2,返回其 funding_rounds 平均数之差。
  • 使用两个数据集的 funding_rounds 列、您定义的统计量函数以及 100 次重采样,进行置换检验。
  • 打印置换检验得到的 p 值。

交互式实操练习

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

# Write a "statistic" function which calculates the difference in means
def statistic(funding_group_1, funding_group_2):
  return ____(fundings_group_1) - ____(funding_group_2)

# Conduct a permutation test using 100 resamples
perm_result = stats.permutation_test((____['funding_rounds'], ____['funding_rounds']),
                                    statistic=____,
                                    n_resamples=____,
                                    vectorized=____)

# Print the p-value
____(____.pvalue)
编辑并运行代码