開始使用免費開始

常態性檢定

有一整套強大的統計工具(包含多種常見的假設檢定)都建立在資料服從常態分配的假設上。直方圖可以提示資料是否大致呈常態,但各種假設檢定能讓我們直接檢驗這個假設。此外,直方圖對於箱數非常敏感,尤其在樣本量很小時更是如此。

在這個練習中,你會使用 salary_df 中奧斯汀市員工的薪資資料。特別是針對西語裔的消防員。你將使用 Anderson–Darling 假設檢定,分析他們的任職年數是否大致呈常態分配。

本練習屬於課程

Python 推論基礎

檢視課程

練習說明

  • 繪製員工 Years of Employment 的直方圖。
  • 進行 Anderson–Darling 常態性檢定,查看 Years of Employment 是否大致呈常態分配。
  • 找出檢定 statistic 大於哪些 critical_values。
  • 列印在那些 significance_level 下會拒絕虛無假設。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Plot a histogram of the employees' "Years of Employment"
____.plot(kind="____")
plt.show()

# Conduct an Anderson-Darling test using the years of employment from salary_df
result = stats.____(____)

# Print which critical values the test statistic is greater than the critical values
print(result.____ > result.____)

# Print the significance levels at which the null hypothesis is rejected
print(result.____[result.____ > result.____])
編輯並執行程式碼