開始使用免費開始

負二項式模型擬合

負二項式分配允許變異數大於平均數,而你在前一個練習中對 crab 資料的檢查也觀察到這種情形。本題要你回顧先前使用對數連結函式的 Poisson 迴歸擬合,並另外以相同的對數連結函式擬合負二項式模型。

你將分析並比較統計量如何改變。

工作空間中已載入模型 crab_pois 與資料 crab

本練習屬於課程

Generalized Linear Models in Python

檢視課程

練習說明

  • 定義迴歸模型的 formula,讓 satwidth 預測。
  • 使用 NegativeBinomial() 擬合負二項式模型,並將模型儲存為 crab_NB
  • 列印 Poisson 模型 crab_pois 與新擬合的負二項式模型的摘要。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Define the formula for the model fit
formula = '____ ~ ____'

# Fit the GLM negative binomial model using log link function
crab_NB = smf.glm(formula = ____, data = ____, 
				  family = ____.____.____).____

# Print Poisson model's summary
print(____.____)

# Print the negative binomial model's summary
print(____.____)
編輯並執行程式碼