[R-sig-Geo] Problem with moran.test (spdep)

Roger Bivand Roger.Bivand at nhh.no
Tue Sep 7 10:46:35 CEST 2010


On Tue, 7 Sep 2010, Breitbach, Nils wrote:

> Dear Community,
>
> I already performed some successful Moran's I tests using the moran.test 
> function (spdep package) for my data but now I got an error that I do 
> not understand.
>
> For the code:
>
>> moran.temp <- moran.test(birds_spdf at data[, i], birds.nb4.idw.W_lw, 
>> zero.policy = TRUE, na.action = na.exclude)
>
> where birds_spdf at data is the data frame with the variables to be tested 
> and birds.nb4.idw.W_lw is a listw object with the weights from an 
> inverse distance matrix and four neighbours for each coordinate. I set 
> na.action to na.exclude because I know that there are some NA values in 
> the data; therefore I also set the zero.policy to TRUE. The code 
> fragment is running in a loop for all variables that I want to be 
> tested. For all other data sets it worked perfectly but now I get the 
> the following error:
>
> Error in subset.listw(listw, subset, zero.policy = zero.policy) :
>  Not yet able to subset general weights lists
>
> When I checked for the value of i it was clear that the error happens 
> for the first time in the presence of NA values in the data, i. e. in 
> the first column that contains NAs. Since I set na.action = na.exclude 
> and it worked for other data sets that contain NAs I am not sure what is 
> the problem here?

Look at ?subset.listw. You used the glist= argument in nb2listw(), so the 
reason is clear, isn't it? It cannot have worked with this listw object. 
If you want to do this, you need to drop the NAs manually in the loop, 
subset the nb object, build the inverse distance weights for the subsetted 
nb object, and use nb2listw() each time. The reason subset.listw() cannot 
subset listw objects with glist= set is that it cannot be sure of the 
intentions of the user. subset.nb() does not have the same problem with 
regard to ambiguity.

Hope this helps,

Roger

>
> Any suggestions?
>
>
> Regards,
>
> Nils Breitbach
> _______________________________________________
> 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, 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