我想使用glm()
作为quasipoisson
的值运行family
。但是我已经对色散参数phi进行了非常好的估计,因此我想在应用glm()
时使用它。有没有办法强制glm使用给定的分散参数quasipoisson?
答案 0 :(得分:5)
色散参数仅与推理相关,不适用于参数优化。因此,summary.glm
中有相应的参数。
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
glm.po <- glm(counts ~ outcome + treatment, family = poisson())
summary(glm.po)$coef
# Estimate Std. Error z value Pr(>|z|)
#(Intercept) 3.044522e+00 0.1708987 1.781478e+01 5.426767e-71
#outcome2 -4.542553e-01 0.2021708 -2.246889e+00 2.464711e-02
#outcome3 -2.929871e-01 0.1927423 -1.520097e+00 1.284865e-01
#treatment2 1.337909e-15 0.2000000 6.689547e-15 1.000000e+00
#treatment3 1.421085e-15 0.2000000 7.105427e-15 1.000000e+00
glm.qu <- glm(counts ~ outcome + treatment, family = quasipoisson())
summary(glm.qu)$dispersion
#[1] 1.2933
summary(glm.qu)$coef
# Estimate Std. Error t value Pr(>|t|)
#(Intercept) 3.044522e+00 0.1943517 1.566502e+01 9.698855e-05
#outcome2 -4.542553e-01 0.2299154 -1.975750e+00 1.193809e-01
#outcome3 -2.929871e-01 0.2191931 -1.336662e+00 2.522944e-01
#treatment2 1.337909e-15 0.2274467 5.882297e-15 1.000000e+00
#treatment3 1.421085e-15 0.2274467 6.247992e-15 1.000000e+00
summary(glm.qu, dispersion=1)$coef
# Estimate Std. Error z value Pr(>|z|)
#(Intercept) 3.044522e+00 0.1708987 1.781478e+01 5.426767e-71
#outcome2 -4.542553e-01 0.2021708 -2.246889e+00 2.464711e-02
#outcome3 -2.929871e-01 0.1927423 -1.520097e+00 1.284865e-01
#treatment2 1.337909e-15 0.2000000 6.689547e-15 1.000000e+00
#treatment3 1.421085e-15 0.2000000 7.105427e-15 1.000000e+00
答案 1 :(得分:1)
来自stats :: family的R帮助页面,
Arguments:
...
variance: for all families other than ‘quasi’, the variance function is
determined by the family. The ‘quasi’ family will accept the
literal character string (or unquoted as a name/expression)
specifications ‘"constant"’, ‘"mu(1-mu)"’, ‘"mu"’, ‘"mu^2"’
and ‘"mu^3"’, a length-one character vector taking one of
those values, or a list containing components ‘varfun’,
‘validmu’, ‘dev.resids’, ‘initialize’ and ‘name’.
假设您的方差/平均系数估计值为1.2,
glm(..., family=quasipoisson(variance="1.2*mu"))
将完成这项工作。