[R-sig-Geo] Importing data into spdep package

Roger Bivand Roger.Bivand at nhh.no
Sun Jun 24 18:13:03 CEST 2007


On Sat, 23 Jun 2007, Michael Haenlein wrote:

> Dear all,
>
> I'm quite new to spatial statistics, so I hope the question I'm asking
> is not to stupid. But I'm struggling with the issue for days now ...
>
> I want to estimate a spatial simultaneous autoregressive lag model
> using the spdep package in R. My data is currently stored in an Access
> database. There I have two tables. The first one contains information
> about each location. Assume one of these variables is y. Each location
> is identified by a unique ID. Hence, the first table is structured in
> the form "ID - y". The second table contains the distance between
> pairs of location and is structured in the form "ID1 - ID2 - Distance
> between ID1 and ID2".
>
> My question is: How can I import my two tables in R and convert the
> second one (giving distances between two locations) in a spatial
> weights matrix? I want to estimate a model of form: y = a + bWy, where
> W is a spatial weights matrix and y is a location characteristic as
> defined above. I am familiar with importing data into R in general
> (using the read.csv function) as well as with exporting data from
> Access into csv format.

Most likely you should export y and the IDs in a rectangular CSV file, and 
the distance matrix in a square CSV file. Once you have read the squre 
matrix into R, try the mat2listw() function to get hold of the distances 
in list form (although it may be sensible to take inverse distances from 
the matrix, and set very small values to zero to reduce density first). 
The output listw object may need re-building with nb2listw() on the 
neighbours and weights components if you want for example to use row 
standardisation. From there on lagsarlm() ought to work.

Hope this helps,

Roger

>
> Thanks very much for your help in advance,
>
> Michael
>
> _______________________________________________
> 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