R: Incompatible Dimensions Error vglm function in VGAM

2.8k views Asked by At

TL;DR


I am running Tobit regressions with the VGAM package in R -- Here is a toy dataset that is consistently giving me an error that I have not been able to diagnose:

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

Attempts to diagnose

With traceback:

> 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)

I have viewed the source code for lm.wfit and find the source of the error:

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...>
  }

I have found the following in the source code for 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, 
        ...)

Where the method is defaulted to vglm.fit.

I still have not been able to locate where the exclusion criteria use.i11 is created, what it is doing and why it results in conflicting dimensions between the weights, regressor and regressand.

I have observed that rounding the minS and maxS to ten or less places results in a successful run, but this is because maxS is increased so the 1st observation is no longer right censored and minS is increased so the 2nd, 4th and 5th observations are no longer left censored. Both alter the observation's treatment in the maximum likelihood function so I suspect I would be contaminating the regression with false results.

Can someone kindly help diagnose why this type of error occurs?

1

There are 1 answers

0
mlegge On BEST ANSWER

I received word from the package's developer that this was indeed a bug and that is has been fixed in the pre-released package here, which will presumably be upgraded to the CRAN in the next iteration -- or when his book is released.