變更常態分配的標準差
你會繼續探索美國成年男性的身高。你已經知道這些身高近似呈常態分配,平均數為 177 公分,標準差為 8 公分。
在這個練習中,你同樣會從常態分配取樣,並計算平均身高的 95% 信賴區間。不過這次,你會把標準差改為 15,而不改變平均數。你將觀察當再次進行取樣時,平均數與其信賴區間會發生什麼變化!
以下物件已為你匯入:random、以 np 命名的 NumPy,以及以 st 命名的 SciPy stats 模組。
本練習屬於課程
Python 的 Monte Carlo 模擬
練習說明
- 從平均數為 177、標準差為 15 的常態分配取樣 1,000 次,並將結果儲存到
heights_177_15。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
random.seed(1231)
heights_177_8 = st.norm.rvs(loc=177, scale=8, size=1000)
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 standard deviation is 15
heights_177_15 = ____
print(np.mean(heights_177_15))
upper = np.quantile(heights_177_15, 0.975)
lower = np.quantile(heights_177_15, 0.025)
print([lower, upper])