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

Roger Bivand Roger.Bivand at nhh.no
Fri Oct 24 23:19:06 CEST 2003


On Thu, 23 Oct 2003, Orlando Zacarias wrote:

> Yes. i have managed to create the adjacency matrix in GeoDa. What i am now
> struggling with is the map conversion from shapefile format to R, and from R
> to WinBugs. Since i am running out of time, have downloaded the maptools and
> trying to experiment it for data conversion. Will post you my results. BTW i
> am working on malaria mapping adapting the hierarchical Bayes model (the
> Besag, York and Mollié model).....
> Tanxs all for the help and discussion so far.
> Rgs,
> Orlando. 
> 
> -------Original Message-------
> 
> From: c.declercq at orsnpdc.org
> Date: 23 October 2003 10:25:20
> To: Roger.Bivand at nhh.no
> Cc: anselin at uiuc.edu; r-sig-geo at stat.math.ethz.ch; si-opz at dsv.su.se
> Subject: RE: [R-sig-Geo] RE: [R] adjacency matrix
> 
> > ----- 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))
> +)

Would it be useful for a function doing this to be put into spdep, 
including checking that things "add up"? Should the function write data 
out to a file - probably not, if you are using bugsR as the interface?

Would a similar function to output the polygon boundaries in a 
GeoBUGS-friendly format be helpful - should that rather be in maptools?

This is a very fruitful thread - please keep up the flow of ideas, because 
the need for data exchange with WinBUGS is clear and if we can get it 
right, should be useful for quite a large (and growing) group of people. 
Could some of us try to do a very rough mini-HOWTO, possibly with the 
author of convert.r (cc to Yue Cui, thread "adjacency matrix" on r-help 
and r-sig-help)?

Roger

> 
> 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
> 
> 
> 
> .

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list