モデル推論の解釈

Pythonで学ぶ一般化線形モデル

Ita Cirovic Donev

Data Science Consultant

β係数の推定

  • 最尤推定(MLE)
  • 推定係数 $\hat\beta$
    • 対数尤度が最大

尤度関数

Pythonで学ぶ一般化線形モデル

β係数の推定

  • 逐次再重み付け最小二乗法(IRLS)

当てはめたモデルのサマリー出力

Pythonで学ぶ一般化線形モデル

有意性の検定

係数推定に関する統計量を強調した当てはめ結果のサマリー。

Pythonで学ぶ一般化線形モデル

標準誤差(SE)

  • 山が平坦
    $\rightarrow$ 最大値の位置が不明瞭
    $\rightarrow$ SEが大きい

標準誤差が大きいときの尤度の可視化。

  • 山が鋭い
    $\rightarrow$ 最大値の位置が明確
    $\rightarrow$ SEが小さい

標準誤差が小さいときの尤度の可視化。

Pythonで学ぶ一般化線形モデル

標準誤差の計算

# Extract variance-covariance matrix
print(model_GLM.cov_params())
           Intercept    weight
Intercept   0.774762 -0.325087
weight     -0.325087  0.141903
# Compute standard error for weight
std_error = np.sqrt(0.141903)
0.3767

分散共分散行列

分散共分散行列の図

Pythonで学ぶ一般化線形モデル

有意性の検定

  • z統計量 $$ \color{#2485F2}{z=\hat\beta/SE} $$

  • $\color{#2485F2}{z}$ が大きい $\Rightarrow$ 係数 $\ne0$ $\Rightarrow$ 変数は有意

  • 目安: 閾値は 2

: スナホリガニのモデル
y ~ weight

$z = 1.8151/0.377 = 4.819$

Pythonで学ぶ一般化線形モデル

βの信頼区間

  • 推定値の不確実性
  • $\beta$ の95%信頼区間

$$ [\color{#5A5AF3}{下限},\color{#D8498E}{上限}] $$

$$ [\color{#5A5AF3}{\hat\beta - 1.96 \times SE},\color{#D8498E}{\hat\beta+1.96 \times SE}] $$

Pythonで学ぶ一般化線形モデル

信頼区間の計算

例: スナホリガニのモデル

                 coef    std err   
<hr />-------------------------------
Intercept     -3.6947      0.880  
weight         1.8151      0.377  

Pythonで学ぶ一般化線形モデル

信頼区間の抽出

print(model_GLM.conf_int())
                  0         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Pythonで学ぶ一般化線形モデル

信頼区間の抽出

print(model_GLM.conf_int())
              lower         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Pythonで学ぶ一般化線形モデル

信頼区間の抽出

print(model_GLM.conf_int())
                  0     upper
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Pythonで学ぶ一般化線形モデル

オッズの信頼区間

  1. $\beta$ の信頼区間を抽出

  2. 端点を指数化

print(np.exp(model_GLM.conf_int()))
                  0          1
Intercept  0.004428   0.139519
weight     2.935348  12.851533
Pythonで学ぶ一般化線形モデル

Let's practice!

Pythonで学ぶ一般化線形モデル

Preparing Video For Download...