[R-sig-Geo] About an Error coming from the Moran Eigenvectors method in spdep package

Roger Bivand Roger.Bivand at nhh.no
Fri Sep 7 09:30:04 CEST 2012


On Thu, 6 Sep 2012, Lei Wang wrote:

> Dear listers and Prof. Bivand,
>
> I started working on spatial econometrics and R three weeks ago and this 
> is my first time posting here.
>
> My dependent variable is a count variable and its variance is much 
> greater than its mean. So I choose negative binomial regression and use 
> glm.nb() to do it. I also suspect that there maybe spatial 
> autocorrelation issue in the residuals. In order to reduce this residual 
> spatial autocorrelation in the error of my model, I am using the Moran 
> Eigenvectors approach.  And I use the inverse distance matrix as the 
> weights. Below is my model and the error message from R:
>
> fypME<-ME(Count ~ CTN + CSTN + Price + Rating, data=fyp, 
> family=negative.binomial(theta=2.9, link=log), 
> listw=fyp.dists.inv.listw, alpha=0.05)
>
> Error in if (pIZ > alpha) stop("base correlation larger than alpha") : 
> missing value where TRUE/FALSE needed

The message means that when testing (pIZ > alpha), either pIZ or alpha is 
NA, alpha is given, so pIZ must be NA. It is the p-value from a bootstrap 
Moran's I on the glm residuals. You will either need to make your data 
available for checking - save(fyp, fyp.dists.inv.listw, file="fyp.RData"), 
generate the same problem with a data set distributed with an R package 
(it doesn't occur with the NC SIDS data), or run debug(ME) before running 
ME(), stepping through to lines:

     glm_res <- glm_fit$y - glm_fit$fitted.values
     cpvar <- crossprod(glm_res)
     mRES <- MIR_a(glm_res, sW = sW, n = n, cpvar = cpvar, S0 = S0,
         nsim = nsim, stdev = stdev)
     pIZ <- mRES$p.value

and check each of the returned values for NAs. Do you have any missing 
values in your variables. I don't think so, but for me on 2.15.1:

> options("na.action")
$na.action
[1] "na.omit"

rather than "na.fail", I expected "na.fail". If you do:

options(na.action="na.fail")

does this make a difference (almost certainly not, because the weights 
will have a different dimension from the residuals, and the bootstrap 
Moran will fail earlier)?

Hope this helps,

Roger

>
> Could anybody help me with this? What does this error mean? and how 
> should I fix this?
>
> Thanks a lot!
>
> Michelle
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list