找回密码
 注册
查看: 986|回复: 0

R语言 AER包 CameronTrivedi1998()函数中文帮助文档(中英文对照)

  [复制链接]
发表于 2012-9-11 10:12:22 | 显示全部楼层 |阅读模式
CameronTrivedi1998(AER)
CameronTrivedi1998()所属R语言包:AER

                                        Data and Examples from Cameron and Trivedi (1998)
                                         从卡梅伦和Trivedi(1998年)的数据和实例

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

This manual page collects a list of examples from the book. Some  solutions might not be exact and the list is certainly not complete. If you have suggestions for improvement (preferably in the form of code), please contact the package maintainer.
本手册收集从书中的例子。某些解决方案可能不是很准确,肯定是不完整的列表。如果你有改进的建议(最好是在代码的形式),请联系软件包的维护者。


参考文献----------References----------

Cambridge: Cambridge University Press.

参见----------See Also----------

DoctorVisits, NMES1988, RecreationDemand
DoctorVisits,NMES1988,RecreationDemand


实例----------Examples----------


library("pscl")

###########################################[##########################################]
## Australian health service utilization ##[#中国卫生服务利用率##]
###########################################[##########################################]

## data[#数据]
data("DoctorVisits", package = "AER")

## Poisson regression[#泊松回归]
dv_pois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = poisson)
dv_qpois <- glm(visits ~ . + I(age^2), data = DoctorVisits, family = quasipoisson)

## Table 3.3 [#表3.3]
round(cbind(
  Coef = coef(dv_pois),
  MLH = sqrt(diag(vcov(dv_pois))),
  MLOP = sqrt(diag(vcovOPG(dv_pois))),
  NB1 = sqrt(diag(vcov(dv_qpois))),
  RS = sqrt(diag(sandwich(dv_pois)))
), digits = 3)

## Table 3.4[#表3.4]
## NM2-ML[NM2-ML]
dv_nb <- glm.nb(visits ~ . + I(age^2), data = DoctorVisits)
summary(dv_nb)
## NB1-GLM = quasipoisson[NB1-GLM = quasipoisson]
summary(dv_qpois)

## overdispersion tests (page 79)[#偏大测试(第79页)]
lrtest(dv_pois, dv_nb) ## p-value would need to be halved[#p-值将需要以被减半]
dispersiontest(dv_pois, trafo = 1)
dispersiontest(dv_pois, trafo = 2)


##########################################[#########################################]
## Demand for medical care in NMES 1988 ##[#医疗服务需求,1988年在NMES##]
##########################################[#########################################]

## select variables for analysis[#选择变量进行分析。]
data("NMES1988", package = "AER")
nmes <- NMES1988[,-(2:6)]

## dependent variable[#因变量]
## Table 6.1[#表6.1]
table(cut(nmes$visits, c(0:13, 100)-0.5, labels = 0:13))

## NegBin regression[#NegBin回归]
nmes_nb <- glm.nb(visits ~ ., data = nmes)

## NegBin hurdle[#NegBin障碍]
nmes_h <- hurdle(visits ~ ., data = nmes, dist = "negbin")

## from Table 6.3[从表6.3#]
lrtest(nmes_nb, nmes_h)

## from Table 6.4[从表6.4#]
AIC(nmes_nb)
AIC(nmes_nb, k = log(nrow(nmes)))
AIC(nmes_h)
AIC(nmes_h, k = log(nrow(nmes)))

## Table 6.8[#表6.8]
coeftest(nmes_h, vcov = sandwich)
logLik(nmes_h)
1/nmes_h$theta


###################################################[##################################################]
## Recreational boating trips to Lake Somerville ##[#娱乐划船游湖萨默维尔##]
###################################################[##################################################]

## data[#数据]
data("RecreationDemand", package = "AER")

## Poisson model:[#泊松模型:]
## Cameron and Trivedi (1998), Table 6.11[#卡梅伦和Trivedi(1998年),表6.11]
## Ozuna and Gomez (1995), Table 2, col. 3[#Ozuna和戈麦斯(1995年),表2,山坳。 3]
fm_pois <- glm(trips ~ ., data = RecreationDemand, family = poisson)
summary(fm_pois)
logLik(fm_pois)
coeftest(fm_pois, vcov = sandwich)

## Negbin model:[#Negbin模型:]
## Cameron and Trivedi (1998), Table 6.11[#卡梅伦和Trivedi(1998年),表6.11]
## Ozuna and Gomez (1995), Table 2, col. 5[#Ozuna和戈麦斯(1995年),表2,山坳。 5]
library("MASS")
fm_nb <- glm.nb(trips ~ ., data = RecreationDemand)
coeftest(fm_nb, vcov = vcovOPG)
logLik(fm_nb)

## ZIP model:[#ZIP模式:]
## Cameron and Trivedi (1998), Table 6.11[#卡梅伦和Trivedi(1998年),表6.11]
fm_zip <- zeroinfl(trips ~  . | quality + income, data = RecreationDemand)
summary(fm_zip)
logLik(fm_zip)

## Hurdle models[#跨栏型号的]
## Cameron and Trivedi (1998), Table 6.13[#卡梅伦和Trivedi(1998年),表6.13]
## poisson-poisson[#泊松泊松]
sval <- list(count = c(2.15, 0.044, .467, -.097, .601, .002, -.036, .024),
             zero = c(-1.88, 0.815, .403, .01, 2.95, 0.006, -.052, .046))
fm_hp0 <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson",
  zero = "poisson", start = sval, maxit = 0)
fm_hp1 <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson",
  zero = "poisson", start = sval)
fm_hp2 <- hurdle(trips ~ ., data = RecreationDemand, dist = "poisson",
  zero = "poisson")
sapply(list(fm_hp0, fm_hp1, fm_hp2), logLik)

## negbin-negbin[#negbin-negbin]
fm_hnb <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "negbin")
summary(fm_hnb)
logLik(fm_hnb)

sval <- list(count = c(0.841, 0.172, .622, -.057, .576, .057, -.078, .012),
             zero = c(-3.046, 4.638, -.025, .026, 16.203, 0.030, -.156, .117),
             theta = c(count = 1/1.7, zero = 1/5.609))
fm_hnb2 <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "negbin", start = sval)
summary(fm_hnb2)
logLik(fm_hnb2)


## geo-negbin[#GEOnegbin]
sval98 <- list(count = c(0.841, 0.172, .622, -.057, .576, .057, -.078, .012),
             zero = c(-2.88, 1.44, .4, .03, 9.43, 0.01, -.08, .071),
             theta = c(count = 1/1.7))
sval96 <- list(count = c(0.841, 0.172, .622, -.057, .576, .057, -.078, .012),
             zero = c(-2.882, 1.437, .406, .026, 11.936, 0.008, -.081, .071),
             theta = c(count = 1/1.7))
      
fm_hgnb <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "geometric")
summary(fm_hgnb)
logLik(fm_hgnb)

## logLik with starting values from Gurmu + Trivedi 1996[#初始值,从Gurmu +特里维迪1996 logLik]
fm_hgnb96 <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin", zero = "geometric",
                  start = sval96, maxit = 0)
logLik(fm_hgnb96)

## logit-negbin[#罗吉特negbin]
fm_hgnb2 <- hurdle(trips ~ ., data = RecreationDemand, dist = "negbin")
summary(fm_hgnb2)
logLik(fm_hgnb2)

## Note: quasi-complete separation[#注:准完全分离]
with(RecreationDemand, table(trips > 0, userfee))

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-23 13:40 , Processed in 0.028509 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表