LoginSignup
0
2

More than 1 year has passed since last update.

中心極限定理 試してみた

Last updated at Posted at 2021-07-28

#前提
母集団の平均を$ μ $、分散を$ σ^2 $とおく

中心極限定理は、
母集団から抽出した標本の平均$\overline{x}$は平均μ、分散$ σ^2/n$の正規分布に従う
というものである。(平均・分散が存在しさえすれば母集団の分布に寄らない)

実際にpythonで$\overline{x}$を計算するために抽出する標本数nを増やしていき比較してみた

#pythonでサイコロを例に試行

サイコロを1回振った時の平均$μ$と分散$σ^2$はそれぞれ$ μ=3.5 $、$ σ^2=35/12 $
である

今回は抽出する標本数を変化させて、その標本平均と標準偏差それぞれを計算してみる
※標本平均のばらつきをわかりやすくするため、標本平均を抽出する回数を10回とする
(pythonのstreamlitライブラリを使用)

n=10の時

import streamlit as st
import numpy as np
import pandas as pd

st.title('n=10')

# 変数初期化
n = 10
sample_mean = []

for i in range(10): # 抽出回数は10回
    # 1~6までのさいころのランダムな目
    x = np.random.randint(1, 7, n)
    # 標本平均
    sample_mean.append(x.mean())

df = pd.DataFrame({
      '標本平均': sample_mean,
    })

# 結果
st.dataframe(df ,width=500)
st.write('標本平均の標準偏差:{}'.format(np.var(sample_mean)))

nが10.png

n=100の時

st.title('n=100')

# 変数初期化
n = 100
sample_mean = []

for i in range(10): # 抽出回数は10回
    # 1~6までのさいころのランダムな目
    x = np.random.randint(1, 7, n)
    # 標本平均
    sample_mean.append(x.mean())

df = pd.DataFrame({
      '標本平均': sample_mean,
    })

# 結果
st.dataframe(df ,width=500)
st.write('標本平均の標準偏差:{}'.format(np.var(sample_mean)))

nが100.png

n=1000の時

st.title('n=1000')

# 変数初期化
n = 1000
sample_mean = []

for i in range(10): # 抽出回数は10回
    # 1~6までのさいころのランダムな目
    x = np.random.randint(1, 7, n)
    # 標本平均
    sample_mean.append(x.mean())

df = pd.DataFrame({
      '標本平均': sample_mean,
    })

# 結果
st.dataframe(df ,width=500)
st.write('標本平均の標準偏差:{}'.format(np.var(sample_mean)))

nが1000.png

#考察
標本数nが大きいほど、標本平均は3.5に近づいていき、標準偏差は小さくなることが分かる

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2