開始使用免費開始

平均數是否等於變異數?

在 Poisson 模型中,其中一個假設是平均數應該等於變異數。正如你在課堂中所學,如果這個假設不成立,就會出現過度離散(overdispersion)。若不對過度離散做調整,你會錯誤解讀該模型的標準誤。

在這個練習中,你會先計算雌性螃蟹「衛星雄蟹」數量的平均數與變異數。

crab 資料集已載入到你的工作環境。

本練習屬於課程

Generalized Linear Models in Python

檢視課程

練習說明

  • 使用 numpymean() 計算並印出衛星數變數 sat 的樣本平均數為 sat_mean
  • 使用 numpyvar() 計算並印出衛星數變數 sat 的樣本變異數為 sat_var
  • 計算並印出 sat_varsat_mean 的比值。

動手互動練習

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

# Compute and print sample mean of the number of satellites: sat_mean
____ = np.____(____.____)

print('Sample mean:', round(____, 3))

# Compute and print sample variance of the number of satellites: sat_var
____ = np.____(____.____)
print('Sample variance:', round(____, 3))

# Compute ratio of variance to mean
print('Ratio:', round(____/____, 3))
編輯並執行程式碼