【问题标题】:GLM and quasipoissonGLM 和准泊松
【发布时间】:2016-11-25 15:02:34
【问题描述】:

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

【问题讨论】:

    标签: r glm


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      来自 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"))
      

      会做的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-09
        • 2022-06-13
        • 2022-01-10
        • 2021-10-24
        • 2013-02-02
        • 1970-01-01
        相关资源
        最近更新 更多