

Your question is not really clear because:
 I don't know what 'convert.r' do
 I don't know where 'transf.cgm' is (BTW, 'cgm' is not the usual extension
for shapefiles which is 'shp'). Check if it is really in your current
directory.
but, yes, if what you want is to import shapefiles in R, it's easy. Look at
the 'maptools' package on CRAN (there is also a 'shapefiles' package).
And if you want to build an adjacency matrix for a map of polygons (as I
guess from the header of you mail), look at the 'spdep' package, too. It is
then possible to write a text file with your data as a list readable by
WinBUGS.
(I send a copy of my answer to the the RSIGGEO mailing list which can be
of interest to you).
Hope it helps.
Christophe

Christophe DECLERCQ, MD
Observatoire R?gional de la Sant? NordPasdeCalais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax +33 3 20 55 92 30
Email c.declercq at orsnpdc.org
> Message d'origine
> De : rhelpbounces at stat.math.ethz.ch
> [mailto:rhelpbounces at stat.math.ethz.ch]De la part de Orlando Zacarias
> Envoy? : mercredi 22 octobre 2003 11:58
> ? : rhelp at stat.math.ethz.ch
> Objet : [R] adjacency matrix
>
>
> Dear R experts,
> I am new to the list and R software. I need to convert arcview
> file to Winbugs having R has middle package. Got from friends
> that it is possible following the steps:
> 1. Converting arcview shapefile to "cgm clear text file"
> 2. Downloading "convert.r" to into R
> 2.1 use source("convert.r")
> 2.2 convert("filename_cgm") without the extension.
> But that doesn't work, given the following errors:
> 
> R : Copyright 2003, The R Development Core Team
> Version 1.8.0 (20031008)
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information.
> Type 'demo()' for some demos, 'help()' for online help, or
> 'help.start()' for a HTML browser interface to help.
> Type 'q()' to quit R.
> [Previously saved workspace restored]
> > source("convert.r")
> > convert("transf")
> Error in file(file, "r") : unable to open connection
> In addition: Warning message:
> cannot open file `transf.cgm'
> >
> 
> Have i done some mistakes?Or i am missing some files?
> Please assist.
> Rgs,
> Orlando.
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> Rhelp at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/rhelp>


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.
On Wednesday, October 22, 2003, at 09:19 AM, Christophe Declercq wrote:
> Your question is not really clear because:
>
>  I don't know what 'convert.r' do
>  I don't know where 'transf.cgm' is (BTW, 'cgm' is not the usual
> extension
> for shapefiles which is 'shp'). Check if it is really in your current
> directory.
>
> but, yes, if what you want is to import shapefiles in R, it's easy.
> Look at
> the 'maptools' package on CRAN (there is also a 'shapefiles' package).
>
> And if you want to build an adjacency matrix for a map of polygons (as
> I
> guess from the header of you mail), look at the 'spdep' package, too.
> It is
> then possible to write a text file with your data as a list readable by
> WinBUGS.
>
> (I send a copy of my answer to the the RSIGGEO mailing list which
> can be
> of interest to you).
>
> Hope it helps.
>
> Christophe
> 
> Christophe DECLERCQ, MD
> Observatoire R?gional de la Sant? NordPasdeCalais
> 13, rue Faidherbe 59046 LILLE Cedex FRANCE
> Phone +33 3 20 15 49 24
> Fax +33 3 20 55 92 30
> Email c.declercq at orsnpdc.org
>
>
>
>> Message d'origine
>> De : rhelpbounces at stat.math.ethz.ch
>> [mailto:rhelpbounces at stat.math.ethz.ch]De la part de Orlando
>> Zacarias
>> Envoy? : mercredi 22 octobre 2003 11:58
>> ? : rhelp at stat.math.ethz.ch
>> Objet : [R] adjacency matrix
>>
>>
>> Dear R experts,
>> I am new to the list and R software. I need to convert arcview
>> file to Winbugs having R has middle package. Got from friends
>> that it is possible following the steps:
>> 1. Converting arcview shapefile to "cgm clear text file"
>> 2. Downloading "convert.r" to into R
>> 2.1 use source("convert.r")
>> 2.2 convert("filename_cgm") without the extension.
>> But that doesn't work, given the following errors:
>> 
>> R : Copyright 2003, The R Development Core Team
>> Version 1.8.0 (20031008)
>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>> You are welcome to redistribute it under certain conditions.
>> Type 'license()' or 'licence()' for distribution details.
>> R is a collaborative project with many contributors.
>> Type 'contributors()' for more information.
>> Type 'demo()' for some demos, 'help()' for online help, or
>> 'help.start()' for a HTML browser interface to help.
>> Type 'q()' to quit R.
>> [Previously saved workspace restored]
>>> source("convert.r")
>>> convert("transf")
>> Error in file(file, "r") : unable to open connection
>> In addition: Warning message:
>> cannot open file `transf.cgm'
>>>
>> 
>> Have i done some mistakes?Or i am missing some files?
>> Please assist.
>> Rgs,
>> Orlando.
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> Rhelp at stat.math.ethz.ch mailing list
>> https://www.stat.math.ethz.ch/mailman/listinfo/rhelp>>
>
> _______________________________________________
> RsigGeo mailing list
> RsigGeo at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/rsiggeo>

Administrator

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
preprocessing tool (also for spdep weights).
Roger
>
>
> On Wednesday, October 22, 2003, at 09:19 AM, Christophe Declercq wrote:
>
> > Your question is not really clear because:
> >
> >  I don't know what 'convert.r' do
> >  I don't know where 'transf.cgm' is (BTW, 'cgm' is not the usual
> > extension
> > for shapefiles which is 'shp'). Check if it is really in your current
> > directory.
> >
> > but, yes, if what you want is to import shapefiles in R, it's easy.
> > Look at
> > the 'maptools' package on CRAN (there is also a 'shapefiles' package).
> >
> > And if you want to build an adjacency matrix for a map of polygons (as
> > I
> > guess from the header of you mail), look at the 'spdep' package, too.
> > It is
> > then possible to write a text file with your data as a list readable by
> > WinBUGS.
> >
> > (I send a copy of my answer to the the RSIGGEO mailing list which
> > can be
> > of interest to you).
> >
> > Hope it helps.
> >
> > Christophe
> > 
> > Christophe DECLERCQ, MD
> > Observatoire R?gional de la Sant? NordPasdeCalais
> > 13, rue Faidherbe 59046 LILLE Cedex FRANCE
> > Phone +33 3 20 15 49 24
> > Fax +33 3 20 55 92 30
> > Email c.declercq at orsnpdc.org
> >
> >
> >
> >> Message d'origine
> >> De : rhelpbounces at stat.math.ethz.ch
> >> [mailto:rhelpbounces at stat.math.ethz.ch]De la part de Orlando
> >> Zacarias
> >> Envoy? : mercredi 22 octobre 2003 11:58
> >> ? : rhelp at stat.math.ethz.ch
> >> Objet : [R] adjacency matrix
> >>
> >>
> >> Dear R experts,
> >> I am new to the list and R software. I need to convert arcview
> >> file to Winbugs having R has middle package. Got from friends
> >> that it is possible following the steps:
> >> 1. Converting arcview shapefile to "cgm clear text file"
> >> 2. Downloading "convert.r" to into R
> >> 2.1 use source("convert.r")
> >> 2.2 convert("filename_cgm") without the extension.
> >> But that doesn't work, given the following errors:
> >> 
> >> R : Copyright 2003, The R Development Core Team
> >> Version 1.8.0 (20031008)
> >> R is free software and comes with ABSOLUTELY NO WARRANTY.
> >> You are welcome to redistribute it under certain conditions.
> >> Type 'license()' or 'licence()' for distribution details.
> >> R is a collaborative project with many contributors.
> >> Type 'contributors()' for more information.
> >> Type 'demo()' for some demos, 'help()' for online help, or
> >> 'help.start()' for a HTML browser interface to help.
> >> Type 'q()' to quit R.
> >> [Previously saved workspace restored]
> >>> source("convert.r")
> >>> convert("transf")
> >> Error in file(file, "r") : unable to open connection
> >> In addition: Warning message:
> >> cannot open file `transf.cgm'
> >>>
> >> 
> >> Have i done some mistakes?Or i am missing some files?
> >> Please assist.
> >> Rgs,
> >> Orlando.
> >>
> >>
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> Rhelp at stat.math.ethz.ch mailing list
> >> https://www.stat.math.ethz.ch/mailman/listinfo/rhelp> >>
> >
> > _______________________________________________
> > RsigGeo mailing list
> > RsigGeo at stat.math.ethz.ch
> > https://www.stat.math.ethz.ch/mailman/listinfo/rsiggeo> >
>
> _______________________________________________
> RsigGeo mailing list
> RsigGeo at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/rsiggeo>

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
email: Roger.Bivand at nhh.no
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N5045 Bergen, Norway


>  Original Message 
> From: "Roger Bivand" <Roger.Bivand at nhh.no>
> To: "Luc Anselin" <anselin at uiuc.edu>
> Cc: <cdeclercq at nordnet.fr>; <rsiggeo at stat.math.ethz.ch>; "Orlando
> Zacarias" <siopz at dsv.su.se>
> Sent: Wednesday, October 22, 2003 6:19 PM
> Subject: Re: [RsigGeo] 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
> preprocessing 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? NordPasdeCalais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax +33 3 20 55 92 30
Email c.declercq at orsnpdc.org


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; rsiggeo at stat.math.ethz.ch; siopz at dsv.su.se
Subject: RE: [RsigGeo] 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>; <rsiggeo at stat.math.ethz.ch>; "Orlando
> Zacarias" <siopz at dsv.su.se>
> Sent: Wednesday, October 22, 2003 6:19 PM
> Subject: Re: [RsigGeo] 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
> preprocessing 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? NordPasdeCalais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax +33 3 20 55 92 30
Email c.declercq at orsnpdc.org
.
 next part 
An HTML attachment was scrubbed...
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/3da73810/attachment.html>
 next part 
A nontext attachment was scrubbed...
Name: not available
Type: image/gif
Size: 494 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/3da73810/attachment.gif>


Hi once again,
Now i have been trying to run the R changed example from Maptools package
manual, and errors occur underlined bellow. It is really troublesome....
Please assist,
Orlando.

shp < try(library(shapefiles))
Error in library(maptools) : There is no package called 'shapefiles'
> if (class(shp) != "tryerror") {
+ ShapeDir < system.file("shapes", package="maptools")[1]
+ try1 < read.shapefile(paste(ShapeDir, "shapes", sep="/"))
+ shppolys < shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
+ plotpolys(shppolys)
+ title(main="Polygons for Vermani from shapefiles package")
+ }
>
> try2 < read.shape(system.file("shapes/Vermani.shp",
+ package="maptools/man")[1])
Error: couldn't find function "read.shape"
> mappolys < Map2poly(try2, as.character(try2$att.data$NEIGNO))
Error: couldn't find function "Map2poly"
> plotpolys(mappolys)
Error: couldn't find function "plotpolys"
> title(main="Polygons for Vermani from maptools package")
Error in title(main = "Polygons for Vermani from maptools package") :
plot.new has not been called yet
> if (class(shp) != "tryerror") {
+ plotpolys(shppolys)
+ plotpolys(mappolys, add=TRUE, border="red", lty="dotted")
+ title(main="Polygons for Vermani overplotted from both packages")
+ }

 next part 
An HTML attachment was scrubbed...
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c5da4174/attachment.html>
 next part 
A nontext attachment was scrubbed...
Name: not available
Type: image/gif
Size: 41982 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c5da4174/attachment.gif>
 next part 
A nontext attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1738 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c5da4174/attachment0001.gif>
 next part 
A nontext attachment was scrubbed...
Name: not available
Type: image/gif
Size: 494 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c5da4174/attachment0002.gif>
 next part 
A nontext attachment was scrubbed...
Name: not available
Type: image/gif
Size: 3937 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c5da4174/attachment0003.gif>


Have you install the shapefiles library on your computer ??
At 12:56 23/10/2003, Orlando Zacarias wrote:
>a77632.gif
>
>Hi once again,
>Now i have been trying to run the R changed example from Maptools package
>manual, and errors occur underlined bellow. It is really troublesome....
>Please assist,
>Orlando.
>
>shp < try(library(shapefiles))
>Error in library(maptools) : There is no package called 'shapefiles'
> > if (class(shp) != "tryerror") {
>+ ShapeDir < system.file("shapes", package="maptools")[1]
>+ try1 < read.shapefile(paste(ShapeDir, "shapes", sep="/"))
>+ shppolys < shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
>+ plotpolys(shppolys)
>+ title(main="Polygons for Vermani from shapefiles package")
>+ }
> >
> > try2 < read.shape(system.file("shapes/Vermani.shp",
>+ package="maptools/man")[1])
>Error: couldn't find function "read.shape"
> > mappolys < Map2poly(try2, as.character(try2$att.data$NEIGNO))
>Error: couldn't find function "Map2poly"
> > plotpolys(mappolys)
>Error: couldn't find function "plotpolys"
> > title(main="Polygons for Vermani from maptools package")
>Error in title(main = "Polygons for Vermani from maptools package") :
> plot.new has not been called yet
> > if (class(shp) != "tryerror") {
>+ plotpolys(shppolys)
>+ plotpolys(mappolys, add=TRUE, border="red", lty="dotted")
>+ title(main="Polygons for Vermani overplotted from both packages")
>+ }
>
>
>a77678.gif
>____________________________________________________
>< http://www.incredimail.com/redir.asp?ad_id=309&lang=9>a77683.gif
>IncrediMail  Email has finally evolved 
>< http://www.incredimail.com/redir.asp?ad_id=309&lang=9>Click Here
>
>_______________________________________________
>RsigGeo mailing list
>RsigGeo at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/rsiggeo next part 
An HTML attachment was scrubbed...
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c8518e77/attachment.html>
 next part 
A nontext attachment was scrubbed...
Name: a77632.gif
Type: image/gif
Size: 41982 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c8518e77/attachment.gif>
 next part 
A nontext attachment was scrubbed...
Name: a77678.gif
Type: image/gif
Size: 1738 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c8518e77/attachment0001.gif>
 next part 
A nontext attachment was scrubbed...
Name: a77683.gif
Type: image/gif
Size: 494 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031023/c8518e77/attachment0002.gif>


Hi
As far as I know, some of the error messages results from the fact that you
either did not install the package or did not load the package.
If you did not install the package, you can install from R's GUI (my
experiences are based on the Windows Version), and load them by type library
(packagename). If you have already installed them, just type library
(packagename) and you will be good to go. For your specific case, after you
started R, just type library(maptools), and you will be able to use all the
functions such as read.shape, Map2poly, plotpolys, etc.
Quoting Orlando Zacarias <siopz at dsv.su.se>:
>
> Hi once again,
> Now i have been trying to run the R changed example from Maptools package
> manual, and errors occur underlined bellow. It is really troublesome....
> Please assist,
> Orlando.
> 
> shp < try(library(shapefiles))
> Error in library(maptools) : There is no package called 'shapefiles'
> > if (class(shp) != "tryerror") {
> + ShapeDir < system.file("shapes", package="maptools")[1]
> + try1 < read.shapefile(paste(ShapeDir, "shapes", sep="/"))
> + shppolys < shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
> + plotpolys(shppolys)
> + title(main="Polygons for Vermani from shapefiles package")
> + }
> >
> > try2 < read.shape(system.file("shapes/Vermani.shp",
> + package="maptools/man")[1])
> Error: couldn't find function "read.shape"
> > mappolys < Map2poly(try2, as.character(try2$att.data$NEIGNO))
> Error: couldn't find function "Map2poly"
> > plotpolys(mappolys)
> Error: couldn't find function "plotpolys"
> > title(main="Polygons for Vermani from maptools package")
> Error in title(main = "Polygons for Vermani from maptools package") :
> plot.new has not been called yet
> > if (class(shp) != "tryerror") {
> + plotpolys(shppolys)
> + plotpolys(mappolys, add=TRUE, border="red", lty="dotted")
> + title(main="Polygons for Vermani overplotted from both packages")
> + }
> 


>
>  Original Message 
> From: "Orlando Zacarias" <siopz at dsv.su.se>
> To: <cdeclercq at nordnet.fr>
> Cc: <rsiggeo at stat.math.ethz.ch>; <rhelp at stat.math.ethz.ch>
> Sent: Thursday, October 23, 2003 6:56 PM
> Subject: RE: [R] adjacency matrix
>
>
>
> Hi once again,
> Now i have been trying to run the R changed example from Maptools
> package manual, and errors occur underlined bellow. It is really
> troublesome....
> Please assist,
> Orlando.
> 
> shp < try(library(shapefiles))
> Error in library(maptools) : There is no package called 'shapefiles'
The message is clear!
> > if (class(shp) != "tryerror") {
> + ShapeDir < system.file("shapes", package="maptools")[1]
> + try1 < read.shapefile(paste(ShapeDir, "shapes", sep="/"))
> + shppolys < shape2poly(try1, as.character(try1$dbf$dbf$NEIGNO))
> + plotpolys(shppolys)
> + title(main="Polygons for Vermani from shapefiles package")
> + }
> >
> > try2 < read.shape(system.file("shapes/Vermani.shp",
> + package="maptools/man")[1])
> Error: couldn't find function "read.shape"
> > mappolys < Map2poly(try2, as.character(try2$att.data$NEIGNO))
> Error: couldn't find function "Map2poly"
> > plotpolys(mappolys)
> Error: couldn't find function "plotpolys"
> > title(main="Polygons for Vermani from maptools package")
> Error in title(main = "Polygons for Vermani from maptools package") :
> plot.new has not been called yet
> > if (class(shp) != "tryerror") {
> + plotpolys(shppolys)
> + plotpolys(mappolys, add=TRUE, border="red", lty="dotted")
> + title(main="Polygons for Vermani overplotted from both packages")
> + }
> 
Did you forget:
> library(maptools)
before that?
Christophe

Administrator

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; rsiggeo at stat.math.ethz.ch; siopz at dsv.su.se
> Subject: RE: [RsigGeo] 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>; <rsiggeo at stat.math.ethz.ch>; "Orlando
> > Zacarias" <siopz at dsv.su.se>
> > Sent: Wednesday, October 22, 2003 6:19 PM
> > Subject: Re: [RsigGeo] 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
> > preprocessing 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
GeoBUGSfriendly 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 miniHOWTO, possibly with the
author of convert.r (cc to Yue Cui, thread "adjacency matrix" on rhelp
and rsighelp)?
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? NordPasdeCalais
> 13, rue Faidherbe 59046 LILLE Cedex FRANCE
> Phone +33 3 20 15 49 24
> Fax +33 3 20 55 92 30
> Email c.declercq at orsnpdc.org
>
>
>
> .

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
email: Roger.Bivand at nhh.no
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N5045 Bergen, Norway


> Message d'origine
> De : rsiggeobounces at stat.math.ethz.ch
> [mailto:rsiggeobounces at stat.math.ethz.ch]De la part de Roger Bivand
> Envoy? : vendredi 24 octobre 2003 22:19
[...]
> > 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?
Something generic would be useful but not that simple if you want to take
care of:
 the different models we can use (a simple example is the case where we
have an X variable for ecological regression)
 the different ways to connect R and WinBUGS:
 export all the data from R in a format WinBUGS can read and do all the
work in WinBUGS
 driving completely the WinBUGS engine from R (the bugsR approach)
 a semiinteractive way using some of the bugsR functions to write text
files with data and inits, launching WinBUGS script from R (with something
as 'system("C:/\"Program Files\"/WinBUGS14/WinBUGS14 /par script.txt")', do
what you want in WinBUGS: more iterations, MCMC diagnostics... and save what
you want, get back in R when closing WinBUGS, read the saved files you need
in R to map estimates... It's the way I use now.
>
> Would a similar function to output the polygon boundaries in a
> GeoBUGSfriendly format be helpful  should that rather be in maptools?
I don't use GeoBUGS mapping functions at all for the moment (I use
plotpolys()... and poly2nb()...) but, yes, it should be useful. As I
understand it, GeoBUGS read the S maps format: would converting polylist
from/to S maps be useful?
> 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 miniHOWTO, possibly with the
> author of convert.r (cc to Yue Cui, thread "adjacency matrix" on rhelp
> and rsighelp)?
Good idea! I can try to write a rough HOWI sketch if you want. I hope
Orlando has eventually been sucessful in his work and so his experience will
be useful.
Christophe

Christophe DECLERCQ, MD
Observatoire R?gional de la Sant? NordPasdeCalais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax +33 3 20 55 92 30
Email c.declercq at orsnpdc.org


Dear list friends,
I should have written this msg before, but so many things happened in
between that made it impossible.... So, i have to thank everybody for the
help, suggestion and discussion on this issue. I have solved the problem by
using GeoDa to produce the adj. matrix and loaded the results of WinBugs run
into arcview to produce my maps. Anyway, i will continue to learn Rsoftware
to avoid all these complications.
Regards,
orlando.
Original Message
From: cdeclercq at nordnet.fr
Date: 27 October 2003 10:43:00
To: Roger.Bivand at nhh.no; Orlando Zacarias
Cc: rsiggeo at stat.math.ethz.ch; yuecui at biostat.umn.edu
Subject: RE: [RsigGeo] RE: [R] adjacency matrix
> Message d'origine
> De : rsiggeobounces at stat.math.ethz.ch
> [mailto:rsiggeobounces at stat.math.ethz.ch]De la part de Roger Bivand
> Envoy? : vendredi 24 octobre 2003 22:19
[...]
> > 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?
Something generic would be useful but not that simple if you want to take
care of:
 the different models we can use (a simple example is the case where we
have an X variable for ecological regression)
 the different ways to connect R and WinBUGS:
 export all the data from R in a format WinBUGS can read and do all the
work in WinBUGS
 driving completely the WinBUGS engine from R (the bugsR approach)
 a semiinteractive way using some of the bugsR functions to write text
files with data and inits, launching WinBUGS script from R (with something
as 'system("C:/\"Program Files\"/WinBUGS14/WinBUGS14 /par script.txt")', do
what you want in WinBUGS: more iterations, MCMC diagnostics... and save what
you want, get back in R when closing WinBUGS, read the saved files you need
in R to map estimates... It's the way I use now.
>
> Would a similar function to output the polygon boundaries in a
> GeoBUGSfriendly format be helpful  should that rather be in maptools?
I don't use GeoBUGS mapping functions at all for the moment (I use
plotpolys()... and poly2nb()...) but, yes, it should be useful. As I
understand it, GeoBUGS read the S maps format: would converting polylist
from/to S maps be useful?
> 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 miniHOWTO, possibly with the
> author of convert.r (cc to Yue Cui, thread "adjacency matrix" on rhelp
> and rsighelp)?
Good idea! I can try to write a rough HOWI sketch if you want. I hope
Orlando has eventually been sucessful in his work and so his experience will
be useful.
Christophe

Christophe DECLERCQ, MD
Observatoire R?gional de la Sant? NordPasdeCalais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax +33 3 20 55 92 30
Email c.declercq at orsnpdc.org
.
 next part 
An HTML attachment was scrubbed...
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031126/88cc70f8/attachment.html>
 next part 
A nontext attachment was scrubbed...
Name: not available
Type: image/gif
Size: 494 bytes
Desc: not available
URL: < https://stat.ethz.ch/pipermail/rsiggeo/attachments/20031126/88cc70f8/attachment.gif>

