[STATSGRASS] Re: [GRASS5] r.moran

Roger Bivand Roger.Bivand at nhh.no
Wed Mar 22 10:57:31 EST 2006


On Wed, 22 Mar 2006, Wolf Bergenheim wrote:

> On Wed, 22 Mar 2006, Roger Bivand wrote:
> 
> >>
> >> This is what the data looks like:
> >> http://wolf.bergenheim.net/tmp/alkoul_i.jpg
> >
> > What platform are you doing the analysis on?
> >
> 
> Debian Linux, Intel CPU.
> 
> > The immediate easy route is the shapefile. Yes, R can talk to SQLite, but
> > I can't, so can't advise on that.
> >
> 
> So R can can read shapefiles. cool (: I have R installed and I 
> also installed the spgrass6 package. I have root access so I can install 
> additional software.

Fine. Can I suggest that you make a personal directory for the additional 
contributed packages, then you don't need to change who you are too often? 
In my .bashrc I have:

R_LIBS="$HOME/lib/R" ; export R_LIBS

which R picks up, and uses in addition to the system-wide library. Did you 
install R from source, or otherwise? Source is nice, because then you know 
that it figures out your machine and gets dependencies right straight 
away, but the debian binary builders are very good too.

Under Linux (and other platforms), the easiest way to install contributed 
packages is from the R prompt, as you've seen. Some packages depend on 
other R packages, but some have external dependencies, which also need 
meeting.

You'll need the spdep package and all its dependencies, so:

install.packages("spdep", depencencies=TRUE)

does that, and the packages end up in your own library. 

The easiest way for now to import the shapefile is to do v.out.ogr from 
GRASS, and 

library(maptools)
my_shape <- readShapePoly("my_shape.shp")
plot(my_shape)
names(my_shape)

maybe

summary(my_shape)

If you are running R within GRASS (start R from the GRASS shell prompt),
you can give my_shape its coordinate reference system by:

library(spgrass6)
meta <- gmeta6()
proj4string(my_shape) <- CRS(meta$proj4)

in case that is needed.

Being brave:

library(classInt)
var_class_intervals <- classIntervals(my_shape$variable_of_interest, 
  style="fisher")
cols <- findColours(var_class_intervals, pal=c("blue", "red"))
plot(my_shape, cols)

and hope the plot shows the data in similar places to the PNGs.

Shall we try to get that far first - I'm not too sure how many polygons 
there are, but there seem to be a fair number?

The next bits are simple:

my_nb <- poly2nb(my_shape) 

maybe setting queen=FALSE to only choose neighbours sharing more than just 
a corner point.

print(my_nb)
plot(my_nb, coordinates(my_shape))

display the neighbours.



More information about the grass-stats mailing list