用排列檢定分析偏態資料
當資料不符合你已知假設檢定的條件時,排列檢定會很有用。在本練習中,你會用 statsmodels 套件撰寫一個排列檢定。
你想比較分析(analytics)領域公司與其他所有風險投資公司之間的平均募資輪次。雖然你可能想用 t 檢定,但你可以確定募資輪次並非常態分配。相反地,多數公司只有 1 輪,擁有 2 輪或以上的公司數量會快速下降。
以下物件已為你載入:
analytics_df-所有 analytics 公司的資料non_analytics_df-所有非 analytics 公司的資料
本練習屬於課程
Python 推論基礎
練習說明
- 定義一個統計量函式,給定兩個樣本
fundings_group_1和fundings_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)