[R-sig-Geo] RE: [R] adjacency matrix

Christophe Declercq c.declercq at orsnpdc.org
Thu Oct 23 11:25:18 CEST 2003


> ----- Original Message -----
> From: "Roger Bivand" <Roger.Bivand at nhh.no>
> To: "Luc Anselin" <anselin at uiuc.edu>
> Cc: <cdeclercq at nordnet.fr>; <r-sig-geo at stat.math.ethz.ch>; "Orlando
> Zacarias" <si-opz at dsv.su.se>
> Sent: Wednesday, October 22, 2003 6:19 PM
> Subject: Re: [R-sig-Geo] RE: [R] adjacency matrix
>
>
> On Wed, 22 Oct 2003, Luc Anselin wrote:
>
> > Another alternative would be to use the "Tools" in GeoDa
> > (free from http://sal.agecon.uiuc.edu/csiss/geoda.html ).
> > This creates contiguity and distance based sparse weights
> > files (in ascii format) directly from point and polygon shape
> > files. The spdep package contains functions to read and
> > manipulate these weights files. I'm not familiar with the
> > format used by WinBUGS, but I doubt it can be very different.
> > L.
>
> >From links from the web page I googled (convert.r AND cgm), and from the
> GeoBUGS manual, their format can be generated, but looks a bit naive as
> is. We could implement it, and/or talk to the GeoBUGS developers about
> using GeoDa (and maybe R/spdep) as a convenient front end - then they
> would avoid having to generate the weights internally. Since they are
> Windows, and WinBUGS is closed source, GeoDa could be a useful
> pre-processing tool (also for spdep weights).

I did not know GeoDa so I will have a look at it.

I'm now working on a project with mortality mapping using smoothing with a
hierarchical Bayes model (the Besag, York and Mollié model) and I'm actually
using R/maptools/spdep as a front end to WinBUGS1.4.

I do all the data preparation for WinBUGS in R, I use the new scripting
facility in WinBUGS1.4 and I get back the samples in R to plot maps of the
estimates with plotpolys(). It works fine for me.

It's easy to get the adjacency data as WinBUGS want them.
Something along the lines of (if 'cantons' is a 'polylist' object):

> cantons.nb<-poly2nb(cantons, bb=cantons.bb) # calculate the neighbourhood
> data<-list(N = length(cantons),
+  O=lungcanc$o, E=lungcanc$e,
+  num=sapply(cantons.nb, length),
+  adj=unlist(cantons.nb),
+  sumNumNeigh=length(unlist(cantons.nb))
+)

Some care is needed in the formating of numbers. I use some of the functions
by Andrew Gelman at http://www.stat.columbia.edu/~gelman/bugsR (a web
appendix to the book Bayesian Data Analysis, Second Edition,  by Andrew
Gelman, Donald B. Rubin, Hal S. Stern) to write the ascii files for WInBUGS.

Christophe
--
Christophe DECLERCQ, MD
Observatoire Régional de la Santé Nord-Pas-de-Calais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax   +33 3 20 55 92 30
E-mail c.declercq at orsnpdc.org




More information about the R-sig-Geo mailing list