[R-sig-Geo] SpatialPolygonsDataFrame and lm.morantest

jonmitchellchicago jonsmitch2 at gmail.com
Wed Oct 10 18:02:22 CEST 2012


Hello all,

I have a SpatialPolygonsDataFrame object with 2550 polygons, representing 37
distinct regions (polygon region labels are stored in map at data$Labels). I
have two continuous variables for each of those 37 distinct regions. For the
life of me, I cannot figure out how to utilize lm.morantest to

LM <- lm(Y~X) #Where X & Y are  vectors of 37 data points
mapNB <- poly2nb(Map)
lm.morantest(LM,nb2listw(mapNB,style="W",zero.policy=TRUE)) 

Error in lm.morantest(LM, nb2listw(mapNB, style = "W", zero.policy = TRUE))
: 
  objects of different length

If I set zero.policy=FALSE, or exclude it, I get the empty neighbor sets
message.

As an experiment, I tried the following (which makes no statistical sense,
but fixes the uneven length problem so I thought I'd see what errors it
conjured):

LM <- lm(Y[Map at data$Labels]~X[Map at data$Labels])
lm.morantest(LM,nb2listw(mapNB,style="W",zero.policy=TRUE)) 


	Global Moran's I for regression residuals

data:  
model: lm(formula = Y[Map at data$Labels] ~ X[Map at data$Labels])
weights: nb2listw(mapNB, style = "W", zero.policy = TRUE)
 
Moran I statistic standard deviate = NA, p-value = NA
alternative hypothesis: greater 
sample estimates:
Observed Moran's I        Expectation           Variance 
                NA                 NA                 NA 

Warning messages:
1: In lag.listw(listw.U, u, zero.policy = zero.policy) :
  NAs in lagged values
2: In lag.listw(listw.U, X, zero.policy = zero.policy) :
  NAs in lagged values
3: In lm.morantest(LM, nb2listw(mapNB, style = "W", zero.policy = TRUE)) :
  Out-of-range p-value: reconsider test arguments


Any suggestions?



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/SpatialPolygonsDataFrame-and-lm-morantest-tp7581242.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list