正規分布の標準偏差を変えてみる
アメリカ人成人男性の身長を引き続き見ていきます。これは平均177センチ、標準偏差8センチの正規分布に従うことがわかっています。
この演習では、正規分布からサンプリングして平均身長の95%信頼区間を計算します。ただし今回は、身長の平均は変えずに標準偏差を15に変更します。サンプリングをやり直したとき、平均と平均身長の信頼区間がどう変化するかを確認しましょう。
次のモジュールはすでにインポート済みです:random、NumPy は np、SciPy の stats モジュールは st。
この演習はコースの一部です
Pythonで学ぶモンテカルロ・シミュレーション
演習の手順
- 平均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])