計算 Wald 統計量
在上一個練習中,你以 width 變數配適了一個模型,並評估了解釋變數與反應變數之間的關係。這一題你將透過計算 Wald 統計量來評估 width 變數的顯著性。
另外請注意,在模型摘要中,Wald 統計量以字母 z 表示,代表該統計量的值服從標準常態分配。回顧 Wald 統計量的公式:
$$ z=\frac{\hat\beta}{SE} $$
其中 \(\hat\beta\) 是估計係數,\(SE\) 是其標準誤。
已在工作空間預先載入配適好的模型 crab_GLM 與資料集 crab。
本練習屬於課程
Generalized Linear Models in Python
練習說明
- 使用
.params擷取並印出模型係數,並分別儲存為 intercept 與 slope。 - 將共變異數矩陣儲存並印出為
crab_cov。 - 使用共變異數矩陣擷取相應元素,計算並印出標準誤
std_error。 - 計算並印出 Wald 統計量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Extract coefficients
intercept, slope = ____.____
# Estimated covariance matrix: crab_cov
____ = crab_GLM.____
print(____)
# Compute standard error (SE): std_error
____ = np.____(____.loc['width', 'width'])
print('SE: ', round(____, 4))
# Compute Wald statistic
wald_stat = ____/____
print('Wald statistic: ', round(____,4))