[R] spdep question - Moran's I

Roger Bivand Roger.Bivand at nhh.no
Sat Apr 19 23:27:00 CEST 2008

Haenlein.Michael <Michael.Haenlein <at> whu.edu> writes:

> Dear all,
> I would like to calculate a Moran's I statistic using the moran function in 
> the spdep package. The problem
> I'm having deals with how to create the listw object.
> My data stems from the area of social network analysis. I have list of poeple
> and for each pair of them I have a
> measure of their relationship strength. So my dataset looks like:
> Jim; Bob; 0.5
> This measure of relationship strength can be interpreted like a distance 
> measure in a spatial model.
> I assume that I need to work with the nb2listw function, but I am lost
> what to do in detail.

If you have a data frame of from, to, weight, and possibly change the 
column names to suit the sn2listw() function, you might be able to move 
forward. The from-to strings would need to form a single set of names, where
for Moran's I the resulting network may be asymmetric. If you start with 
a simple example, you can trace things through. If it is the case 
that sn2listw() wants integers not names, coerce the names (factor levels) 
to integer.

Perhaps the R-sig-geo list would be more suitable, even if this use is not
spatial as such - there is a higher proportion of people there who might
be able to help. Probably traceback() and debug(sn2listw) will be your
friends in trying to have it do things it was not written for. If you 
make progress, please say so.

Hope this helps,


> Thanks very much for your help in advance!
> Michael Haenlein
> Assistant Professor of Marketing
> ESCP-EAP European School of Management
> Paris, France

More information about the R-help mailing list