検定力

Pythonで学ぶ推測の基礎

Paul Savala

Assistant Professor of Mathematics

検定力を決める要因

標本サイズ 効果量 有意水準
大人数の集団の画像。 薬を投与される患者の画像。 95%信頼区間の画像。
Pythonで学ぶ推測の基礎

減量データのシミュレーション

from scipy.stats import norm


# 対照群: 平均 0 ポンド,標準偏差 1 ポンド
control = norm.rvs(loc=0,
scale=1,
size=100)
# 介入群: 平均 -2 ポンド,標準偏差 1 ポンド
treatment = norm.rvs(loc=-2, scale=1, size=100)
Pythonで学ぶ推測の基礎

t検定

$H_0$: 減量差はない(誤り)

$H_a$: 介入群は減量する(正しい)

結論: $H_0$ を棄却し $H_a$ を採択(正しい)。

from scipy.stats import ttest_ind


# t検定を実行 alpha = 0.05 t_test = ttest_ind(treatment, control, alternative='less')
# 有意か確認 print(t_test.pvalue < alpha)
TRUE
Pythonで学ぶ推測の基礎

小さい標本サイズ

control = norm.rvs(loc=0, scale=1, size=5)
treatment = norm.rvs(loc=-2, scale=1, size=5)

# t検定を実行 tt = ttest_ind(treatment, control, alternative='less')
print(tt.pvalue < 0.05)
FALSE

結論: H0 を棄却できず(誤り)

Pythonで学ぶ推測の基礎

小さい効果量

# 体重減少 = 0.2ポンド,標本サイズ = 100

treatment = norm.rvs(loc=-0.2, scale=1, size=100)
# t検定を実行 t_test = ttest_ind(treatment, control, alternative='less')
print(t_test.pvalue < 0.05)
FALSE
Pythonで学ぶ推測の基礎

効果が小さい?標本を大きく!

少人数の集団の隣に大人数の集団。

Pythonで学ぶ推測の基礎

検定力の定義

有意な効果があれば、検定は検出できるか?

虫眼鏡で手のばい菌を拡大表示。

検定力: 対立仮説 (Ha) が真のとき、与えたデータで帰無仮説 (H0) を棄却できる確率はどれくらいか。

標本収集の前に検定力を計算する

Pythonで学ぶ推測の基礎

検定力の計算

from statsmodels.stats import power
# 検定力関数
tt_power = power.TTestIndPower()


# 検定力を計算 pwr = tt_power.power(effect_size=0.2,
nobs1=100,
alpha=0.05)
print(pwr)
0.291

検出確率は低い!

Pythonで学ぶ推測の基礎

検定力の逆算

nobs1 = TTestIndPower().solve_power(effect_size=-0.2, 
                                    nobs1=None, # これを解く
                                    alpha=0.05,
                                    power=0.8)

print(nobs1)
13735.26
Pythonで学ぶ推測の基礎

練習しましょう!

Pythonで学ぶ推測の基礎

Preparing Video For Download...