詮釋模型推論

Generalized Linear Models in Python

Ita Cirovic Donev

Data Science Consultant

β 係數的估計

  • 最大概似估計(MLE)
  • 估計係數 $\hat\beta$
    • 對數概似達到最大值

概似函數

Generalized Linear Models in Python

β 係數的估計

  • 反覆加權最小平方法(IRLS)

配適模型的摘要輸出

Generalized Linear Models in Python

顯著性檢定

配適模型摘要,著重於係數估計的統計量。

Generalized Linear Models in Python

標準誤(SE)

  • 峰較平緩
    $\rightarrow$ 最大值位置較難界定
    $\rightarrow$ SE 較大

SE 較大時的概似視覺化。

  • 峰較尖銳
    $\rightarrow$ 最大值位置更清楚
    $\rightarrow$ SE 較小

SE 較小時的概似視覺化。

Generalized Linear Models in 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

變異—共變異矩陣

變異—共變異矩陣示意圖

Generalized Linear Models in Python

顯著性檢定

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

  • $\color{#2485F2}{z}$ 大 $\Rightarrow$ 係數 $\ne0$ $\Rightarrow$ 變數具顯著性

  • 經驗法則:臨界值為 2

範例:horseshoe crab 模型
y ~ weight

$z = 1.8151/0.377 = 4.819$

Generalized Linear Models in Python

β 的信賴區間

  • 估計的不確定性
  • $\beta$ 的 95% 信賴區間

$$ [\color{#5A5AF3}{lower},\color{#D8498E}{upper}] $$

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

Generalized Linear Models in Python

計算信賴區間

範例:horseshoe crab 模型

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

Generalized Linear Models in Python

擷取信賴區間

print(model_GLM.conf_int())
                  0         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Generalized Linear Models in Python

擷取信賴區間

print(model_GLM.conf_int())
              lower         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Generalized Linear Models in Python

擷取信賴區間

print(model_GLM.conf_int())
                  0     upper
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Generalized Linear Models in Python

勝算比的信賴區間

  1. 擷取 $\beta$ 的信賴區間

  2. 端點取指數

print(np.exp(model_GLM.conf_int()))
                  0          1
Intercept  0.004428   0.139519
weight     2.935348  12.851533
Generalized Linear Models in Python

一起來練習吧!

Generalized Linear Models in Python

Preparing Video For Download...