r - 比例建模 - Betareg 错误

标签 r glm beta-distribution

我想知道这里是否有人可以帮助我。

我正在尝试使用 betareg 包来拟合 beta GLM,因为我的因变量是从 0 到 1 变化的比例(500 米网格大小中鲸鱼的相对密度)。我有三个协变量:

  • 深度(以米为单位,范围从 4 到 100 米),
  • 到海岸的距离(以米为单位,范围从 0 到 21346 米)和
  • 到船的距离(以米为单位,范围从 0 到 20621)。

我的因变量有很多 0 和很多太接近 0 的值(如 7.8e-014)。当我尝试拟合模型时,出现以下错误:

invalid dependent variable, all observations must be in (0, 1). 

从我之前的讨论来看,这似乎是由我在数据集中的 0 引起的(我不应该有任何 0 或 1)。当我将所有 0 更改为仅正定(例如 0.0000000000000001)时,我收到的错误消息是:

Error in chol.default(K) : 
  the leading minor of order 2 is not positive definite
In addition: Warning messages:
1: In digamma(mu * phi) : NaNs produced
2: In digamma(phi) : NaNs produced
Error in chol.default(K) : 
  the leading minor of order 2 is not positive definite
In addition: Warning messages:
1: In betareg.fit(X, Y, Z, weights, offset, link, link.phi, type, control) :
  failed to invert the information matrix: iteration stopped prematurely
2: In digamma(mu * phi) : NaNs produced

从我在几个论坛上看到的情况来看,这似乎是因为我的矩阵不是正定矩阵。它可能是不确定的(即同时具有正特征值和负特征值)或者我的矩阵可能接近奇异值,即它的最小特征值非常接近 0(因此在计算上为 0)。

我的问题是:因为我只有这个数据集,有没有办法解决这些问题并运行 beta 回归?或者,我可以使用任何其他模型来代替它可以工作的 betareg 包吗?

这是我的代码:

betareg(Density~DEPTH+DISTANCE_TO_COAST+DIST_BOAT,data=misti)

最佳答案

When I change all my 0 to only positive definite (e.g. 0.0000000000000001)

这样做似乎是个坏主意,会导致您看到错误消息。

似乎 betareg 目前只对 (0,1) 区间内的数据有效,这就是 package vignette 的作用不得不说:

The class of beta regression models, as introduced by Ferrari and Cribari-Neto (2004), is useful for modeling continuous variables y that assume values in the open standard unit interval (0, 1). [...] Furthermore, if y also assumes the extremes 0 and 1, a useful transformation in practice is (y · (n − 1) + 0.5)/n where n is the sample size (Smithson and Verkuilen 2006).

所以解决这个问题的一种方法是:

y.transf.betareg <- function(y){
    n.obs <- sum(!is.na(y))
    (y * (n.obs - 1) + 0.5) / n.obs
}


betareg( y.transf.betareg(Density) ~ DEPTH+DISTANCE_TO_COAST+DIST_BOAT, data=misti)

对于 betareg 的替代方法,使用带有 logit 链接的 binomial GLM,请参阅交叉验证和链接的 UCLA 上的这个问题常见问题:

有些人会建议使用 quasibinomial GLM 来模拟比例/百分比...

关于r - 比例建模 - Betareg 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26385617/

相关文章:

r 计算每个变量每个 ID 的非缺失条目数

python - 如何在 Python 中集成 beta 发行版

r - 为什么 r 中的滞后不适用于矩阵?

r - 是否有用于模糊字符串检测的 R 包(或现有函数)?

r - 使用 gsub() 替换除某些子字符串之外的所有数字

r - 如何从 R 中的 glm 中排除特定变量?

r - glmer-使用二项式数据预测(结合计数数据)

r - 用 95% CI 绘制具有多个解释的结果 glm

c# - 我在哪里可以找到简单的 beta cdf 实现

r - 如何使用基数 r 将 dbeta 图中的 x 值转换为百分比?