[R-sig-Geo] Problem with lm.morantest

Roger Bivand Roger.Bivand at nhh.no
Sat Dec 25 22:16:20 CET 2004


On Sat, 25 Dec 2004 buczkowski at delta.sggw.waw.pl wrote:

> Hello
> 
> I have a map of polygons in shapefile and a database in Access with
> several 
> attributes of the polygons from the shapefile. On data from the database I
> 
> am doing linear regression using function lm(). I would like to check 
> whether there is spatial correlation in regresssion residuals. I loaded 
> polygons using maptools, created a neighbor list using poly2nb() and then
> 
> spatial weights using nb2listw(). I made regression on data from the 
> database (not from shapefile) and wanted to use lm.morantest() to
> calculate 
> Moran's I, and there the following error appeared "Error in 
> lm.morantest(wmoddef, def_w, zero.policy = TRUE, alternative = "greater", 
> :
>         objects of different length" )
> 
> I realize that this is because the lists of polygons from shapefile and
> records from regression are different. I was trying to match them by
> sorting them in the same order but it didn't work. My question is how can
> I conduct my analysis so the neighbor list and residuals from regression
> would match each other in lm.morantest? 

First, maybe check whether there are no NAs in the regression:

> data(oldcol)
> COL.OLD$HOVAL[1:5] <- NA
> oldcrime.lm <- lm(CRIME ~ HOVAL + INC, data = COL.OLD)
> lm.morantest(oldcrime.lm, nb2listw(COL.nb, style = "W"))
Error in lm.morantest(oldcrime.lm, nb2listw(COL.nb, style = "W")) : 
        objects of different length

I think you need to establish where the lack of equivalence between your 
data and your shapefile is coming from - will using the spChk= argument 
help one the numbers of polygons and regression residuals agree? Does your 
data have an ID row name that can be used as the region.id= argument in 
poly2nb?

If necessary please contact me off-list; at the moment, your residuals are 
not the same length as the number of neighbours, and we need to find out 
why.

Roger

> 
> Thanks in advance for your help
> 
> With best Christmas and New Year wishes
> 
> Rafal Buczkowski
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list