【问题标题】:Zeros in Count data, how to deal with?Count数据出现零,如何处理?
【发布时间】:2018-03-05 18:40:15
【问题描述】:

我有一个包含计数数据的数据集。我用 glm 做泊松回归。 现在我想手动计算零偏差。为此,我需要完整模型的 loglike。对于 loglike,我得到 NaN。我认为这是因为响应变量的某些值是 0 并且 log(0) 产生 NaN。然而 glm 计算零偏差。所以必须有一个技巧来处理 y 中的 0 条目。我应该用非常小的值(例如 0,00001 或其他可能的解决方案来获得不是 NaN 的 lf 的结果)替换它们吗

data(discoveries)
disc <- data.frame(count=as.numeric(discoveries),
                   year=seq(0,(length(discoveries)-1),1))

yearSqr <- disc$year^2

hush <- glm(count ~ year + yearSqr , family = "poisson", disc)


# modelFrame
test <- hush$model
# reponse variable 
test$count

# formula for loglike full modell lf = sum(y * log(y) - y - log(factorial(y)))


# result is NaN
lf <- sum(test$count * log(test$count) - test$count - log(factorial(test$count)))

【问题讨论】:

  • 这可能更适合CrossValidated 板。
  • 查看零膨胀或跨栏模型。
  • 仅当我们的零值多于非零值并且在我的数据集上我只有 5 个零条目时才使用零膨胀模型 ...

标签: r regression nan poisson


【解决方案1】:

你应用的公式是错误的;它不使用任何有关估计参数的信息。您想使用以下内容:

sum(test$count * log(fitted(hush)) - fitted(hush) - log(factorial(test$count)))
# [1] -200.9226
logLik(hush)
# 'log Lik.' -200.9226 (df=3)

【讨论】:

    猜你喜欢
    • 2021-11-29
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 2020-12-04
    • 1970-01-01
    • 2014-09-05
    相关资源
    最近更新 更多