變更常態分配的平均數
在這個練習中,你會用取樣來計算美國成年男性平均身高的 95% 信賴區間。請回想課程中提到:美國成年男性的身高近似常態分配,平均數為 177 公分,標準差為 8 公分。
在使用上述樣本統計量從該分配取樣之後,你會把身高的平均數改為 185 公分,但不改變標準差,藉此觀察再次取樣後,平均數與平均身高的信賴區間會發生什麼變化。
以下內容已為你匯入:random、將 NumPy 匯入為 np,以及 SciPy 的 stats 模組作為 st。
本練習屬於課程
Python 的 Monte Carlo 模擬
練習說明
- 從平均數為 177、標準差為 8 的常態分配取樣 1,000 次;將結果存為
heights_177_8。 - 從平均數為 185、標準差為 8 的常態分配取樣 1,000 次;將結果存為
heights_185_8。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
random.seed(1222)
# Sample 1,000 times from the normal distribution where the mean is 177
heights_177_8 = ____
print(np.mean(heights_177_8))
upper = np.quantile(heights_177_8, 0.975)
lower = np.quantile(heights_177_8, 0.025)
print([lower, upper])
# Sample 1,000 times from the normal distribution where the mean is 185
heights_185_8 = ____
print(np.mean(heights_185_8))
upper = np.quantile(heights_185_8, 0.975)
lower = np.quantile(heights_185_8, 0.025)
print([lower, upper])