1

I am trying to calculate the moran I index (for spatial autocorrelation) using the the following argument:

moran.test(data_total$prod_ser, dnb60.listw, randomisation=F)

The error I get is that the two objects are of different length.

Vector prod_ser belonging to data.frame data_total (first object in () ) is 2373 long (in other words data_total contain 2373 observations-firms). I am trying to see whether this variable is spatially auto-correlated.

dnb50.listw is a nb2listw object, spatial weights created based on distance between coordinates of the country's regions.Its length is 3. This object is created using a polygon shapefile, containing 25 regions.This polygon shapefile contains regions's ID, which data_total data.frame contains too (along with the regions' coordinates).

I tried to extend the length of dnb60.listw object to 2373 (the length of prod_ser vector), but that would not be possible since it is a nb2listw object.

I also tried creating list object using data_total (since this data_frame does have coordinates and region's ID). However,I would get the following error:

Error in UseMethod("coords") :
no applicable method for 'coords' applied to an object of class "data.frame"

Is there any idea of how to make these two objects (prod_ser and dnb60.listw) of the same length so that I can do the testing?

989
  • 12,579
  • 5
  • 31
  • 53
Mina Wu
  • 61
  • 6
  • When asking for help, you should include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Provide sample input data and specify which package the `moran.test` function comes from. – MrFlick Jul 01 '15 at 16:59
  • @MrFlick I gave the reproducible example on the following post stackoverflow.com/questions/31101043/… If you have any idea how to sort this out-it would be great! – Mina Wu Jul 07 '15 at 12:58

0 Answers0