【问题标题】:Still get non-positive values for the 'gamma' family仍然得到 \'gamma\' 族的非正值
【发布时间】:2022-11-17 02:52:13
【问题描述】:

我正在用glmer分析百分比数据,我读到Gamma family应该适合这种数据。我检查了我的数据,没有低于 0 的值,但我仍然收到一条错误消息,说我有非正值。

  > summary(total_F$p.prcnt)
       Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
       0.00   50.00   75.00   68.56  100.00  100.00 

只需添加我使用的代码:

F_par1<- glmer(p.prcnt ~ b.element+distance+b.element*distance +year+sampling.round+(1|LS1),  
                   family = Gamma, 
                   data=total_F)

我有哪些选择?我尝试将 Excel 中的数据修改为成比例并使用二项式,但如果可能的话,我更愿意使用 Gamma。

【问题讨论】:

    标签: r lme4 gamma-distribution


    【解决方案1】:

    似乎零也被认为是非正数。这里有一个例子,lme4 附带的cbpp 数据集。

    library(lme4)
    
    table(cbpp$incidence)
    #  0  1  2  3  4  5  8 11 12 
    # 22 13  9  5  1  2  2  1  1 
    

    正如我们所见,DV 中有零,

    glmer(incidence ~ period + (1 | herd), data=cbpp, family=Gamma)
    # Error in eval(family$initialize, rho) : 
    #   non-positive values not allowed for the 'Gamma' family
    

    这导致了错误。没有错误,如果我们排除零:

    glmer(incidence ~ period + (1 | herd), data=cbpp[cbpp$incidence != 0, ], family=Gamma)
    # Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
    #  Family: Gamma  ( inverse )
    # Formula: incidence ~ period + (1 | herd)
    #    Data: cbpp[cbpp$incidence != 0, ]
    #      AIC      BIC   logLik deviance df.resid 
    # 121.5891 130.7473 -54.7946 109.5891       28 
    # Random effects:
    #   Groups   Name        Std.Dev.
    #     herd     (Intercept) 0.1714  
    #     Residual             0.5186  
    # Number of obs: 34, groups:  herd, 15
    # Fixed Effects:
    # Intercept)      period2      period3      period4  
    #     0.3891       0.2251       0.1487       0.4620  
    

    【讨论】:

    • 谢谢,但我在数据中的零是有意义的,因此我不能简单地删除它们。我应该放弃 Gamma 而只做二项式吗?
    • @Sisi 当然零是有意义的,很可能 Gamma 不是正确的选择。然而,这是一个统计问题,应该在 Cross Validated 上提问。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多