gpt4 book ai didi

r - GLM 和拟泊松

转载 作者:行者123 更新时间:2023-12-04 09:12:22 24 4
gpt4 key购买 nike

我想用 quasipoisson 作为 family 的值来运行 glm()。然而,我已经对色散参数 phi 有了很好的估计,因此我想在应用 glm() 时使用它。有没有办法强制 glm 使用给定的色散参数进行准泊松?

最佳答案

色散参数仅与推理相关,与参数优化无关。于是,在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

关于r - GLM 和拟泊松,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22482500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com