R:不兼容的维度VGAM中的错误vglm函数

时间:2014-12-19 16:44:43

标签: r glm vgam

TL; DR


我在R中使用VGAM软件包运行Tobit回归 - 这是一个玩具数据集,它一直给我一个我无法诊断的错误:

library(data.table)
library(VGAM)

> sessionInfo()$otherPkgs
$VGAM
Package: VGAM
Version: 0.9-7
Date: 2015-03-06
... <ommitted> ...

reg_data <- structure(list(S = c(1.83271488441825, 0.75411550370994, 0.904938604451928, 
                                 0.75411550370994, 0.75411550370994), H = c(0.6429, 0.7788, 
                                                                            0.6292, 0.8892, 0.2035), W= c(1.52497, 1.1391, 1.59722, 
                                                                                                          1.8406, 1.01865)), .Names = c("S", "H", "W"), class = c("data.table", 
                                                                                                                                                                  "data.frame"), row.names = c(NA, -5L))

minS <- 0.75411550370994
maxS <- 1.83271488441825

m <- vglm(S ~ H, tobit(Upper = maxS, Lower = minS), weights = W, data = reg_data)
Error in lm.wfit(x = cbind(x[!use.i11, ]), y = y[!use.i11, ii], w = w[!use.i11,  : 
  incompatible dimensions

尝试诊断

使用追溯:

> traceback()
6: stop("incompatible dimensions")
5: lm.wfit(x = cbind(x[!use.i11, ]), y = y[!use.i11, ii], w = w[!use.i11, 
       ii])
4: eval(expr, envir, enclos)
3: eval(slot(family, "initialize"))
2: vglm.fitter(x = x, y = y, w = w, offset = offset, Xm2 = Xm2, 
       Ym2 = Ym2, etastart = etastart, mustart = mustart, coefstart = coefstart, 
       family = family, control = control, constraints = constraints, 
       criterion = control$criterion, extra = extra, qr.arg = qr.arg, 
       Terms = mt, function.name = function.name, ...)
1: vglm(y ~ x, tobit(Upper = maxy, Lower = miny), weights = w, data = X)

我查看了lm.wfit的源代码并找到了错误的来源:

function (x, y, w, offset = NULL, method = "qr", tol = 1e-07, 
    singular.ok = TRUE, ...) 
{
  <ommitted...>
    if (NROW(y) != n | length(w) != n) 
        stop("incompatible dimensions")
  <ommitted...>
  }

我在vglm的源代码中找到了以下内容:

    vglm.fitter <- get(method)
    fit <- vglm.fitter(x = x, y = y, w = w, offset = offset, 
        Xm2 = Xm2, Ym2 = Ym2, etastart = etastart, mustart = mustart, 
        coefstart = coefstart, family = family, control = control, 
        constraints = constraints, criterion = control$criterion, 
        extra = extra, qr.arg = qr.arg, Terms = mt, function.name = function.name, 
        ...)

该方法默认为vglm.fit

我仍然无法找到排除标准use.i11的创建位置,它正在做什么以及为什么它会导致权重,回归和回归之间存在冲突。

我观察到将minSmaxS四舍五入到十个或更少的位置会导致成功运行,但这是因为maxS增加了所以第一次观察不再正确审查和minS增加,因此第2,第4和第5次观察不再受到审查。两者都改变​​了最大似然函数中观察的处理,所以我怀疑我会以错误的结果污染回归。

有人可以帮助诊断出现此类错误的原因吗?

1 个答案:

答案 0 :(得分:7)

我收到了软件包开发人员的消息,这确实是一个错误,并且已在预先发布的软件包here中修复,可能会在下一次迭代中升级到CRAN - 或者他的书已经发布了。