答案1
您需要安装软件包AER
、MASS
和lmtest
。然后您可以使用它们的函数和数据集。以下是安装这些软件包并计算所需结果的代码:
install.packages("AER")
install.packages("MASS")
install.packages("lmtest")
data(RecreationDemand, package = "AER")
rd_nb <- MASS::glm.nb(trips ~ ., data = RecreationDemand)
lmtest::coeftest(rd_nb)
结果:
z test of coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.1219363 0.2143029 -5.2353 1.647e-07 ***
quality 0.7219990 0.0401165 17.9976 < 2.2e-16 ***
skiyes 0.6121388 0.1503029 4.0727 4.647e-05 ***
income -0.0260588 0.0424527 -0.6138 0.53933
userfeeyes 0.6691676 0.3530211 1.8955 0.05802 .
costC 0.0480087 0.0091848 5.2270 1.723e-07 ***
costS -0.0926910 0.0066534 -13.9314 < 2.2e-16 ***
costH 0.0388357 0.0077505 5.0107 5.423e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1