Re: [R] write geotiff with projection - RGDAL package

2007-09-07 Thread Roger Bivand
On Thu, 6 Sep 2007, Monica Pisica wrote:


 Hi,

 Doing more search i've discovered package RGDAL that can write a geotiff 
 file with projection. I saved a geotiff file in UTM projection and if i 
 read the file back in R and check the projection seems that everything 
 is OK. But if i load the file in ArcGIS (ESRI product) i get the warning 
 that the file is missing spatial reference so it cannot be projected, 
 but it is displayed correctly. I guess somewhere i am doing a mistake 
 when i define the projection in R. My code follows:

 data.grid - read.csv(x, header=TRUE)
 gridded(data.grid) = ~East.m.+North.m.
 proj4string(data.grid) = CRS(+proj=tmerc +lat_0=0.000 
 +lon_0=-81.000 +k=0.9996 +x_0=50.00 +y_0=0.000 
 +ellps=GRS80 +units=m)
 tr - e:\\JELA_veg\\test_gtiff\\test.tif
 writeGDAL(data.grid[class.pca], tr)

 mg3 - readGDAL(tr)
 proj4string(mg3)
 [1]  +proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs

 I will really appreciate if anybody can point me in the right dirrection.

In my previous reply, I suggested that you visit:

http://www.gdal.org/frmt_gtiff.html

There you will find that for ESRI products, you may need to set
options=TFW=YES at least, because ESRI products do not honour the 
projection information already encoded inside the GTiff file. The 
information is there, it is just that ESRI products only look for it in 
places they have thought of, not in the proper places. If necessary, 
showWKT() can make a *.prj file. Otherwise just override ESRI.

Roger


 Thanks,

 Monica


 _
 News, entertainment and everything you care about at Live.com. Get it now!
 http://www.live.com/getstarted.aspx

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] geotiff or tiff files with world files

2007-09-06 Thread Roger Bivand
Monica Pisica pisicandru at hotmail.com writes:

 
 
 Hi,
 
 I have a matrix of data which i can vizualize as an image - for example.
 I would like to save this image as a
 geotiff file or at a tiff file with a world file which holds the projection
 of my data (ultimately the data
 represent a map of some sort). I know i can save the data as an ESRI
 grid, but i am not interested in that.
 
 I wonder if anybody knows about any code which will help me do that.

See the writeGDAL() function in the rgdal package, and hints on how to 
turn your matrix into a SpatialGridDataFrame object in the sp package. 
For example:

data(volcano)
str(volcano)
image(volcano)
grd - GridTopology(c(0.5, 0.5), c(1, 1), c(87, 61))
SGDF - SpatialGridDataFrame(grd, data=data.frame(volcano=c(volcano)))
image(SGDF, volcano)

See the proj4string= argument to insert the projection in valid PROJ.4 
format. Then:

writeGDAL(SGDF, volcano.tif, drivername = GTiff, ...)

using the options= id needed, to pass through create options as on:

http://www.gdal.org/frmt_gtiff.html

For follow-ups, please consider the R-sig-geo list.

Roger

 
 Thanks in advance,
 
 Monica
 _
 
 s. It's easy!
 
 aspxmkt=en-us
   [[alternative HTML version deleted]]
 
 __
 R-help at stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [R-sig-Geo] Plot SpatialLinesDataFrame with xlim ylim

2007-07-11 Thread Roger Bivand
On Wed, 11 Jul 2007, Edzer J. Pebesma wrote:

 Michael,

 The plot method for SpatialLinesDataFrame objects resides in package sp,
 and questions regarding it are easier noticed on the r-sig-geo mailing
 list.

 The reason why they are plotted with aspect ratio 1 is that they are
 assumed to be spatial (geographical) data, and assume that 1 m north
 equals 1 m west -- think of a map. The exception is when the projection
 argument is set to longlat data (i.e. decimal degrees North/East), where
 the aspect ratio is computed differently, such that the argument above
 more or less holds.

 You should be able to override the default aspect setting by explicitly
 passing the e.g. asp=0.5 argument to plot.

 Here's the comment in the documentation of plot for Spatial objects
 (such as SpatialLinesDataFrame):

 The default aspect for map plots is 1; if however data are not projected
 (coordinates are longlat), the aspect is by default set to 1/cos(My *
 pi)/180) with My the y coordinate of the middle of the map (the mean of
 ylim, which defaults to the y range of bounding box).

 The argument |setParUsrBB| may be used to pass the logical value |TRUE|
 to functions within |plot.Spatial|. When set to |TRUE|, par(?usr?) will
 be overwritten with |c(xlim, ylim)|, which defaults to the bounding box
 of the spatial object. This is only needed in the particular context of
 graphic output to a specified device with given width and height, to be
 matched to the spatial object, when using par(?xaxs?) and par(?yaxs?) in
 addition to |par(mar=c(0,0,0,0))|.


Yes, if you look at how the GE_SpatialGrid() function in maptools works - 
you'll see how it meddles with the actual regional extents and the device 
size. I think Michael's data should also have been set to longlat:

proj4string(tmp) - CRS(+proj=longlat)

The key is realising that the axes are driven by the device shape, not by 
the xlim/ylim as such, as Edzer says.

Roger


 --

 Edzer

 I'm running windows xp, R 2.3.1 with maptools 0.6-6, I guess.
 When plotting from a large SpatialLinesDataFrame and using xlim  ylim to 
 reduce the area, the plot axes automatically have the same scale size, even 
 if xlim and ylim ranges differ.
 E.g.:
 tmp - readShapeLines(filepath)
 plot(tmp,xlim=c(-126,-119),ylim=c(50,51))

 The y-axis range is actually 47-54, same range as the x-axis.  What am I 
 doing wrong?  Should I be using a different object for simple coastline  
 river data?
 Thanks in advance!
 Michael

 ___
 R-sig-Geo mailing list
 [EMAIL PROTECTED]
 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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] installing GRASS-R packages

2007-06-13 Thread Roger Bivand
On Wed, 13 Jun 2007, Philippe LAGACHERIE wrote:

 Hi,
 I tried to install R packages required for the GRASS-R interface by
 using the following command (copied from
 http://www.geog.uni-hannover.de/grass/statsgrass/grass6_r_install.html):
 /install.packages (c(sp, spgrass6,rgdal,maptools), dependencies
 =TRUE)/
 rgdal package was installed successfully;
 There were problems to find 'sp' and 'maptools' packages. The error
 message was /: dependencies 'sp' and 'maptools' are not available/.
 I tried to download the packages from three different mirrors with the
 same result  ( http://cran.fr.r-project.org/ ,
 http://cran.mirroring.de/, http://probability.ca/cran/ )
 http://probability.ca/cran/
 I then failed to download 'spgrass6' since it required to download first
 sp
 can anybody tell me what mistake I did and how (where?) I can get these
 packages

The note in the OSGeo Journal:

http://www.osgeo.org/files/journal/final_pdfs/OSGeo_vol1_GRASS-R.pdf

is more recent, although the note you accessed is accurate, and says just:

install.packages(spgrass6, dependencies = TRUE)

should be enough, because all the packages are on CRAN, and current sp 
and maptools are on at least http://cran.fr.r-project.org.

Topics like this are best raised on the R-sig-geo list, or perhaps on the 
GRASS STATGRASS list. It is also good practice to say what platform you 
are on (OS, R version, etc.) as reported by sessionInfo().

 Thank you very much by advance
 http://probability.ca/cran/



-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Build Windows pkgs from source - online

2007-06-12 Thread Roger Bivand
On Tue, 12 Jun 2007, Benilton Carvalho wrote:

 Hi,

 First of all, I apologize for sending out this message, as I'm sure
 the answer is on the archives, but I just can't find it.

 Not long ago, there was a discussion about building Windows packages
 from the source code and someone posted a link to a website  to which
 we could submit the source and get the Windows version a while later.

 Could someone point me to that website or to where I can find such info?

http://win-builder.r-project.org/

from link on:

http://cran.r-project.org/src/contrib/PACKAGES.html

via

http://cran.r-project.org/bin/windows/contrib/checkSummaryWin.html


 Thanks,

 -benilton

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Starting R within an VBA makro

2007-06-11 Thread Roger Bivand

On Mon, 11 Jun 2007, Maja Schröter wrote:


Hello everybody,

at work I want to start R within an VBA program.

First I calculate something in Excel 2003.

After that I want to start within my VBA makro R wich should start an R 
file, say i.g, superplot.R which plots me the data well.


So is it possible?


http://cran.r-project.org/contrib/extra/dcom/00ReadMe.html

and

RSiteSearch(Excel VBA)





Maybe something like that:

sub test()

 'calculate something

start R superplot.R

end test()

Thank you so much.

Kindly regards,

Maja





--
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: [EMAIL PROTECTED]
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] spgrass6 and aggregation (bis)

2007-06-06 Thread Roger Bivand
On Wed, 6 Jun 2007 [EMAIL PROTECTED] wrote:

 
 Dear all,
 
 I have some additionale question concerning the spgrass6 package.
 
 * When you set a region in GRASS, does the readGRASS6 function in R only
 load data contained in the zoomed region or the whole map ?

readRAST6() uses the current region, readVECT6() should not clip to the 
current region.

 
 * When you have a MASK map in grass, does the readGRASS6 function in R only
 load data contained inside the MASK area ?
 

MASK is respected (in spearfish):

r.mask input=rushmore
d.rast elevation.dem
R
library(spgrass6)
el - readRAST6(elevation.dem)
summary(el)
image(el)

 
 Could this be the problem ?

No, the problem was that you did not pay attention to the class of the 
data objects you were reading. You could have done:

my_SGDF - readRAST6(c(landuse_mapname_in_grass, 
  catchement_mapname_in_grass,
  precipitation_mapname_in_grass), cat=c(TRUE, TRUE, FALSE))

treating the whole as a single SpatialGridDataFrame, and the first two 
maps as factors (categorical).

Please remember that class(), summary(), image(), and other methods let 
you look at the data you have read - here I would certainly do:

summary(my_SGDF)
image(my_SGDF, precipitation_mapname_in_grass)

You can then try:

my_DF - as(my_SGDF, data.frame)
aggregate(my_DF, by=list(my_DF$catchement_mapname_in_grass, 
  my_DF$landuse_mapname_in_grass), sum, na.rm=TRUE)

although I'm not sure whether this is what you need.

There are two mailing lists that are better suited to this question, 
R-sig-geo on the R side, and STATGRASS on the GRASS side, both with a fair 
number of experienced helpers.

 
 Thanks,
 
 Jessica
 
 
 3
 
 Dear all,
 
 
 I am exporting grass map into R thanks to the very useful spgrass6 package.
 
 library(spgrass6)
 
 # I have 3 map I am working with a MASK map of a specific area.
 
 # 1) a landuse map
 landuse-readRAST6(landuse_mapname_in_grass)
 
 # 2) a catchment map which divide the area in several catchements
 catchment-readRAST6(catchement_mapname_in_grass)
 
 # 3) a precipitation map
 precipitation-readRAST6(precipitation_mapname_in_grass)
 
 
 # then I would like to sum the precipitation spatialy over each catchment
 and landuse. So, first I cbind all maps with cbind
 
 MAP-cbind(landuse,catchment,precipitation)
 
 # then I use the aggregate function
 SUM-aggregate(MAP[3],by=list(MAP[1],MAP[2]),sum,na.rm=TRUE)
 # here is the problem !!!
 Error in as.vector(x, mode) : invalid argument 'mode'
 
 
 
 I don't find any idea to solve this...
 
 Does anyone has a suggestion ??
 
 Thanks in advance
 
 
 Jess
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] kernel smooth for tw-dimensional data

2007-06-05 Thread Roger Bivand
On Tue, 5 Jun 2007, Patrick Wang wrote:

 Hi, I found kde2d in the MASS packages return densities for the bivariate
 random varaibles.
 
 I donot understand why each element of density Z is a 2*2 matrix.
 Why it is not a number.
 
 For example, a bivariate normula distribution given (x, y) will return a
 number, the density, not a matrix.

I think you were asking these questions last week: 

library(mvtnorm) 
?dmvnorm

not 2D kernel *density* (the word is perhaps overloaded).

However, kde2d() *is* a 2D density(), so maybe you need to consider what 
you are looking for.

 
 Thanks
 Pat
 
 
  Hi all:
 
  I can use the density() function to get the kernel density for given
  observed data X with bandwidth.
 
  Is there a function in R that can take in two dimensional data(x, y) and
  return a joint density based
  on the bandwidth. Do I need to provide bandwith for x and then for y?
 
  Is the GRASS package
  kde2d.G(x, y, h, G, reverse=reverse(G))
 
  provide such function?
 
  Thanks
  pat
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] spatial simulation

2007-06-02 Thread Roger Bivand
On Fri, 1 Jun 2007, Kitty Lee wrote:

 Dear R-users,
 
 I'm trying to do some spatial simulation. I have two covariates, Z and
 C. I want to examine their relationship under different spatial
 distribution.
 
 I have no problem simulating completely spatial random process but I'm
 totally stuck on poisson (cluster) pattern. I already have a dataset
 with Z and C (obs=575) and I know the relationship between them. Using
 these 575 cases, how can I simulate a clustered process and have a
 dataset that has four columns:
 
 x-coor y-coor z c
 
 I know I can use rpois or pcp.sim to generate points that clustered and
 then use cbind to attach Z and C values. But the problem is my
 observations will not be spatially clustered. How can I simulate so that
 now Z is spatially clustered?

Although you are not being very clear, I think that unless both Z and C
are marked point processes (ie. both take (discrete) values and are
observed at different points), this is not a spatial point process
problem. If Z and C are observed at the same points, and what you are
looking for are clusters of correlated values of Z with C, the clusters
are not the locations of the points, but rather the co-occurrence of
high/low values of Z and C respectively. How to go forward from here would
depend on what kind of process you are actually interested in. More 
detail might help - as might following up on R-sig-geo, rather than on the 
general list. 

 
 Thanks!
 
 K.
  

 -
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [R-sig-Geo] Connecting to PostgreSQL/PostGIS from R (rgdal?)

2007-05-30 Thread Roger Bivand
On Wed, 30 May 2007, Mike Leahy wrote:

 Hello,
 
 I've been trying every now and then to find a cross operating system
 solution that would let me access PostgreSQL (and PostGIS) from R, or to
 access R from PostgreSQL.  I know of pl/r, which accomplishes the
 latter, but has yet to be successfully ported to Windows.  Similarly,
 I've tried to use Rdbi and DBI, but I haven't had luck with those on
 Windows either for connecting to PostgreSQL from R.  Can anyone suggest
 a solution for this?
 
 It would seem that rgdal could also help me in this case. Unfortunately,
 the version of the GDAL library that is included in the rdgal binary
 available on CRAN (for windows) doesn't include the PostgreSQL driver
 for OGR (i.e., it's not listed by the ogrDrivers() function).
 
 I compiled rgdal on Windows myself using the GDAL library from
 FWTools-1.3.1, but I was unsuccessful at creating a proper binary
 package for R.  I was only able to get it to work by substituting the
 rgdal.dll that was installed by CRAN with the one that I compiled that
 links against the GDAL library from FWTools.  Even though it works (at
 first glance with ogrInfo(), and readOGR()), I still get a warning
 message when I load the libary: DLL attempted to change FPU control
 word from 8001f to 9001f.
 
 So my question with respect to rgdal is a) is it likely that an rgdal
 package is going to be released in the future with the PostgreSQL driver
 included in GDAL/OGR, or b) are there any suggestions/instructions that
 might get me through the compilation and packaging process for rgdal
 with better success?

The warning is harmless - R is just reporting that it has stopped the 
dynamically linked libraries resetting a flag that they should not change 
while R is running. If you followed the notes in README.windows in rgdal, 
you ought to be OK. There are no plans to provide more Windows binary 
drivers than those present now, because the others involve further 
external dependencies, which most users would not welcome. 

So please try to do an ogrinfo at the command line in Windows using
FWTools to your PostGIS data, and then the equivalent within R with your
locally built rgdal, and see how it goes. Even on Linux, getting all the
components lined up isn't easy, according to people who have tried, but
can be done if you need to do it.

Hope this helps,

Roger

 
 Thanks in advance for any help,
 Mike
 
 ___
 R-sig-Geo mailing list
 [EMAIL PROTECTED]
 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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Zipcodes latitude and longitude

2007-05-23 Thread Roger Bivand
On Tue, 22 May 2007, Farrel Buchinsky wrote:

 I see several mapping libraries but cannot find how to do a simple task.

(for some definition of simple)

Perhaps this thread:

http://article.gmane.org/gmane.comp.lang.r.geo/1534

on geocoding might help, especially Gabor Grothendieck's contribution.

 Starting with a vector of zip codes (in the United States and in Canada) I
 would like to automatically lookup the corresponding coordinates. Can you
 suggest a package and function that I should turn to?
 I would also like to automatically pull in the altitude, and some climate
 data.

Elevation data are available from USGS at varying resolutions, but how you 
want them smoothed for the zip code polygons is not given, it will be your 
choice. The polygons (but not for strictly postal zip codes) are on the US 
Census site for the US, I'm not aware of the correct address for Canada, 
but data are being released for administrative boundaries. Climate data 
may be available for download, but note that the point support for your 
zip code units doesn't suit climate either, really. Unless the met. 
stations are at your points, the values will be interpolated rather than 
observed.

Follow-ups to R-sig-geo, please.

Roger

 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Graphically show population density for a specific geographicarea using R

2007-05-21 Thread Roger Bivand
On Mon, 21 May 2007, Greg Snow wrote:

 1. Yes you need a shape file with that information.
 
 2. One place to look is:
 http://www.census.gov/geo/www/cob/bdy_files.html There are shapefiles
 (the .shp ones) for counties and zip codes (as well as many other
 things).  These work pretty directly with the tools in the maptools and
 sp packages.
 
 3. Read the .shp file in using maptools, the .dbf information is
 automatically read in as well (with whatever details come with the
 shapefile), then look at the structure of what you read in, you will see
 the data frame and you should be able to just add your data into that
 data frame, or use it seperately.

wget http://www.census.gov/geo/cob/bdy/zt/z500shp/zt17_d00_shp.zip
unzip zt17_d00_shp.zip
R

ill_zip - readShapePoly(zt17_d00.shp, proj4string=CRS(+proj=longlat))
names(ill_zip)
summary(ill_zip)
plot(ill_zip, axes=TRUE)

suggests that there is no useful attribute data in the shapefile. It is in 
geographical coordinates, so that the AREA variable is not in useful 
coordinates. If you look at the codes, you'll see that some are 
represented by multiple polygons, especially the HH codes (water 
features). Also note that ZCTA are not the same as Postal ZIP Codes, 
according to the FAQ.

The easiest way to map a variable at the moment is:

spplot(ill_zip, AREA)
 ill_zip$HH - FALSE
 ill_zip$HH[grep(HH, as.character(ill_zip$NAME))] - TRUE
 spplot(ill_zip, HH)

only AREA doesn't tell you anything. You'll need to look for data for
ZCTAs or similar, and if you need to compute the areas, project to
something suitable and extract the values from the underlying
SpatialPolygons object.

Finally, you'll need up-to-date numbers of inhabitants, as at this scale, 
a housing development can easily date your data.

I suggest you follow up on R-sig-geo.

Roger

 
 4. plot.Map has an option auxvar, though it is now prefered to use the
 plot methods for the more specific objects (SpatialLinesDataFrame object
 from the readLinesShape function).  I would expect that they would have
 an auxvar or similar argument also.  Or you can decide what color you
 want to use, plot the overall map, then add each county/zipcode
 individually using the specified color.
 
 Hope this helps,
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] a question about spatial autocorrelation in R

2007-05-14 Thread Roger Bivand
On Mon, 14 May 2007 [EMAIL PROTECTED] wrote:

 Dear all,
 
 I am currently facing a problem related to the spatial autocorrelation of 
 a sample of stations; these stations supply weekly data for a fixed 
 time-window during the year (namely, 4-6 months per year).

Could I suggest that you read the relevant parts of Collecting Spatial 
Data by Werner G. Müller, 3rd edition 2007? Given your second question, 
the book's treatment of experimental design is probably relevant. 

Once you've found a suitable approach, perhaps R-sig-geo would be a more 
focussed list to go forward to see if suitable functions are available?

Roger

 
 For this reason I'm trying to use the R package 'spdep' (specifically 
 Moran's I) in order to get rid of it.
 
 Does anyone know how is it possible (if it is...) to estimate the spatial 
 autocorrelation of this kind of data ? In other words, in the examples I 
 could only see applications of Moran's I related to a time-independent 
 distribution of data from any sample of stations.
 
 Another question's coming up right now: if I change the sample of stations 
 for a future development, is there the chance to get an estimation of the 
 degree of spatial autocorrelation, given only the geographical location of 
 the sampling points ?
 
 Thanks a lot for the attention !!!
 
 Stef
 
 Stefano Marchesi
 Environmental Epidemiologic Unit
 Environmental Protection Agency - ARPA Emilia Romagna
 Via Fontanelli 23 - 41100 Modena (Italy)
 tel: +39 059 433635 (int. 5035)
 fax: +39 059 241312
 sito web: www.arpa.emr.it/epam
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] control margin when plotting polygons?

2007-05-12 Thread Roger Bivand
On Fri, 11 May 2007, Shengde Liang wrote:

 
 Hello everyone,
 
 I have some difficulties on controling the margin of a plot.
 For example, the following code from the help of maptools:
 
 library(maptools)
 xx - readShapePoly(system.file(shapes/sids.shp, package=maptools)[1], 
 IDvar=FIPSNO, proj4string=CRS(+proj=longlat +ellps=clrk66))
 plot(xx, border=blue, axes=TRUE, las=1)
 
 There is a lot of white margin on the bottom and top of the plot and I 
 want to get rid of it. I used option usr, but it does not make any 
 change.
 
 plot(xx, border=blue, axes=TRUE, las=1,usr=c(-85,-75,33,39))
 par(usr=c(-85,-75,33,39))
 plot(xx,border=blue,axes=T,las=1)
 
 Option ylim does not work either.

This plot method is more complicated than you can see for geographical 
coordinates, because the y axis is streched. But the real cause of your 
problem is the shape of the plot device. If you compare the output of:

png(default_size.png, pointsize=8)
par(mar=c(3,3,1,1))
plot(xx, border=blue, axes=TRUE, las=1)
dev.off()
png(portrait_size.png, width=300, height=480, pointsize=8)
par(mar=c(3,3,1,1))
plot(xx, border=blue, axes=TRUE, las=1)
dev.off()
png(landscape_size.png, width=480, height=300, pointsize=8)
par(mar=c(3,3,1,1))
plot(xx, border=blue, axes=TRUE, las=1)
dev.off()

you can see that the amount of the plotting area covered by the map can be 
controlled to reduce the white space.

You can also use par(mar=c()) to remove margins, but then possibly without
the axes, or at least watching the effects of las=. The GE_SpatialGrid()  
function also sets up cropping sizes for export of maps in geographical
coordinates as image overlays for Google Earth, and may contain some
ideas.

 
 Anyone has any idea how to do it?

The answers vary a great deal depending on needs, and are seldom 
completely general. For publication, editing externally may be an option.

Roger

 
 Thanks a lot.
 
 Best,
 
 Shengde Liang
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with map

2007-05-05 Thread Roger Bivand
On Sat, 5 May 2007, Alberto Vieira Ferreira Monteiro wrote:

 [for those that worry about these things, this _is_ a homework
 assignment. However, it's not an R homework, it's a Geography
 and History homework... and I want to use R to create a pretty
 map]
 
 Roger Bivand wrote:
 
  Is there any way to associate one color to each country?
 
  Try:
 
  map_poly_obj - map(worldHires, c(Argentina, Brazil), plot=FALSE,
fill=TRUE)
  str(map_poly_obj)
 
  and you'll see that the component of interest is the named polygons, of
  which there are 28, namely
 
 Ok, I guess I can see what you mean. It worked, but I don't think
 this is a practical way to draw things.
 
 For example, suppose [this would help homework mentioned above] I
 want to draw a series of maps showing the evolution of Communism
 in the XX century. I would like to start with a 1917 map, showing most
 countries as in...
 
 map(worldHires)
 
 ... but with the Soviet Union in red. I don't see how I could mix the two 
 maps (BTW, there's no Russia in worldHires, but there is a USSR...)
 
 map(worldHires); map(worldHires, USSR, col=red, fill=T)

[Please note that the worldHires database refers to a particular time
cross section, probably late 1980's. The territorial extents of the former
USSR in 1919, 1920, 1939, 1940, 1941, 1944, 1945, etc., etc. are not the
same;  the same consideration would apply to PRC's actual control over
Tibet. 

So to do this, you need a sequence of maps showing the marginal
increments, with 1917 actually only colouring Petrograd/St Petersburg and
perhaps some other cities. I'm not aware of any publically available
sequence of boundary files adequately representing the situation of say
the Baltic states or Finland for the 1917-2007 period, if anyone has a
suitable link, please say so.

Geographical data are vintaged, not just where, but where when. Was
for example Estonia occupied by the USSR 1940-1941, 1944-1991, or was it
part of the USSR for the purposes of this exercise? Using disputed 
boundaries implies a choice of point of view, one that may not be 
intended.]

Roger

 
 
  map_poly_obj$names
 
  So you can build a matching colours vector, or:
 
  library(sp)
  library(maptools)
  IDs - sapply(strsplit(map_poly_obj$names, :), function(x) x[1])
  SP_AB - map2SpatialPolygons(map_poly_obj, IDs=IDs,
proj4string=CRS(+proj=longlat +datum=wgs84))
 
  but
 
  plot(SP_AB, col=c(cyan, green))
 
  still misses, because some polygons have their rings of coordinates in
  counter-clockwise order, so:
 
  pl_new - lapply(slot(SP_AB, polygons), checkPolygonsHoles)
  slot(SP_AB, polygons) - pl_new
  # please forget the assignment to the slot and do not do it unless you can
  # replace what was there before
 
  plot(SP_AB, col=c(cyan, green), axes=TRUE)
 
  now works. Moreover, SP_AB is a SpatialPolygons object, which can be
  promoted to a SpatialPolygonsDataFrame object, for a data slot holding a
  data.frame with row names matching the Polygons ID values:
 
  sapply(slot(SP_AB, polygons), function(x) slot(x, ID))
 
  So adding a suitable data frame gets you to the lattice graphics method
 
  spplot(SP_AB, my_var)
 
  Hope this helps,
 
 So, in the above mentioned case, I could do something like:
 
 library(mapdata)
 commies - c(USSR, Mongolia) 
 # Mongolia was the 2nd communist country, in 1925
 map_poly_obj - map(worldHires, plot=FALSE)
 map_poly_commies - map(worldHires, commies,
   plot=FALSE, fill=TRUE)
 plot(map_poly_obj, type=l)
 polygon(map_poly_commies, col=red, border=black)
 
 I guess I can keep going, unless there is a simpler solution.
 
 Alberto Monteiro
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with map

2007-05-04 Thread Roger Bivand
On Fri, 4 May 2007, Alberto Monteiro wrote:

 I have just learned how to play with map, but something weird
 (or not) is happening.
 
 Suppose I want to draw a map of two countries (that have disconnected
 components), like Argentina and Brazil.
 
 If I command:
 
 library(maps)
 library(mapdata)
 map(worldHires, c(Argentina, Brazil))
 
 It works fine. However, if I want to _colour_ the interior:
 
 map(worldHires, c(Argentina, Brazil), c(cyan, green), fill=T)
 
 Then the colors will be assigned to the islands (Marajo in Brazil's
 North and Tierra del Fuego in Argentina's South) and there will be
 a recycling.
 
 Is there any way to associate one color to each country?

Try:

map_poly_obj - map(worldHires, c(Argentina, Brazil), plot=FALSE, 
  fill=TRUE)
str(map_poly_obj)

and you'll see that the component of interest is the named polygons, of
which there are 28, namely

map_poly_obj$names

So you can build a matching colours vector, or:

library(sp)
library(maptools)
IDs - sapply(strsplit(map_poly_obj$names, :), function(x) x[1])
SP_AB - map2SpatialPolygons(map_poly_obj, IDs=IDs, 
  proj4string=CRS(+proj=longlat +datum=wgs84))

but

plot(SP_AB, col=c(cyan, green))

still misses, because some polygons have their rings of coordinates in 
counter-clockwise order, so:

pl_new - lapply(slot(SP_AB, polygons), checkPolygonsHoles)
slot(SP_AB, polygons) - pl_new
# please forget the assignment to the slot and do not do it unless you can 
# replace what was there before

plot(SP_AB, col=c(cyan, green), axes=TRUE)

now works. Moreover, SP_AB is a SpatialPolygons object, which can be 
promoted to a SpatialPolygonsDataFrame object, for a data slot holding a 
data.frame with row names matching the Polygons ID values:

sapply(slot(SP_AB, polygons), function(x) slot(x, ID))

So adding a suitable data frame gets you to the lattice graphics method

spplot(SP_AB, my_var)

Hope this helps,

Roger

 
 Alberto Monteiro
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Off topic? Geographic data

2007-05-03 Thread Roger Bivand
On Thu, 3 May 2007, Alberto Vieira Ferreira Monteiro wrote:

 Sorry if this is off-topic, but since there are so many data sets in R,
 I wonder if there is any data set with Geographic data, like 
 (latitude,longitude) lists of the contour of the continents and
 countries.

Please see the Spatial Task View on CRAN. In general, position data is 
heavily protected outside the US, so that existing and available data is 
limited for other countries. The maps and mapdata packages have some 
databases, some of which are also up to date, but others still feature the 
Soviet Union and Yugoslavia, which is only of historical interest. 

There is an interface to more recent shorelines in the maptools package,
which will handle all the levels of detail in GSHHS. The CDC has a set of
shapefiles covering many countries with borders from about 1997, but sadly
these are restricted. Some enlightened countries are releasing data;
Canada has recently decided to do so: http://www.geogratis.gc.ca/, an
initiative other countries could with benefit follow. The US has by far
the most developed geographical data service sector, because the data are
free like beer but hard to use, creating opportunties for service
providers. Most of these data formats can be read by functions in maptools
or rgdal.

Roger

 
 Alberto Monteiro
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] intersect filled.contour and polygon

2007-05-01 Thread Roger Bivand
On Mon, 30 Apr 2007, Pedro Mardones wrote:

 Dear R users;
 
 Is there any way to intersect a filled contour image and a polygon? My
 problem is that I want to create a kriging map and the boundaries of
 my map are given by the coordinates of the polygon.
 
 So far I can superompose the polygon in the filled.contour image but I
 don't know how to get rid of the contour image outside of the polygon
 boundaries.

Two possibilities seem to be present: define your polygon as a hole inside 
the bounding box of the image, with a link between the polygon and the 
bounding box, and fill it; or, perhaps better, only make kriging 
predictions for the polygon. Since you haven't given a code example, it 
isn't obvious how you are making the kriging predictions, but the choice 
of the newdata locations ought to decide - and they do not need to be a 
full grid, or even a regular grid at all.

If you need to follow this up, please consider using the R-sig-geo list.

 
 Any hint will be appreciated
 PM
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Greek symbols in xtable rows

2007-04-29 Thread Roger Bivand
On Tue, 17 Apr 2007, James W. MacDonald wrote:

 Roger Bivand wrote:
 Andris Jankevics andza at osi.lv writes:
 
 
Thank You for answer. I Tried code that You provided in reply to my question 
on both PC's with Linux and Widows OS.

 
 Yes, I have also been bitten by the upgrade to xtable, which between 1.4-2 
 and 1.4-3 added code to try to be cleverer, but has broken output of LaTeX 
 markup directly. The offending code starts around line 177 in print.xtable.R 
 (#based on contribution from Jonathan Swinton jonathan at swintons.net in e-
 mail dated Wednesday, January 17, 2007). I did try to write a 
 sanitize.text.function= solution, but failed, and backed off to an earlier 
 version. Could the maintainer David Dahl, please address this, and include a 
 relevant test? (I would CC him, but am travelling and posting via gmane to 
 keep 
 thr thread together - I apologize for pruning, but gmane won't post 
 otherwise).
 
 So a solution is to install an earlier version of xtable from the package 
 archives, a harder but feasible task for Windows.

The solution is to use a workable sanitize.text.function.

  mat - diag(c($\\sigma_1^2$,$\\sigma_2^2$))
  tbl - xtable(mat)
  print.xtable(tbl, sanitize.text.function = function(x) x)
% latex table generated in R 2.5.0 by xtable 1.4-3 package
% Tue Apr 17 11:00:05 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
   \hline
   1  2 \\
   \hline
1  $\sigma_1^2$  0 \\
   2  0  $\sigma_2^2$ \\
\hline
\end{tabular}
\end{center}
\end{table}
---
But (sorry for the long delay):

 mat - diag(c($\\sigma_1^2$,$\\sigma_2^2$))
 colnames(mat) - c($\\sigma_1^2$,$\\sigma_2^2$)
 rownames(mat) - c($\\sigma_1^2$,$\\sigma_2^2$)
 tbl - xtable(mat)
 print.xtable(tbl, sanitize.text.function = function(x) x)
% latex table generated in R 2.5.0 by xtable 1.4-3 package
% Sun Apr 29 21:24:18 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
  \hline
  \$$\backslash$sigma\_1\verb|^|2\$  \$$\backslash$sigma\_2\verb|^|2\$ 
\\
  \hline
$\sigma_1^2$  $\sigma_1^2$  0 \\
  $\sigma_2^2$  0  $\sigma_2^2$ \\
   \hline
\end{tabular}
\end{center}
\end{table}
 

because sanitize() rather than sanitize.text.function() is used on the 
column names:

 sessionInfo()
R version 2.5.0 (2007-04-23) 
i686-pc-linux-gnu 

locale:
LC_CTYPE=en_GB;LC_NUMERIC=C;LC_TIME=en_GB;LC_COLLATE=en_GB;LC_MONETARY=en_GB;LC_MESSAGES=en_GB;LC_PAPER=en_GB;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods  
[7] base 

other attached packages:
 xtable   rgdal  lmtest zoo   spdep  Matrix 
1.4-3 0.5-90.9-19 1.3-0 0.4-2 0.9975-11 
latticebootmaptools foreign  sp tripack 
   0.15-41.2-270.6-110.8-200.9-131.2-10 

Roger

Best,

Jim




 
 Roger
 
 
 ...
 
 
Thank You,

Andris Jankevics

On Pirmdiena, 16. Aprīlis 2007 22:38, Charles C. Berry wrote:

On Mon, 16 Apr 2007, Andris Jankevics wrote:


mat - diag(c($\\sigma_1^2$,$\\sigma_2^2$))
xtable(mat)

 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
James W. MacDonald, M.S.
Biostatistician
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623

 
 **
 Electronic Mail is not secure, may not be read every day, and should not be 
 used for urgent or sensitive issues.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with saptial analysis (cluster)

2007-04-27 Thread Roger Bivand
ONKELINX, Thierry Thierry.ONKELINX at inbo.be writes:

 
 Dear Fransico,
 
 The distance matrix would be 102000 x 102000. So it would contain 1040400 
values. If you need one bit for
 each value, this would requier 9,7 GB. So the distance matrix won't fit in 
the RAM of your computer.

Perhaps you could make progress by using a 2D kernel density - there are 
functions among others in the MASS and splancs packages, or by binning - 
Bioconductor's hexbin package comes to mind. Then you would be looking for 
areas of increased density on the grid (in points per unit area or equivalently 
counts per bin) rather than at the interpoint distances. The kernel2d() 
function in splancs handles a data set of your size with no problems.

Roger

(with apologies for pruning, gmane is very dictatorial)

 
 Cheers,
 
 Thierry


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Greek symbols in xtable rows

2007-04-17 Thread Roger Bivand
On Tue, 17 Apr 2007, James W. MacDonald wrote:

 Roger Bivand wrote:
 Andris Jankevics andza at osi.lv writes:
 
 
Thank You for answer. I Tried code that You provided in reply to my question 
on both PC's with Linux and Widows OS.

On linux box output is:

 
 
 ...
 
 
System information:


sessionInfo ()

R version 2.4.0 (2006-10-03)
i686-redhat-linux-gnu

locale:
LC_CTYPE=lv_LV.UTF-8;LC_NUMERIC=C;LC_TIME=lv_LV.UTF-8;LC_COLLATE=lv_LV.UTF-
 
 8;LC_MONETARY=lv_LV.UTF-8;LC_MESSAGES=lv_LV.UTF-8;LC_PAPER=lv_LV.UTF-
 8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=lv_LV.UTF-
 8;LC_IDENTIFICATION=C
 
attached base packages:
[1] tcltk methods   stats graphics  grDevices utils
[7] datasets  base

other attached packages:
 xtable pls ellipse
1.4-3 1.2-1 0.3-2

And there is an output form my windows PC:


mat - diag (c($\\sigma_1^2,$\\sigma_2^2$))
xtable (mat)
 
 
 ... (replicates for me on same system)
 
 
sessionInfo ()

R version 2.4.1 (2006-12-18) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   
base 

other attached packages:
 xtable 
1.4-3 
 
 
 Yes, I have also been bitten by the upgrade to xtable, which between 1.4-2 
 and 1.4-3 added code to try to be cleverer, but has broken output of LaTeX 
 markup directly. The offending code starts around line 177 in print.xtable.R 
 (#based on contribution from Jonathan Swinton jonathan at swintons.net in e-
 mail dated Wednesday, January 17, 2007). I did try to write a 
 sanitize.text.function= solution, but failed, and backed off to an earlier 
 version. Could the maintainer David Dahl, please address this, and include a 
 relevant test? (I would CC him, but am travelling and posting via gmane to 
 keep 
 thr thread together - I apologize for pruning, but gmane won't post 
 otherwise).
 
 So a solution is to install an earlier version of xtable from the package 
 archives, a harder but feasible task for Windows.

The solution is to use a workable sanitize.text.function.

  mat - diag(c($\\sigma_1^2$,$\\sigma_2^2$))
  tbl - xtable(mat)
  print.xtable(tbl, sanitize.text.function = function(x) x)
% latex table generated in R 2.5.0 by xtable 1.4-3 package
% Tue Apr 17 11:00:05 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
   \hline
   1  2 \\
   \hline
1  $\sigma_1^2$  0 \\
   2  0  $\sigma_2^2$ \\
\hline
\end{tabular}
\end{center}
\end{table}

OK, thanks, I was trying too hard to be clever in my attempts. Now back to
many Rnw files to add the sanatize... functions ...

Roger

Best,

Jim




 
 Roger
 
 
 ...
 
 
Thank You,

Andris Jankevics

On Pirmdiena, 16. Aprīlis 2007 22:38, Charles C. Berry wrote:

On Mon, 16 Apr 2007, Andris Jankevics wrote:


mat - diag(c($\\sigma_1^2$,$\\sigma_2^2$))
xtable(mat)

 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
James W. MacDonald, M.S.
Biostatistician
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623

 
 **
 Electronic Mail is not secure, may not be read every day, and should not be 
 used for urgent or sensitive issues.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Greek symbols in xtable rows

2007-04-17 Thread Roger Bivand
Andris Jankevics andza at osi.lv writes:

 
 Thank You for answer. I Tried code that You provided in reply to my question 
 on both PC's with Linux and Widows OS.
 
 On linux box output is:
 

...

 
 System information:
 
  sessionInfo ()
 R version 2.4.0 (2006-10-03)
 i686-redhat-linux-gnu
 
 locale:
 LC_CTYPE=lv_LV.UTF-8;LC_NUMERIC=C;LC_TIME=lv_LV.UTF-8;LC_COLLATE=lv_LV.UTF-
8;LC_MONETARY=lv_LV.UTF-8;LC_MESSAGES=lv_LV.UTF-8;LC_PAPER=lv_LV.UTF-
8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=lv_LV.UTF-
8;LC_IDENTIFICATION=C
 
 attached base packages:
 [1] tcltk methods   stats graphics  grDevices utils
 [7] datasets  base
 
 other attached packages:
  xtable pls ellipse
 1.4-3 1.2-1 0.3-2
 
 And there is an output form my windows PC:
 
  mat - diag (c($\\sigma_1^2,$\\sigma_2^2$))
  xtable (mat)

... (replicates for me on same system)

  sessionInfo ()
 R version 2.4.1 (2006-12-18) 
 i386-pc-mingw32 
 
 locale:
 LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
 States.1252;LC_MONETARY=English_United 
 States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   
 base 
 
 other attached packages:
  xtable 
 1.4-3 

Yes, I have also been bitten by the upgrade to xtable, which between 1.4-2 
and 1.4-3 added code to try to be cleverer, but has broken output of LaTeX 
markup directly. The offending code starts around line 177 in print.xtable.R 
(#based on contribution from Jonathan Swinton jonathan at swintons.net in e-
mail dated Wednesday, January 17, 2007). I did try to write a 
sanitize.text.function= solution, but failed, and backed off to an earlier 
version. Could the maintainer David Dahl, please address this, and include a 
relevant test? (I would CC him, but am travelling and posting via gmane to keep 
thr thread together - I apologize for pruning, but gmane won't post otherwise).

So a solution is to install an earlier version of xtable from the package 
archives, a harder but feasible task for Windows.

Roger


...

 
 Thank You,
 
 Andris Jankevics
 
 On Pirmdiena, 16. Aprīlis 2007 22:38, Charles C. Berry wrote:
  On Mon, 16 Apr 2007, Andris Jankevics wrote:
 
   mat - diag(c($\\sigma_1^2$,$\\sigma_2^2$))
   xtable(mat)
 

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R Source Code

2007-04-13 Thread Roger Bivand
On Fri, 13 Apr 2007, Uwe Ligges wrote:

 Sione wrote:
  Dear Users,
  
  I am new to R, I have just downloaded it to play with. I am a Java   
  Matlab user, so I assume that it  wouldn't be a hurdle.  Where do I get 
  to see the source codes for R  sub-packages  ? I looked at those 
  sub-packages in folder  'R-ex'  for the source codes and they are 
  compressed files.  Do I mean to de-compress these files where the source 
  codes reside ?
 
 You can download the sources from CRAN.
 
 Uwe Ligges

Or even read the very clear advice in the Newsletter:

Uwe Ligges and Duncan Murdoch. R help desk: Accessing the sources. R News, 
6(4):43-45, October 2006.

 
 
  Any hint would be useful.
  
  Cheers,
  Sione.
  
  __
  [EMAIL PROTECTED] mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 __
 [EMAIL PROTECTED] mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] data encapsulation with classes

2007-04-08 Thread Roger Bivand
On Sun, 8 Apr 2007, Peter Williams wrote:

 Hi All,
 
 I'm new to R from a C and Octave/Matlab background.  I am trying to  
 construct some classes in R to which I want to attach pieces of data.
 First, is attr(obj, 'member name') - data the accepted way of doing  
 this?

No, it isn't. You seem to be trying to deduce new-style classes from a
representation used before R 2.4, but in any case it would not be
sensible. Please consult John M. Chambers. Programming with Data.
Springer, New York, 1998, and/or William N. Venables and Brian D. Ripley.
S Programming. Springer, New York, 2000, or for a shorter online resource:

http://www.stat.auckland.ac.nz/S-Workshop/Gentleman/Methods.pdf

 
 Second, having attached member data with attr is there anything wrong  
 with accessing it by the asperand (@), i.e.
 
   t = 
   attr(t, 'test') - 4
   [EMAIL PROTECTED]
 [1] 4
 
 I can't find any documentation on using the asperand to access  
 attributes like this.  I saw it in a piece of code as I was googling  
 around trying to find some information on attaching data to a class  
 in R.  Is this deprecated?  Is this poor form?  If anyone has some  
 suggestions please let me know.
 
 Thank you
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems loading package GeoXp

2007-04-05 Thread Roger Bivand
On Wed, 4 Apr 2007, Carlos Guerra wrote:

 Dear useR's,
 I wanted to load the package GeoXP in my computer but I couldn't because 
 this warning message appeared:
 
   require(GeoXp)
 Carregando pacotes exigidos: GeoXp
 Carregando pacotes exigidos: tcltk
 Loading Tcl/Tk interface ... Erro em fun(...) : couldn't connect to 
 display :0

The problem seems not to be GeoXp, but rather that your installation does 
not have a working tcltk/X11 setup. Can you check that your tcltk works, 
for example using it in update.packages()? Are you perhaps installing 
GeoXp on a server with no X11 rather than a workstation?


 Além disso: Warning message:
 pacote 'GeoXp' foi compilado na versão do R 2.4.1
 Erro: .onLoad falhou em 'loadNamespace' para 'tcltk'
 Erro: pacote 'tcltk' não pôde ser carregado
 
 Can this package only be used under Windows??

No, it works on Linux workstations.

 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] gpclib library

2007-04-05 Thread Roger Bivand
On Thu, 5 Apr 2007, Leonardo Lami wrote:

 
 Hi
 my OS is Linux Debian distribution, my R vers is 2.4.0 Patched
 (2006-11-25 r39997)
 
 I tried several repositories but the output is ever the same

Please do not write to the author of the original non-R-project C code -
the package maintainer is the appropriate person. Your R version is now
out of date, and you may be caught by the current package depending on R
2.4.1 (that is probably why you got the not found message). If you can't
upgrade R to match gpclib, consider an older version of the package source
pre-dating R 2.4.1, such as:

http://cran.r-project.org/src/contrib/Archive/G/gpclib_1.3-3.tar.gz

 
 Thank yor for your help
 
 All the best
 Leonardo
 
 
 Prof Brian Ripley ha scritto:
  It's a _package_ that you are looking for (there is something else
  called a gpclib library, to do with GNU Pascal).
 
  You haven't told us your OS or R version, so we don't know what file
  you are looking for.  But try another mirror if one appears not to
  work (and using a US mirror with an email address in Italy seems odd).
  On Wed, 4 Apr 2007, Leonardo Lami wrote:
 
  Hi all,
  I'm tring to download the gpclib library but I don't find it in the old
  repository
 
  install.packages(c(gpclib), dependencies=TRUE,
  repos=http://cran.cnr.berkeley.edu/;)
  Avviso in install.packages(c(gpclib), dependencies = TRUE, repos =
  http://cran.cnr.berkeley.edu/;) :
  argument 'lib' is missing: using /usr/local/lib/R/site-library
 
  That's not what that message says: presumably you got some more output.
 
 
 
  May be my old library have some problem:
 
  library(gpclib)
  Errore in loadNamespace(package, c(which.lib.loc, lib.loc), keep.source
  = keep.source) :
 in 'gpclib', metodi da esportare specificati, ma nessuno
  definito: show, get.bbox, plot, intersect, union, setdiff, [,
  append.poly, scale.poly, area.poly, get.pts, coerce
  Errore: caricamento pacchetto/namespace fallito per 'gpclib'
 
  Someone knows where I can find the library
 
  Thank you
  Leonardo
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to image.plot a XY grid file into a lat-lon map

2007-04-05 Thread Roger Bivand
On Thu, 5 Apr 2007, Vladimir Eremeev wrote:

 
 If your country or state borders are polygons or polylines, you could
 convert them to desired projection using the function project from the
 package rgdal.
 
 Latitude-longitude grid also could be added by generating desired
 polylines in lat-lon and converting them to the desired projection using
 project.
 

Yes, the route would be to plot the image in its native projection, and
project the vector data (shorelines, countries) to the same projection.  
Similar topics have been discussed on the R-sig-geo list, including the
reading of netcdf files (which are a bit picky) with functions in the
rgdal package which import the coordinate reference system directly.

Please follow this up on R-sig-geo if you need more help.

 
 Linda Smith wrote:
  
  I have a netcdf gridded file with LCC projection. I can easily use
  image.plot to visualize it. However, as the axises are in X,Y, not Lat and
  Lon, I could not add state or country maps onto it (or lat lon
  information).
  I do have a grid2d file that describes the lat and lon for each (X,Y)
  grid,
  but the lat and lon are not regularly spaced, so I could not use
  image.plot.
  
  Does anyone know how to plot this type of gridded data so that country or
  state borders can be easily added? Thanks a lot!
  
 
 What do you mean by grid2d file that describes the lat and lon for each
 (X,Y) grid?
 If this are two rasters of the same size having corresponding latitude and
 longitude values in each raster cell, then you could use contourLines to get
 lat-lon grid. However, you, probably, will want to smooth it.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Info on SPATSTAT window and maps

2007-04-04 Thread Roger Bivand
On Wed, 4 Apr 2007, Giuseppe Brundu wrote:

 I wonder if there is any tutorial explaining, step by step, how to convert a 
 (georeferenced) map boundary (from esri shape-file) into a Spatstat window, 
 for performing the analysis of marked point patterns surveyed inside that 
 map. Any help on the subject will be really appreciated.

Doing RSiteSearch(shapefile owin) shows that this is possible. The 
current route is:

library(spatstat)
library(maptools)
your_sp - readShapePoly(your.shp)
your_sp1 - as(your_sp, SpatialPolygons)
your_owin - as(your_sp1, owin)
plot(your_owin)
pp - runifpoint(500, your_owin) 

but you may need extra steps, for example to merge polygons or to remove
small polygon artefacts. Other functions in maptools would let you create
a ppp object from a SpatialPointsDataFrame, if you need that too.

You might also consider looking at the R-sig-Geo list for questions of 
this kind.

 
 Giuseppe Brundu
 
 (University of Sassari, Italy)
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] confine a dataframe with a polygon

2007-04-03 Thread Roger Bivand
On Tue, 3 Apr 2007, temiz wrote:

 hello
 
 how can I confine a dataframe with a known polygon that is part of whole 
 data ?

Could I suggest following up this question on the R-sig-geo list? It is 
not clear what you want to do - are the rows in the data frame points 
which may lie inside or outside a polygon? If so, the overlay() methods in 
the sp package may be suitable.

 
 regards
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Trouble installing package 'sp' in R 2.4.1

2007-03-30 Thread Roger Bivand
On Fri, 30 Mar 2007, Duncan Murdoch wrote:

 On 3/30/2007 2:39 PM, Gaurav Ghosh wrote:
  Hi all,
  
  I just installed R 2.4.1 and tried to install the package 'sp' working down 
  from the 'Packages' menu in the R GUI.  The package would not install and I 
  got the following message:
  
  quot;trying URL 
  'http://cran.us.r-project.org/bin/windows/contrib/2.4/sp_0.9-10.zip'
  Error in download.file(url, destfile, method, mode = quot;wbquot;) : 
  cannot open URL 
  'http://cran.us.r-project.org/bin/windows/contrib/2.4/sp_0.9-10.zip'
  In addition: Warning message:
  cannot open: HTTP status was '404 Not Found' 
  Warning in download.packages(pkgs, destdir = tmpd, available = available,  
  : 
   download of package 'sp' failedquot;
  
  I tried to find the installation file quot;sp_0.9-10.zipquot; through the 
  CRAN website, but was unable to do so.  So I was wondering if there was 
  some other way to get this package I need.  Or perhaps  there might be some 
  problem with the website itself.
 
 
 You didn't say which mirror you were using, but it looks like a problem 
 there.  I just tried from one of the Canadian mirrors and there was no 
 problem finding the package.

From HTTP, the mirror mentioned inline http://cran.us.r-project.org/ has 
problems, is well behind on versions in the project pages, and

http://cran.us.r-project.org/bin/windows/contrib/2.4/

has no sp package at all. The last check summary is dated 2007-03-16.

Please try another mirror; if anyone could find out what is the matter 
with the mirror, and get it corrected, that would be welcome.

 
 Duncan Murdoch
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] order of values in vector

2007-03-19 Thread Roger Bivand
On Mon, 19 Mar 2007, Tord Snäll wrote:

 Dear all,
 I would like to get the order of the values in a vector. I have tried 
 rank(), order() and searched the archive, though without success.
 
 Here is an example of a try
 x= c(20,30,50,40,60,10)
 cbind(sort.list(x),x)
 x
 [1,] 6 20
 [2,] 1 30
 [3,] 2 50
 [4,] 4 40
 [5,] 3 60
 [6,] 5 10
 but I was hoping to get this:
 x
 [1,] 2 20
 [2,] 3 30
 [3,] 5 50
 [4,] 4 40
 [5,] 6 60
 [6,] 1 10

 cbind(rank(x), x)
x
[1,] 2 20
[2,] 3 30
[3,] 5 50
[4,] 4 40
[5,] 6 60
[6,] 1 10


 
 I'm most grateful for a tip!
 
 cheers,
 Tord
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] character to numeric conversion

2007-03-19 Thread Roger Bivand
On Mon, 19 Mar 2007, Robin Hankin wrote:

 Hello everybody
 
 thanks for the tips.
 
 I *think* this should be the same thread
 
 
 The manpage for system() says that lines of over 8095
 characters will be split.  This is causing me problems.
 How do I get round the 8095 character limit?
 

Can you use sed or awk in a pipe externally to change ,  into \n while
still out in the system() call, for example the record separator RS in
awk?

 
 Simple toy example follows:
 
 
 
 jj - system(echo 4 | awk '{for(i=1;i100;i++){printf(\%s,\, 
 $1)}}'| sed -e \s/,$//\,intern=T)
 
 
 This is  fine.  But .. . .
 
 
 jj - system(echo 4 | awk '{for(i=1;i1;i++){printf(\%s,\, 
 $1)}}'| sed -e \s/,$//\,intern=T)
 
 
 
 has  jj  split into three bits, which is upsetting my call.  In my  
 application
 the split occurs in the middle of a multi-digit number, which messes up
 my conversion to numeric?
 
 
 
 
 
 
 
 --
 Robin Hankin
 Uncertainty Analyst
 National Oceanography Centre, Southampton
 European Way, Southampton SO14 3ZH, UK
   tel  023-8059-7743
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] An example of overloading [

2007-03-13 Thread Roger Bivand
On Mon, 12 Mar 2007, Sender wrote:

 Any insight as to why this is printing twice?

Try:

m - NA
class(m) - mydist
m[]
res - m[]
res

(hint - print.default() is returning what it was asked to print, which 
then gets printed again automatically)

 
 [.mydist - function(x,...){
 print(I called my function)
 }
 
 m - a_mydist_obj
 m[]
 
 I called my function
 I called my function
 
 
 
 
 On 3/12/07, Sender [EMAIL PROTECTED] wrote:
 
  Super. Thanks for the leads.
 
  On 3/12/07, Marc Schwartz [EMAIL PROTECTED] wrote:
  
   On Mon, 2007-03-12 at 21:28 -0700, Sender wrote:
Hello:
   
Could anyone point me to a nice example where someone has created
   methods
for [ on a user defined Class?
   
I looked at the package Matrix but that was a little daunting. I'm
   looking
for someone a little more introductory. I've tried to search the help
section and the web but its difficult since [ isn't searchable.
   
Thanks in advance!
   
Greg
  
   You might want to look at this thread from last year:
  
 http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77057.html
  
  http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77060.html
  
 http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77059.html
  
  http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77102.html
  
  
   You can also review the existing methods defined for '[' in your current
   installation by using:
  
 methods([)
  
   It may be easiest to then review the code for a given method by using
   something like the following as an example:
  
 getAnywhere([.data.frame)
  
  
   BTW, for searching the R help files, REGEX's are used, so for [, you
   would need:
  
 help.search (\\[)
  
   since '[' is a special character in regular expressions and you need to
   escape it to search on the literal character. In R, you need to double
   the '\' to be interpreted properly.
  
   HTH,
  
   Marc Schwartz
  
  
  
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] convert pixels into axis coordinates in R

2007-03-12 Thread Roger Bivand
On Mon, 12 Mar 2007, Peter Stencel wrote:

 Dear R users,
 
 I've two questions:
 
 1) Does anybody have a clue how to convert pixel from a jpeg graphic
 (e.g. something like a square of 100x100 pxs)  into axis coordinate
 values in R?

The posting guide suggests providing enough code for reproducing a problem 
- your question is not specific enough. If the jpeg is just an image, 
maybe something in the rimage package, or the Bioconductor EBImage 
package, or for geospatial, see the rgdal package. The pixmap package can 
do this too, but without more detail and code examples, it's difficult to 
tell.

 
 2) Is there any possibility to extend the R locator function in a way
 that locator( ) outputs all coordinates from a plot at once, without
 clicking on the graph?
 

You are free to make a version for yourself, if that is what you really 
want.

 Thanks for any hint.
 
 Regards,
 P. Stencel
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Analysis of 3-dimensional spatial point patterns

2007-03-12 Thread Roger Bivand
On Mon, 12 Mar 2007 [EMAIL PROTECTED] wrote:

 I am trying to determine how to evaluate homogeneity of points in 
 three-dimensional space.
 
 In two-dimensional data, I have used functions available in the Spatial 
 package
 and I've have looked into the spatstat package
 but, as far as I can tell, neither appears to handle 3-dimensional 
 data.
 
 Is there another version, package, or software that does the same type 
 (G-function, etc.) of evaluation for 3-D data?

I believe that you are correct with regard to spatial, spatstat, and 
splancs. For G, it would be possible to get most of the way there using an 
off-CRAN package interfacing David Mount's Approximate Nearest Neighbours 
code that I can make available (depending on your platform), substantially 
improved thanks to Christian Sangiorgio.

 set.seed(1)
 library(ann)
 D3 - matrix(runif(3000), ncol=3) 
 res - ann(D3)$dnn
 quantile(res, seq(0,1,1/10))
 plot(ecdf(res))

The real difficulties would start with edge adjustment, sampling within a 
volume for simulation ought to be OK, at least for a cube.

Roger

 
 Thanks sincerely,
  Tom Filloon   [Procter  Gamble, Cincinnati, Ohio USA]
 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using large datasets: can I overload the subscript operator?

2007-03-09 Thread Roger Bivand
On Sat, 10 Mar 2007, Maciej Radziejewski wrote:

 Hello,
 

The http://www.met.rdg.ac.uk/cag/rclim/ site may have some useful leads. 
In addition, you'll find ideas in two packages created by Tim Keitt, 
rgdal, and Rdbi+RdbiPgSQL (now on Bioconductor). 

 I do some computations on datasets that come from climate models. These data
 are huge arrays, significantly larger than typically available RAM, so they
 have to be accessed row-by-row, or rather slice-by slice, depending on the
 task. I would like to make an R package to easily access such datasets
 within R. The C++ backend is ready and being used under Windows/.Net/Visual
 Basic, but I have yet to learn the specifics of R programming to make a good
 R interface.

Look at the Matrix package for examples - you may need finalizers to tidy 
up memory allocation - see examples in rgdal. The key thing will be 
thinking through how to implement the R objects as classes, probably not 
simply reflecting the C++ classes. Classes are covered in the Green Book 
(Chambers 1998) and Venables  Ripley (2000) S Programming.

 
 I think it should be possible to make a package (call it slice) that could
 be used like this:
 
 library (slice)
 dataset - load.virtualarray (dataset_definition.xml)
 ordinaryvector - dataset [ , 2, 3] # Load a portion of the data from disk
 and extract it
 
 In the above dataset is an object that holds a definition of a
 3-dimensional large dataset, and ordinaryvector is an ordinary R vector.
 The subscripting operator fetches necessary data from disk and extracts a
 required slice, taking care of caching and other technical details. So, my
 questions are:
 
 Has anyone ever made a similar extension, with virtual (lazy) arrays?
 
 Can the suscript operator be overloaded like that in R? (I know it can be in
 S, at least for vectors.)
 

Yes, there are many examples, see the Matrix package for some that use 
new-style classes (in language issues like this, R is S, the differences 
are in scoping).

 And a tough one: is it possible to make an expression like [1] (without
 quoutes) meaningful in R? At the moment it results in a syntax error. I
 would like to make it return an object of a special class that gets
 interpreted when subscripting my virtual array as drop this dimension,
 like this:

Most likely not in this context, because [ in this context will not be
what you want. But if your [.dataset method is careful about examining
its arguments, you ought to be able to get the result you want. You'll
likely learn a good deal from looking for example at the code in the
Matrix package.

 
 dataset [, 2, 3, drop = F]  # Return a 3-dimensional array
 dataset [, [2], 3, drop = F]  # Return a 2-dimensional array
 dataset [, [2], [3], drop = F]  # Return a 1-dimensional array, like dataset
 [, 2, 3]
 
 Thanks in advance for any help,
 
 Maciej.
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] .C HoltWinters

2007-02-28 Thread Roger Bivand
On Tue, 27 Feb 2007, sj wrote:

 Hello,
 
 I would like to look at the compiled C code behind HoltWinters from the
 stats package. Is that possible? If so where do I find it?

Please see the R help desk note in R News 6(4): 43-45, October 2006, by 
Uwe Ligges and Duncan Murdoch: Accessing the sources for full details.

In this case, you can browse the SVN trunk (current development version) 
at:

https://svn.r-project.org/R/trunk/src/library/stats/src/HoltWinters.c

 
 thanks,
 
 Spencer
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] map population density

2007-02-28 Thread Roger Bivand
On Wed, 28 Feb 2007, Barbara Diane-Spillmann wrote:

 dear all,
 
 i?m trying to plot a map of population density in german communities by 
 using shape files.
 to plot the polygons is not the problem but as soon as I want to add the 
 population data to the map I get the following message:
 
 Fehler in if (attr(theMap$Shapes[[ii]], nParts) == 1) { :
 Argument hat Länge 0
 
 My population data are either in form of a csv file or a column of the 
 dbf file. either possibility gives me the message above.
 what does R want to tell me?

I assume that you are using read.shape() from the maptools package,
followed by plot.Map(), a deprecated function from the same package. It is
possible that you also have a poorly written command, which you have not
shown. If your second argument was not named explicitly, and is assumed to
be recs, mahem may break loose (and has here - function most likely
looking for out-of-range geometries indexed by population numbers).

The currently recommended approach is to read your shapefile into an 
object specifically designed to keep the geometries and their attribute 
data correctly associated. The function readShapePoly() in maptools will 
do this. The plot method for the object you read will by default only show 
the boundaries, but if you are willing to use lattice graphics, you can 
get there in two lines:

x - readShapePoly(my_file.shp)
spplot(x, chosen_column_name)

for variable chosen_column_name in the shapefile DBF.

You can also use base graphics, but then need to pass a vector of colours 
through the col= argument, usually by look-up in a short vector of colours 
indexed by findInterval() on the variable of interest.

Please consider posting follow-ups to the R-sig-geo list, which is more 
focussed.


 
 thank you for your help
 
 barbara
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RDA and trend surface regression

2007-02-27 Thread Roger Bivand
 as formula operators:
  
  rda(Helling ~ x + y + I(x*y) + I(x^2) + I(y^2) + I(x*y^2) + I(y*x^2) +
  I(x^3) + I(y^3))
  
  If you don't have the interaction terms, then it is easier and better
  (numerically) to use poly():
  
  rda(Helling ~ poly(x, 3) + poly(y, 3))
  
  Another issue is that in my opinion using polynomial constraints is an
  Extremely Bad Idea(TM).
  
  cheers, Jari Oksanen
  
  --
  LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}
  
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Spatial error model estimation

2007-02-22 Thread Roger Bivand
On Thu, 22 Feb 2007, Dong GUO wrote:

 Greetings to the list,
 
 I was trying to estimate spatial error model in R, somehow I got the
 message below. Would you please help me with it? Many thanks in
 advance.
 
 Error in solve.default(asyvar, tol = tol.solve) :
   system is computationally singular: reciprocal condition number = 
 5.6964e-18

(This refers to function errorsarlm() in package spdep)

Please see ?errorsarlm, the problem is explained there as follows:

tol.solve: the tolerance for detecting linear dependencies in the
  columns of matrices to be inverted - passed to 'solve()'
  (default=1.0e-10). This may be used if necessary to extract
  coefficient standard errors (for instance lowering to 1e-12),
  but errors in 'solve()' may constitute indications of poorly
  scaled variables: if the variables have scales differing much
  from the autoregressive coefficient, the values in this
  matrix may be very different in scale, and inverting such a
  matrix is analytically possible by definition, but
  numerically unstable; rescaling the RHS variables alleviates
  this better than setting tol.solve to a very small value.



 
 
 Regards,
 Dong
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] random uniform sample of points on an ellipsoid (e.g. WGS84)

2007-02-22 Thread Roger Bivand
On 21 Feb 2007, Russell Senior wrote:

 
 I am interested in making a random sample from a uniform distribution
 of points over the surface of the earth, using the WGS84 ellipsoid as
 a model for the earth.  I know how to do this for a sphere, but would
 like to do better.  I can supply random numbers, want latitude
 longitude pairs out.
 
 Can anyone point me at a solution?  Thanks very much.
 

http://www.csit.fsu.edu/~burkardt/f_src/random_data/random_data.html

looks promising, untried.



 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to print a double quote

2007-02-22 Thread Roger Bivand
On Thu, 22 Feb 2007, Bos, Roger wrote:

 Can anyone tell me how to get R to include a double quote in the middle
 of a character string?  

FAQ 7.37 Why does backslash behave strangely inside strings?

 
 For example, the following code is close:
 
  fnd-Open fnd 'test'
 cat(fnd)
 Open fnd 'test'
 
 
 But instead of Open fnd 'test' I need: Open fnd test.  Difference
 seems minor, but I am writing batch files for another program to read in
 and it has to have the double quotes to work.  
 
 Thanks in advance for any help or ideas,
 
 Roger
 
 ** * 
 This message is for the named person's use only. It may 
 contain confidential, proprietary or legally privileged 
 information. No right to confidential or privileged treatment 
 of this message is waived or lost by any error in 
 transmission. If you have received this message in error, 
 please immediately notify the sender by e-mail, 
 delete the message and all copies from your system and destroy 
 any hard copies. You must not, directly or indirectly, use, 
 disclose, distribute, print or copy any part of this message 
 if you are not the intended recipient.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reading Post-Script files

2007-02-20 Thread Roger Bivand
On Tue, 20 Feb 2007, Ralf Finne wrote:

 Hi everybody!
 Is there any way to read a postscrit file into R?

See http://www.r-project.org/useR-2006/Slides/Murrell.pdf

page 4, the grImport package, now on CRAN, with further notes on Paul 
Murrell's home page:

http://www.stat.auckland.ac.nz/~paul/

 
 All the best to you
 Ralf Finne
 SYH University of Applied Sciences
 Vasa Finland
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Google, hard disc drives and R

2007-02-19 Thread Roger Bivand
On Mon, 19 Feb 2007, Ben Bolker wrote:

 Tim Churches tchur at optushome.com.au writes:
 
  
  A recent paper from Google Labs, interesting in many respects, not the
  least the exclusive use of R for data analysis and graphics (alas not
  cited in the approved manner):
  
  http://labs.google.com/papers/disk_failures.pdf
  
  Perhaps some of the eminences grises of the R Foundation could prevail
  upon Google to make some the data reported in the paper available for
  inclusion in an R library or two, for pedagogical purposes?
  
  Tim C
  
 
After skimming the paper, I can't help wondering why
 they used barplots with error bars instead of boxplots,
 and why they broke the data into discrete age groups?
 Given that they had a relatively large data set
 (several percent of 100,000 disk drives), they could
 have done some cool visualization stuff ...

For example Mondrian via RServe?

 
   Ben Bolker
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] count sequence of integers

2007-02-15 Thread Roger Bivand
On Thu, 15 Feb 2007, Samuel Kemp wrote:

 Hi,
 
 I would like to be able to count a sequence of numbers. For example, given a
 vector of the following integers
 
 (1,1,1,2,2,2,2,3,3,3,3,3,3,1,1,1,1, 3,3)
 
 the function would return
 
 (3, 4, 6, 4,2)

?rle

 x - c(1,1,1,2,2,2,2,3,3,3,3,3,3,1,1,1,1, 3,3)
 rle(x)$lengths
[1] 3 4 6 4 2

 
 Does anyone have any cool ideas to solve this?
 
 Any help appreciated.
 
 Regards,
 
 Sam.
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Polygon triangulation?

2007-02-13 Thread Roger Bivand
On Tue, 13 Feb 2007, ONKELINX, Thierry wrote:

 Have you tried the tri-package?

Perhaps the GPC C library used in the gpclib package, and in PBSmapping 
will get closer - it partitions polygons into tristrip sets.

 
 Cheers,
 
 Thierry
 
 
 
 
 ir. Thierry Onkelinx
 Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
 and Forest
 Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
 methodology and quality assurance
 Gaverstraat 4
 9500 Geraardsbergen
 Belgium
 tel. + 32 54/436 185
 [EMAIL PROTECTED]
 www.inbo.be 
  
 
 Do not put your faith in what statistics say until you have carefully
 considered what they do not say.  ~William W. Watt
 A statistical analysis, properly conducted, is a delicate dissection of
 uncertainties, a surgery of suppositions. ~M.J.Moroney
 
 -Oorspronkelijk bericht-
 Van: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Namens Duncan Murdoch
 Verzonden: dinsdag 13 februari 2007 15:27
 Aan: r-help@stat.math.ethz.ch
 Onderwerp: [R] Polygon triangulation?
 
 Can anyone point me to a package that contains code to triangulate a 
 polygon?  This is easy if the polygon is convex, but tricky if not.  One
 
 algorithm to do it is due to Meister, and is described here:
 
 www.math.gatech.edu/~randall/AlgsF06/planartri.pdf
 
 Duncan Murdoch
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Diffrerence in %in% function to boundry setting via

2007-02-08 Thread Roger Bivand
On Thu, 8 Feb 2007, Benjamin Otto wrote:

A version of FAQ 7.31 Why doesn't R think these numbers are equal?

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

 ps - seq(-0.502,0.378,by=0.001)
 ps[494]
[1] -0.009
 print(ps[494], digits=16)
[1] -0.009008
 all.equal(ps[494], -0.009)
[1] TRUE


 Hi,
 
 There is a point which is irritating me currently quite a bit and that is an
 aspect of different behaviour between the %in% function and the
 smaller/bigger than signs (). Here is are two examples to demonstrate what
 I mean:
 
 Example1:
  c(1,1,2,2,3,4,4,6,7) %in% c(1,2,3)
 [1]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
 
 Right, that is what I expect.
 
 Example2:
  ps - seq(-0.502,0.378,by=0.001)
  ps[494]
 [1] -0.009
 
  class(ps[494])
 [1] numeric
  class(-0.009)
 [1] numeric
  class(ps[494])
 [1] numeric
 
  ps[494] == -0.009
 [1] FALSE
  ps[494] %in% -0.009
 [1] FALSE
  ps[494] == c(-0.009)
 [1] FALSE
  ps[494] %in% c(-0.009)
 [1] FALSE
  ps[494] = -0.008
 [1] TRUE
  ps[494] = -0.010
 [1] TRUE
  -0.009 == -0.009
 [1] TRUE
 
 BUT: 
  ps[249]
 [1] -0.254
  class(ps[249])
 [1] numeric
  ps[249] %in% -0.254
 [1] TRUE
 
 OK! Can sombody explain to me what is happening here? Honestly? I don't
 understand where the difference but it's critical! Because obviuosly when I
 have a set of numeric values (ALL have three digits) and to boundry values
 lb/up, a lower and an upper boundry, I could (from what I thought until now)
 chosse between:
 
 Version1:
  small.set - set[set %in% seq(lb,up,by=0.001)]
 
 Version2:
  small.set - set[set = lb  set = up]
 
 Unfortunately with my data I used I got around 8000 values from my set with
 version1 but about 24000 with version2. IS there some main diffrence I
 didn't take into account or is my system just behaving irrational (that's
 what I think if you look at Example2)?
 
 I checked the behaviour under R-2.4.1 (Windows) and under 2.2.1 (Linux). The
 result was the same.
 
 Sincere regards
 
 Benjamin Otto 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Running source from Unix line

2007-02-08 Thread Roger Bivand
On Thu, 8 Feb 2007, Amir Herman wrote:

 
 How can I run something like source(filename) from the Unix command line?
 Maybe somthing like ./R CMD source(filename) - this does not work.
 
 I need to run an R source code file with a command from the Unix command
 line.
 assuming that I have R installed on my system.

Appendix B of manual An Introduction to R:

http://cran.r-project.org/doc/manuals/R-intro.html#Invoking-R-from-the-command-line

is helpful, or see ?Startup, or google littler R script. For the time 
being, think echo 'source(filename)' | R [options], or cat filename | R

 
 Thank you all
 Amir.
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Scope

2007-02-08 Thread Roger Bivand
On Thu, 8 Feb 2007, Gabor Grothendieck wrote:

 You can assign the environment within main to a variable in
 the global environment and that will make it accessible even
 after main terminates:

Indeed, it can be done, but unless the original questioner is already 
expert at handling scopes and environments, this is an easy way to get 
muddled. Functions take arguments and return values, so putting the output 
into a suitable object and assigning that object:

cars_lm - lm(dist ~ speed, data=cars)

is robust, easy to grasp, and in particular easy to debug. Thinking
through the design of the output object is usually helpful. Assigning to
the global environment will overwrite objects unless one is careful, and
even with years of experience only seems worth considering when no
feasible alternative exists; on consideration, alternatives usually
appear.

 
 main - function() {
  assign(main.env, environment(), .GlobalEnv)
  x - 1; y - 2
 }
 
 main()
 main.env$x
 main.env$y
 # or
 attach(main.env)
 search()  # note that main.env is on search path
 x
 y
 detach()  # remove from path now that we are finished
 
 
 Alternately you could assign each variable within main
 that you want to save:
 
 main - function() {
  x - 1; y - 2
  assign(x, x, .GlobalEnv)
  assign(y, y, .GlobalEnv)
 }
 
 main()
 x
 y
 
 
 
 On 2/8/07, Geoffrey Zhu [EMAIL PROTECTED] wrote:
  Hi all,
 
  When I write a script, I'd like to create a main() function so that I
  only need to type main() t re-run it. However, I'd like all the
  variables in main() to be global so that when the function terminates, I
  still have access to the variables in the environment. Does anyone know
  how to do that?
 
  Best regards,
  Geoffrey
 
 
 
  ___=0A=
  =0A=
  =0A=
  The information in this email or in any file attached hereto...{{dropped}}
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about compile the R 2.4.1 sources

2007-02-07 Thread Roger Bivand
On Wed, 7 Feb 2007, xiaopeng hu wrote:

 When I run ./configure ,I got the message:
 configure: WARNING: you cannot build info or html versions of the R manuals.
 
 What's the matter?

Search for info in the R Installation and Administration manual:

http://cran.r-project.org/doc/manuals/R-admin.html

You will not be able to build the info files unless you have makeinfo 
version 4.7 or later installed.

Reading the manual usually helps - saying what platform you are trying to 
build on also helps, here the platform will guide you to the appropriate 
sections of the manual. I expect that you will usually want access to 
these formats of the help pages.



 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to do moran's I test?

2007-02-06 Thread Roger Bivand
On Tue, 6 Feb 2007, Jian Zhang wrote:

 I want to do moran's I test in R language. I try to use gearymoran in
 Package ade4,moran in Package spdep, and Moran.I in Package ape. But
 I do not know how to do it because data format is different.

Please consider posting on the R-sig-geo mailing list. If you are an 
ecologist, you may find the off-CRAN ncf package by Ottar Bjørnstad more 
intuitive - see the correlog function:

http://asi23.ent.psu.edu/onb1/software.html

 
 My data:
 
 xy   dbh   
 
   111.0310.7   7
 
   118.110.28 1.2
 
   165.360.36 8.4
 
282.9 0.3 7.5
 
   303.29   13.3212.2
 
   319.283.88 6.2
 
  447   9   6
 
445.518.313.8
 
445.512.1 7.1
 
   467.64 1.2 4.7
 
485.414.1 4.4
 
 2.98   23.9511.7
 
   15   35.7823.5
 
   130.2123.614.1
 
213.5   23.2221.5
 
   233.57   28.7635.4
 
482.320.5   6
 
69.73   45.21 7.5
 
 69.8   50.4910.2
 
76.6545.521.5 
 
  
 
 x,y are spatial coordinate;
 
 dbh is variable
 
 I want to test the spatial autocorrelation of dbh in different distances
 by x and y.
 
  
 
 Thanks,
 
 Jian Zhang
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] writing a fomated matrix

2007-02-05 Thread Roger Bivand
On Mon, 5 Feb 2007, Milton Cezar Ribeiro wrote:

 Hi R-gurus,
 
 I have a 1000x1000 matrix and I would like to write it in a ASC file,
 where each row from my matrix are written in a separated line. I tryed
 write() function, but it don´t work fine to me.

RSiteSearch(write matrix, restrict = c(functions, docs))

takes you to:

library(MASS)
?write.matrix

which ought to get you there. But:

?write

would also have shown that there is an ncolumns argument - using that 
would probably also help.

 
 any idea?
 
 Kind regards,
 
 Miltinho
 
 __
 
 
   [[alternative HTML version deleted]]
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems installing R-2.4.1 on Solaris 11 x-86 from source: error in gmake after successful configure]

2007-02-05 Thread Roger Bivand
On Mon, 5 Feb 2007, Octavio Tourinho wrote:

 Dear friends,
 I am trying to install R-2.4.1 from source on Solaris 11 x-86_64. 
 running on Sun Ultra-20 workstation, and using the SunStudio 11 compilers.
 
 I was able to configure R correctly, but received an error in make, 
 aparently related to bzip2 which I have been unable to debug.
 The messages are listed below.
 The configure.log and configure.site and teh terminal output with the 
 error message files are attached.

If you read your site settings *carefully*, you will see that at least 
some are not prefaced by tag=. They will then not be recognised and 
inserted where needed, leading to chaos. Please go through your site 
settings once again and correct them. Here is an example that just will 
not work:

## Header file search directory ('-IDIR') and any other miscellaneous
## options (such as defines) for the C preprocessor and compiler.
## If unset defaults to '-I/usr/local/include', with '-I/sw/include'
## prepended on systems using Fink with root '/sw'.
## CPPFLAGS=-I/usr/local/include -I/usr/local/include/readline
-I/usr/sfw/include 

but you also have:

## The command which runs the C++ compiler.  It not specified, configure
## uses the values of the environment variables 'CXX' or 'CCC' if set,
## and then looks under the names 'c++', 'g++', 'gcc', 'CC', 'cxx', and
## 'cc++' (in that order).
CXX=/opt/SUNWspro/bin/CC -xarch=amd64



 
 Any help would be sincerely appreciated, as I have exausted my debugging 
 resources.  I believe that there is a problem with the configure script 
 in dealing with my particular setup.
 
 Octavio Tourinho
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems installing R-2.4.1 on Solaris 11 x-86 from source: error in gmake after successful configure]

2007-02-05 Thread Roger Bivand
On Mon, 5 Feb 2007, Roger Bivand wrote:

 On Mon, 5 Feb 2007, Octavio Tourinho wrote:
 
  Dear friends,
  I am trying to install R-2.4.1 from source on Solaris 11 x-86_64. 
  running on Sun Ultra-20 workstation, and using the SunStudio 11 compilers.
  
  I was able to configure R correctly, but received an error in make, 
  aparently related to bzip2 which I have been unable to debug.
  The messages are listed below.
  The configure.log and configure.site and teh terminal output with the 
  error message files are attached.
 
 If you read your site settings *carefully*, you will see that at least 
 some are not prefaced by tag=. They will then not be recognised and 
 inserted where needed, leading to chaos. Please go through your site 
 settings once again and correct them. Here is an example that just will 
 not work:

Sorry, my mistake - the line breaks were in my mail client, not your 
original. Do you want to mix gcc and g77 with the SunStudio compilers? You 
are at the moment (from your configure output), not setting CC or F77 but 
setting CXX and FC. Is this an appropriate list for your question?

 
 ## Header file search directory ('-IDIR') and any other miscellaneous
 ## options (such as defines) for the C preprocessor and compiler.
 ## If unset defaults to '-I/usr/local/include', with '-I/sw/include'
 ## prepended on systems using Fink with root '/sw'.
 ## CPPFLAGS=-I/usr/local/include -I/usr/local/include/readline
 -I/usr/sfw/include 
 
 but you also have:
 
 ## The command which runs the C++ compiler.  It not specified, configure
 ## uses the values of the environment variables 'CXX' or 'CCC' if set,
 ## and then looks under the names 'c++', 'g++', 'gcc', 'CC', 'cxx', and
 ## 'cc++' (in that order).
 CXX=/opt/SUNWspro/bin/CC -xarch=amd64
 
 
 
  
  Any help would be sincerely appreciated, as I have exausted my debugging 
  resources.  I believe that there is a problem with the configure script 
  in dealing with my particular setup.
  
  Octavio Tourinho
  
  
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Loop with string variable AND customizable summary output

2007-01-29 Thread Roger Bivand
On Mon, 29 Jan 2007 [EMAIL PROTECTED] wrote:

 Dear All,
 
 I am using R for my research and I have two questions about it:
 
 1) is it possible to create a loop using a string, instead of a numeric
 vector? I have in mind a specific problem:
 
 Suppose you have 2 countries: UK, and USA, one dependent (y) and one
 independent variable (y) for each country (vale a dire: yUK, xUK, yUSA,
 xUSA) and you want to run automatically the following regressions:
 
  
 
 for (i in c(UK,USA))
 
 output{i}-summary(lm(y{i} ~ x{i}))
 
  
 
 In other words, at the end I would like to have two objects as output:
 outputUK and outputUSA, which contain respectively the results of
 the first and second regression (yUK on xUK and yUSA on xUSA).
 

The input data could be reshaped as y, x, country, and subset= used in the 
lm() call. To assign to named objects see assign(), but consider using a 
named list instead, assigning to a list of the required length in turn, 
and giving the names from the defining vector. Then you'd get output$UK, 
etc.

  
 
 2) in STATA there is a very nice code (outreg) to display nicely (and
 as the user wants to) your regression results.
 
 Is there anything similar in R / R contributed packages? More precisely,
 I am thinking of something that is close in spirit to summary but it
 is also customizable. For example, suppose you want different Signif.
 codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 or a different
 format display (i.e. without t value column) implemented automatically
 (without manually editing it every time).
 
 In alternative, if I was able to see it, I could modify the source code
 of the function summary, but I am not able to see its (line by line)
 code. Any idea?

Use a custom function on the output object from using the summary() method 
on the lm object (that is on the summary.lm object). Use str() to look at 
the summary.lm object to see what you want.

 
 Or may be a customizable regression output already exists?
 
 Thanks really a lot!
 
 Carlo
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] sp: proj4string has no impact

2007-01-17 Thread Roger Bivand
On Wed, 17 Jan 2007, Albrecht Kauffmann wrote:

 Hi all,
 
 I'm faced with a problem applying the sp package: The projection argument in
 
 readShapePoly(Shapefile,proj4string=CRS class argument)
 
 e.g.: CRS(+proj=aea +lat_1=46 +lat_2=73 +lat_0=60 +lon_0=84 +x_0=0
 +y_0=0 +ellps=clrk66 +units=m  +no_defs)
 
 doesn't have any impact on the plotted object. I also tested the simple
 example:
 
 xy = cbind(x = 2 * runif(100) - 1, y = 2 * runif(100) - 1)
 plot(SpatialPoints(xy, proj4string =
 CRS(+proj=longlat)),xlim=c(-1,1),ylim=c(-1,1))
 
 looks exactly like
 
 plot(SpatialPoints(xy, proj4string =CRS(+proj=stere +lon_0=98  +over))
 
 or
 
 plot(SpatialPoints(xy))
 
 without any projection.
 
 What I'm doing wrong?

What impact would you like? The vertical scaling adjustment for 
geographical coordinates (+proj=longlat) is proportional to the distance 
of the midpoint of ylim from the Equator, so in your case no adjustment 
would be expected:

library(sp)
set.seed(1)
x - runif(20, -10, 10)
y - runif(20, -10, 10)
par(mfrow=c(3,2))
plot(SpatialPoints(cbind(x, y)), axes=TRUE)
plot(SpatialPoints(cbind(x, y), proj4string=CRS(+proj=longlat)), 
axes=TRUE)
plot(SpatialPoints(cbind(x, y+50)), axes=TRUE)
plot(SpatialPoints(cbind(x, y+50), proj4string=CRS(+proj=longlat)), 
  axes=TRUE)
plot(SpatialPoints(cbind(x, y+70)), axes=TRUE)
plot(SpatialPoints(cbind(x, y+70), proj4string=CRS(+proj=longlat)),
  axes=TRUE)
par(mfrow=c(1,1))



 
 I use the latest versions of sp and rgdal.
 
 With many thanks for any hint,
 
 Albrecht Kauffmann
 Potsdam University
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Regression lines

2007-01-12 Thread Roger Bivand
On Fri, 12 Jan 2007, Tom Backer Johnsen wrote:

 My simpleminded understanding of simple regression is that when 
 plotting regression lines for x on y and y on x in the same plot, the 
 lines should cross each other at the respective means.  But, given the 
 R function below, abline (lm(y~x)) works fine, but abline (lm(x~y)) 
 does not.  Why?
 
 function () {
 attach (attitude)
 x - rating
 y - learning
 detach (attitude)
 plot (x, y)
 abline(v=mean(x))
 abline(h=mean(y))
 abline (lm(y~x))
 abline (lm(x~y))
 }

The axes are getting reversed:

xylm - lm(x~y)
newdata - data.frame(y=0:80)
lines(predict(xylm, newdata), newdata$y, col=blue)

gets them back.

Roger


 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] map data.frame() data after having linked them to a read.shape() object

2007-01-10 Thread Roger Bivand
On Wed, 10 Jan 2007, Tord Snäll wrote:

 Dear all,
 I try to first link data in a data.frame() to a (polygon) read.shape() 
 object and then to plot a polygon map showing the data in the 
 data.frame. The first linking is called link in ArcView and relate 
 in ArcMap. I use the code shown below, though without success.
 
 Help with this would be greatly appreciated.

Please consider continuing this thread on the R-sig-geo list. Searching 
the archives might also have given you some leads. For now, and apart from 
not using sp classes (see note in R News in 2005), you have 490 polygons 
in the shapefile - probably one duplicate and 489 unique entities in 
STACOUNT4, but only 106 unique stacount of 431 observations in the data 
frame. The plot method for Map objects is deprecated. The classes in the 
sp package use S4, not S3, specifically to help users avoid putting things 
inside objects that break methods.

In maptools, see ?readShapePoly, and ?spCbind to see how to read a
shapefile into an sp object (check the 490/489 issue), and how the
Polygons IDs can be used as a key with the data frame row names to make
this easier to do. Please also consider using FIPS numbers as IDs for
counties; the five digit ssccc ID is fairly standard, and avoids the
problem of repetitive county names across US states.

 
 Thanks!
 
 Tord
 
 require(maptools)
 # Read shape file (one row per county)
 a=read.shape(myshp.shp, dbf.data=TRUE, verbose=TRUE)
 str(a)
   ..- attr(*, maxbb)= num [1:4] -100   4900
   ..- attr(*, class)= chr ShapeList
 $ att.data:'data.frame':   490 obs. of  60 variables:
   ..$ STATE_FIPS: Factor w/ 12 levels 04,06,08,..: 11 11 11 11 4 5
 5 5 5 5 ...
 [snip]
   ..$ STACOUNT4 : Factor w/ 489 levels ArizonaApache,..: 437 460 451
 453 147 207 195 198 231 206 ...
   ..- attr(*, data_types)= chr [1:60] C C C C ...
 - attr(*, class)= chr Map
 
 
 # Read case data (one row per case)
 cases = read.table(cases.txt, h=T,)
 str(cases)
 'data.frame':   431 obs. of  8 variables:
 $ Year: int  1950 1950 1950 1951 1956 1957 1959 1959 1959 1959 ...
 $ Case: int  3 1 2 1 1 1 2 4 1 3 ...
 $ stacount: Factor w/ 106 levels ArizonaApache,..: 1 66 76 66 26 29
 15 25 30 60 ...
 
 # table the cases data PER Year, PER County (County = stacount)
 temp = t(table(cases[,c(Year,stacount)]))
 stacount = dimnames(temp)$stacount
 temp = cbind(stacount, as.data.frame(temp[,1:ncol(temp)],row.names=F))
 str(temp)
 'data.frame':   106 obs. of  50 variables:
 $ stacount: Factor w/ 106 levels ArizonaApache,..: 1 2 3 4 5 6 7 8 9
 10 ...
 $ 1950: int  1 0 0 0 0 0 0 0 0 0 ...
 [snip]
 $ 2005: int  0 0 0 0 0 0 0 0 0 0 ...
 
 # Pick out a temporary attribute data.frame
 datfr = a$att.data
 
 # Merge the temporaty data frame with tabled cases
 for(i in 2:ncol(temp)){
  datfr = merge(datfr, temp[,c(1,i)], by.x=STACOUNT4,
 by.y=stacount, all.x=T, all.y=F)
 }
 
 #Replace NAs with 0:
 for(i in 61:109){
  datfr[,i] = ifelse(is.na(datfr[,i])==T,0,datfr[,i])
 }
 
 str(a$att.data)
 'data.frame':   490 obs. of  60 variables:
 $ NAME  : Factor w/ 416 levels Ada,Adams,..: 120 352 265 277 33
 210 122 135 372 209 ...
 [snip]
 $ STACOUNT4 : Factor w/ 489 levels ArizonaApache,..: 437 460 451 453
 147 207 195 198 231 206 ...
 - attr(*, data_types)= chr  C C C C ...
 # Note that the above data is of attribute type
 
 str(datfr)
 'data.frame':   490 obs. of  109 variables:
 $ STACOUNT4 : Factor w/ 489 levels ArizonaApache,..: 1 2 3 4 5 6 7 8
 9 10 ...
 [snip]
 $ 1951  : num  0 0 0 0 0 0 0 0 0 0 ...
 [snip]
 $ 2005  : num  0 0 0 0 0 0 0 0 0 0 ...
 # Note that at the end of this, data type is not described - it is a 
 simple data frame
 
 # bind data together:
 #Alternative 1:
 a$att.data = cbind(a$att.data, datfr[,61:109])
 # Other alternatives:
 test = matrix(ncol=49)
 a$att.data[,61:109] = test
 a$att.data[,61:109] = datfr[,61:109]
 
 # plot:
 plot(a, auxvar=a$att.data[,61], xlim=c(-125,-99),ylim=c(28,52), xlab=,
 ylab=, frame.plot=F,axes=F)
 There were 50 or more warnings (use warnings() to see the first 50)
 warnings()
 49: axes is not a graphical parameter in: polygon(xy$x, xy$y, 
 col,border, lty, ...)
 50: frame.plot is not a graphical parameter in: polygon(xy$x, 
 xy$y,col, border, lty, ...)
 
 # The a$att.data type has changed to becoming a typical data.frame - 
 attr is not mentioned:
 str(a$att.data)
 [snip]
 $ 2003  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ 2004  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ 2005  : num  0 0 0 0 0 0 0 0 0 0 ...
 
 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented

Re: [R] Logical operations or selecting data from data.frames

2007-01-09 Thread Roger Bivand
On Tue, 9 Jan 2007, Benjamin Dickgiesser wrote:

 I suppose this doesn't work for the same reason as
 sdata$VaR  sdata$DdtdAbs  sdata$DdtdDuration = 1
 
 does only return  FALSE and not a vector of TRUE and FALSE as

See ?:

 '' and '' indicate logical AND and '|' and '||' indicate
 logical OR.  The shorter form performs elementwise comparisons in
 much the same way as arithmetic operators.  The longer form
 evaluates left to right examining only the first element of each
 vector...

a - rep(c(1,2), 5)
b - rep(1,10)
a  1  b = 1
a  1  b = 1


 
 sdata$VaR  sdata$DdtdAbs
 
 would return.
 
 Is there a ways around this?
 Benjamin
 
 On 1/9/07, Benjamin Dickgiesser [EMAIL PROTECTED] wrote:
  Hi all,
 
  why doesn't something like this does not work?
 
  speedy -
  (sdata$VaR  sdata$DdtdAbs)  sdata$DdtdDuration = 
  qpois(pct,lambda) 
  sdata$Ddtd  MinDD
 
  or sdata$Ddtd[sdata$Ddtd  0  sdata$VaR  sdata$DdtdAbs]
 
  sdata looks like this:
 
 dataId   date  value Ddtd VaR DdtdAbs DdtdDuration
  18948  79637 2004-07-27 10085.10   NA NA0.00  0
  18949  79638 2004-07-28 10117.10   NA NA0.00  0
  18950  79639 2004-07-29 10129.20   NA NA0.00  0
  18951  79640 2004-07-30 10139.70   NA NA0.00  0
  18952  79641 2004-08-02 10179.20   NA NA0.00  0
  18953  79642 2004-08-03 10120.20  0.579613329 336.060090   59.00
  1
  18954  79643 2004-08-04 10126.50   NA NA0.00  0
  18955  79644 2004-08-05  9963.03  1.614279366 334.306978  163.47
  1
  18956  79645 2004-08-06  9815.33  3.072828717 386.173057  311.17
  2
  18957  79646 2004-08-09  9814.66  3.079445020 420.167049  311.84
  3
  18958  79647 2004-08-10  9944.67   NA NA0.00  0
  18959  79648 2004-08-11  9938.32  0.063853300 328.3159926.35
  1
  18960  79649 2004-08-12  9814.59  1.308037371 379.182568  130.08
  2
 
  I am trying to select rows from the data.frame which have Ddtd  x,
  VaR  DdtdAbs and DdtdDuration  z.
 
  Thank you,
  Benjamin
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] write() gotcha

2006-12-18 Thread Roger Bivand
On Mon, 18 Dec 2006, Robin Hankin wrote:

 Hi
 
 I used write() the other day to save some results.
 
 It seems that write() does not record the full precision of
 the objects being written:
 
 
   write(pi,file=~/f,ncolumns=1)
   pi.saved - scan(~/f)
 Read 1 item
   dput(pi)
 3.14159265358979
   dput(pi.saved)
 3.141593
   pi-pi.saved
 [1] -3.464102e-07
  
 
 
 This difficulty was particularly difficult to find because pi.saved   
 *looks*
 the same as pi.
 
 
 
 What's going on here?
 

Use options(digits=) to control the output. ?write says write() is a 
wrapper for cat(), so:

options(digits=16)
cat(pi, \n)
write(pi,file=~/f,ncolumns=1)
pi.saved - scan(~/f)
dput(pi.saved)
dput(pi)

looks OK


 
 
 
 
 
   R.Version()
 $platform
 [1] powerpc-apple-darwin8.7.0
 
 $arch
 [1] powerpc
 
 $os
 [1] darwin8.7.0
 
 $system
 [1] powerpc, darwin8.7.0
 
 $status
 [1] 
 
 $major
 [1] 2
 
 $minor
 [1] 4.0
 
 $year
 [1] 2006
 
 $month
 [1] 10
 
 $day
 [1] 03
 
 $`svn rev`
 [1] 39566
 
 $language
 [1] R
 
 $version.string
 [1] R version 2.4.0 (2006-10-03)
 
 
 --
 Robin Hankin
 Uncertainty Analyst
 National Oceanography Centre, Southampton
 European Way, Southampton SO14 3ZH, UK
   tel  023-8059-7743
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Function to fit a STARIMA model

2006-12-15 Thread Roger Bivand
On Thu, 14 Dec 2006, Rajesh Krishnan wrote:

 Hi all,
 
 I was wondering if there is a function available in any of the R add-on 
 packages that could be used to fit a STARIMA (Phillip E. Pfeifer and 
 Stuart Jay Deutsch. (1980). A STARIMA Model-Building Procedure with 
 Application to Description and Regional Forecasting, Transactions of 
 the Institute of British Geographers 5(3), 330-349.) model?

I'm afraid there is no such function. The approach has been used very
little since it was proposed, and probably more work has been done on
spatial panel models (not yet in R) and in the hierarchical model
framework (again not yet in R, although the spBayes package may offer some
possibilities).

 
 Thanks,
 
 Rajesh.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Paste function and backslash

2006-12-08 Thread Roger Bivand
On Fri, 8 Dec 2006, Szymon Wlazlowski wrote:

 Dear useRs,
 
 calls and results below:
  paste(\ \n)
 [1]  \n
 *but*
  paste(\ \N)
 [1]  N
 Question: Is that by design? If so, how can I obtain simple LaTeX-type:
 [1] \N

FAQ 7.37:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-does-backslash-behave-strangely-inside-strings_003f


 
  version
 platform   i386-pc-linux-gnu
 arch   i386
 os linux-gnu
 system i386, linux-gnu
 status
 major  2
 minor  4.0
 year   2006
 month  10
 day03
 svn rev39566
 language   R
 version.string R version 2.4.0 (2006-10-03)
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Heteroscedasticity consistent standard errors for Spatial error models

2006-12-07 Thread Roger Bivand
On Thu, 7 Dec 2006, Achim Zeileis wrote:

 On Thu, 7 Dec 2006, Samarasinghe, Oshadhi Erandika wrote:
 
  Hello,
 
  Could anyone please tell me how to estimate Heteroscedasticity
  Consistent standard errors for a Spatial error model? All the functions
  I have looked at only works for lm objects.
 
 I assume that you looked also at the sandwich package: The methods there
 do not only work for lm objects but are object-oriented, appropriate
 methods are already provided for a range of different object classes. So,
 in principle, you can plug in other models as well, potentially including
 spatial models if appropriate methods are provided. See
   vignette(sandwich-OOP, package = sandwich)
 
 Disclaimer: I'm not sure whether the spatial structure of spatial models
 will be appropriately captured by the class of estimators implemented in
 sandwich. But someone who knows spatial models and their HC covariances
 should be able to figure that out from the vignette above. I'm also not
 sure what specialized methods exist...

Typically, the use of HC covariances with these kinds of models is an 
inappropriate fix for missing variables and possibly also wrong functional 
forms. Some supervisors want them, but in practice fitting a better 
specified model is superior. It is also possible to sample from the fitted 
model - I've been looking at MH sampling from MCMCpack - and that I feel 
is a way to go if the model is badly specified and you can't do anything 
about it. 

Settings where natural experiments exist are also very helpful, with
shifts in coefficient values and/or standard errors indicating whether the
hypothesised cause of difference actually had an effect.

It can probably be done, and some journals/referees/supervisors etc. want 
HC covariances, but I'm afraid that doesn't necessarily mean that they are 
any use in practice with these pretty rough kinds of models.

Roger

 
 Best,
 Z
 
 
  Thank you very much!
 
  - Oshadhi
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] making a grid of points

2006-12-07 Thread Roger Bivand
On Thu, 7 Dec 2006, Ross Boylan wrote:

 I'd like to evaluate a function at each point on a 2 or 3-D grid.  Is
 there some function that already does this, or generates the grid of
 points?
 
 My search has led me to the grid and lattice packages, and I found a
 reference to the sp package (e.g., SpatialGrid) for this.  There are
 things in there that might be relevant, but at first blush many of them
 are embedded in other concepts (grobs, shingles, rugs) and don't
 obviously solve the problem.
 
 I know this is not a hard thing to program, but I suspect someone has
 already done it.  Any pointers?

Which space are your points in? The sp package might help if the data 
are spatial/geographical, but I think that expand.grid() is your friend, 
followed by one of the apply() family to run your function on each row of 
the data frame output by expand.grid().

Roger


 
 Thanks.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] test of spatial dependence?? - ask an ecologist?

2006-12-06 Thread Roger Bivand
On Wed, 6 Dec 2006, Xu Yuan wrote:

 Thanks David and Milton for replies. No, I don't have the coordiates.
 In other words, my data are not point data. But I think there is a way
 to test of spatial dependence for areal data or lattice data. In this
 case, the variable of interest is typically the average value of an
 area instead of a point. Do you how to do this?

But do you know where the areas are in relation to each other? Does the 
spatialCovariance package help?

Roger

 
  Thank you.
  Xu
 
 On 12/6/06, Milton Cezar Ribeiro [EMAIL PROTECTED] wrote:
 
  I never used it, but I beleave that it is a job for mantel.rtest() 
  available on ade4 package.
 
  In fact Farrar are right, you will neet the XY coordinates. Give a look at 
  Legendre  Legendre text book.
 
  HTH,
 
  Miltinho
  Brazil
 
  David Farrar [EMAIL PROTECTED] escreveu:
 
 
  In addition to the 25 numbers, I assume you have coordinates of each field.
  Otherwise, I don't understand what you are trying to do. I think ecologists 
  like to use a test due to Mantel in this situation.
 
  The prefix auto means self, of course, the idea being that measurements 
  of the same variable under different conditions are correlated. I guess 
  this would be a case of autodependence. For correlation versus 
  dependence, check your  intro stats book.
 
  de nada,
  X'X
 
  Farrar
 
 
  Xu Yuan wrote:
  hello R-friends,
 
  I am a R beginner and try to ask a basic question:
 
  How to test the spatial dependence of a column of data? for example, I have
  25 agricultural fields, and I measure the average slope (%) or pH for each
  field. All I have is 25 numbers.
 
  PS, could someone confirm that spatial dependence is equivalent to
  spatial correlation or spatial autocorrelation or not.
 
  Thank you very much.
  XY
 
  [[alternative HTML version deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
  [[alternative HTML version  deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
  
   O Yahoo! está de cara nova. Venha conferir!
 
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] double precision

2006-12-05 Thread Roger Bivand
On Tue, 5 Dec 2006, Yoni Schamroth wrote:

 Hi,
 
 I am attempting to query a data frame from a mysql database.
 One of the variables is a unique identification number (numeric) 18 digits
 long.
 I am struggling to retrieve this variable exactly without any rounding.

Read it as a character - a double is a double:

 x - 6527600583317876352
 y - 6527600583317876380
 all.equal(x,y)
[1] TRUE
 storage.mode(x)
[1] double

and why they are equal is a FAQ (only ~16 digits in a double). Integer is
4-byte. Since they are IDs, not to be used for math, leave them as
character strings - which they are, like telephone numbers.


 
 The function I am using is sqlQuery(), with an ODBC connection.
 Querying directly results in the double being rounded towards the end (eg
 6527600583317876352 instead of 6527600583317876380)
 
 Is there anyway of preserving the numeric class of the variable and it
 precision without converting it to a factor? Is the double stored as a
 64-bit integer?
 
 I have attempted to use the 'dec' as well as 'as.is = TRUE', both
 automatically convert it to a factor which I am trying to avoid. 
 
 Any advice or assistance would be greatly appreciated.
 
 Thanks
 
 Yoni Schamroth
 Director of Research
 MediaBoost LTD
 Tel. +972-3-5333033 (ext. 105)
 Fax. +972-3-5480617
 Mob. +972-52-3422204
 [EMAIL PROTECTED]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] memory problem [cluster]

2006-12-02 Thread Roger Bivand
On Sat, 2 Dec 2006, Dylan Beaudette wrote:

 Hi Stephano,

Looks like you used my example verbatim 
(http://casoilresource.lawr.ucdavis.edu/drupal/node/221)

:)

From exchanges on R-sig-geo, I believe the original questioner is feeding
NAs to clara, and the error message in clara() is overrunning the buffer
in sprintf(), so the memory problem isn't correctly identified. Using
scripts out of context without checking whether the input data frame 
satifies the conditions of the functions being used is asking for trouble. 
The error message:

  traceback()
2: stop(ngettext(length(i), sprintf(Observation %d has, i[1]),
sprintf(Observations %s have, paste(i, collapse = ,))),
 *only* NAs -- omit for clustering)
1: clara(morph, k = 5, stand = F)

is coming from lines:

i[1]), sprintf(Observations %s have, paste(i, 
collapse = ,))),  *only* NAs -- omit for clustering)

in clara(). I have suggested dropping those rows from the data frame in a 
reply on R-sig-geo, but maybe clara() could be patched to count the # of 
completely missing rows, and if # is more than a modest number, not print 
the obs. numbers, just the total?

Roger


While my approach has not *yet* been published, the original source [4] by 
Roger Bivand certainly has. Just a reminder.

That said, I would highly recommend reading up on the background literature 
assocated with both the cluster package [1] and terrain classificartion i.e.
[2] and [3]. Note that although the clara() function was created to work on 
massive datasets, it is still possible to overwhelm the available memory with 
multiple gridded objects- recall that all R objects are held in memory.

I have asked the maintainer of the cluster package, Martin Maechler, about 
integrating a known medoid option into the clara() function- which would be 
extremely useful in adding some 'supervision' to landscape classification 
with clara(). Hopefully there will be enough requests for the feature, that 
Martin will kindly add it :) .

1. Kaufman, L.  Rousseeuw, P.J. Finding Groups in Data An Introduction to 
Cluster Analysis Wiley-Interscience, 2005

2. Blaszczynski, J. Landform characterization with geographical information 
systems Photogrammetric Engineering and Remote Sensing, 1997, 63, 183-191

3. Wood, W.F.  Snell, J.B. A Quatitative system for classifying landforms 
U.S. Quatermaster Research  Engineering Center, 1960

4. Bivand, R. Integrating GRASS 5.0 and R: GIS and modern statistics Computers 
 Geosciences, 2000, 26, 1043–1052


On Friday 01 December 2006 14:04, Massimo Di Stefano wrote:
 hi to all,
 frustated for this error, to day i buy a 1 GB memory
 slot for my laptop
 now it have 1,28GB instead the old 512, but i've the
 same error :-(
 damn!damn!how can i do?
 repeat for a little area (about 20X20 km and res=20m)
 it work fine!
 have you any suggestion?
 is ther a method for look if this error depend from my
 ram or other?
 thanks foe any suggestion!
 i need your help.
 thanks.
 Massimo


 Il giorno 01/dic/06, alle ore 16:05, massimodisasha ha
 scritto:
 hi,
 i'm trying to perform a clustering on a big dataframe
 the code is this:


 print(load required R packages)

 require(spgrass6)

 require(cluster)

 gmeta6 - gmeta6()

 print(read in our 7 raster files from GRASS)

 x -
 readFLOAT6sp(c(er,crosc,longc,slope,profc,minic,maxic))

 print(assemble a matrix of our terrain variables)

 morph - data.frame(cbind(x$er, x$crosc, x$longc,
 x$slope, x$profc, x$minic, x$maxic))

 print(normailize slope by dividing my max(slope))

 morph - data.frame(cbind(x$er, x$crosc, x$longc,
 x$slope/max(x$slope), x$profc, x$minic, x$maxic))

 names(morph) -
 c(er,crosc,longc,slope_n,profc,minic,maxic)

 print(perform the clustering)

 morph.clara - clara(morph, k=5, stand=F)

 x$morph_class - morph.clara$clustering

 print(send result back to GRASS)

 rast.put6(x,morph, zcol=morph_class)



 during the step : perform the clustering
 after a lot of time,
 i've this error:




 Errore in sprintf(fmt, ...) : La lunghezza della
 stringa eccede la dimensione del buffer di 8192
 Inoltre: Warning messages:
 1: perl = TRUE è implementato solo nei locale UTF-8
 2: perl = TRUE è implementato solo nei locale UTF-8
 3: perl = TRUE è implementato solo nei locale UTF-8
 4: perl = TRUE è implementato solo nei locale UTF-8
 5: perl = TRUE è implementato solo nei locale UTF-8
 6: perl = TRUE è implementato solo nei locale UTF-8
 7: perl = TRUE è implementato solo nei locale UTF-8
 8: La stringa di caratteri verrà probabilmente
 troncata
 Esecuzione interrotta



 if i try the same code on a subregion of my data, it
 works very fine!
 but for a large region i've this error :-(

 obviously i think that is a memory problem, right ?
 (i'm working with a notebook PPC-1.33-512ram)
 my data are  : 7 raster-map on a region of about 50X40
 km at a resolution of 20m.
 is there some wolkaround about the memory problems?

 an other question

Re: [R] Demand of help

2006-12-01 Thread Roger Bivand
On Fri, 1 Dec 2006 [EMAIL PROTECTED] wrote:

 Hi, I'm a phd student of economics in Tunisia who is intersted now with
 the seasonal unit roots test of Canova and Hansen. So I've installed the
 package uroot in RGUI. I use R 2.4.0. The problem when I apply the
 function to my data, I've always a message from RConsole that it is
 impossible to find the function CH.test. Are there problems as for the
 use of this package? Please help me. Thank you in advance.

library(uroot) ?

   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] *** caught segfault *** error

2006-11-30 Thread Roger Bivand
 use R v2.2.1 on Windows XP Home  
 Edition v2002.
 
 Any ideas of what may cause the error?
 
 Many thanks,
 
 Juanjo Abellan
 Research Associate in Statistics
 Department of Epidemiology and Public Health
 Imperial College London
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Aligning aerial photographs and maps

2006-11-28 Thread Roger Bivand
On Tue, 28 Nov 2006, F.Tusell wrote:

 I have read in Paul Murrell's book R Graphics about how to use a bitmap
 as background for a plot (page 107). Also, I routinely use function
 read.shape() in package maptools to read maps in shapefile format. Now,
 I would like to overlay an aerial photograph in .jpg format and a map. I
 think I could do the alignment manually for each case, but wonder if
 there is a better, automated way. I notice that the .jpg file has a
 companion .jgw file which may be of help.

The most direct route for data with spatial coordinate reference systems 
is to use classes defined in the sp package and functions in the rgdal 
package to fill them. Assuming that your image and shapefile are in the 
same coordinate reference system:

library(rgdal)
x - readGDAL(image.jpg)

will read the image into a SpatialGridDataFrame x. If image.jpg is 
three-band rather than single-band, the next release of rgdal will show 
how to do this on the help pages of the RGB2PCT and SGDF2RBG functions.

If the *.jpw file is read correctly, summary(x) should display the 
coordinate reference system among other things. Next read the shapefile 
with:

y - readOGR(., shapefile) 

where the first argument is the directory containing the shapefile and the 
second is the name of the shapefile with no extension. If the shapefile 
has a coordinate reference system, summary(y) should show it. If it 
doesn't have one, but you know what it is, add it in PROJ.4 notation. If x 
and y differ in coordinate reference system, use the spTransform method to 
transform y to the same CRS as x. Then:

image(x)
plot(y, add=TRUE)

will do what you need.

Perhaps follow-up on the R-sig-geo list?

Roger

 
 If someone has written code for such kind of alignments or can direct me
 to detailed instructions on how to go about,  I would be grateful. ft.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Advice on Grid Data

2006-11-24 Thread Roger Bivand
On Fri, 24 Nov 2006, Lorenzo Isella wrote:

 Dear All,
 I would like to automate the analysis and plotting of data taken from a grid.
 Typically I deal with 2 spatial coordinates and a scalar f(x,y), but
 the spatial grid is not evenly spaced at all and usually given in this
 form:
 x y f(x,y)
 0.0  0.048979383  2.7659438106975056
 0.0  0.044986665  2.603891585041688
 0.0023807306 0.04787451   2.715949356768243
 0.0  0.040993948  2.469223979694342
 0.0023807306 0.043881793  2.5625191444824265
 0.004761461  0.046769638  2.6629703119429022
 0.0  0.03700123   2.361940994655468
 0.0023807306 0.039889075  2.436480700580665
 0.004761461  0.04277692   2.517958884562618
 0.0071421918 0.045664765  2.606844303834078
 0.0  0.060880877  3.470808435449538
 0.0  0.05691371   3.1907723461238686
 0.0020467786 0.059650626  3.3672237912200016
 0.0  0.05294655   2.9558174712065237
 0.0020467786 0.055683464  3.1075221272152054
 0.004093557  0.05842038   3.268965886866726
 0.0020467786 0.051716298  2.8929170062920653
 0.004093557  0.054453213  3.029154848759894
 0.006140336  0.057190128  3.1754081073235088
 0.0  0.02473231   2.138648866573983
 0.0  0.020556964  2.092324627395541
 
 I tried the image plot and lattice but unsuccessfully. Now I am
 reading about the sp package (
 http://cran.r-project.org/src/contrib/Descriptions/sp.html ), but I
 mainly would like a piece of advice about what tools to use and how to
 read and plot these data (I suppose it must be common e.g. in
 geography to deal with this kind of problems).

Your data are not on a 2D grid, there are (here) 7 unique x values, but 21
unique y values of 21. You can treat the data as a SpatialPointsDataFrame
(see note in R News in 2005), but if you want to display them on an actual
grid, you will have to interpolate. For more ideas, perhaps try the 
R-sig-geo mailing list.

 Kind Regards
 
 Lorenzo
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [R-sig-Geo] plot() and Jpeg() increase font size and resolution

2006-11-23 Thread Roger Bivand
On Fri, 24 Nov 2006 [EMAIL PROTECTED] wrote:

  
 Dear list,
 
 I am having troubles increasing the fontize when plotting a
 variogram{gstat} and its model (vgm) with plot and using jpeg(). Also
 the resolution in the jpeg call does not work. I am using R2.4 on
 Mandriva 10.2 linux.
 
 I can change fontsize with cex.axis in a normal plot, so I presume it
 has to do with plotting the variogram model. Any help on how to increase
 the font size and resolution would be appreciated?

I believe that the underlying plot.gstatVariogram() method uses lattice 
graphics, not base graphics. So the problem is to find the right way of 
passing the parameter for xyplot(), and then see if plot.gstatVariogram() 
lets you do the same.

df - data.frame(x=1:10, y=runif(10))
xyplot(y ~ x, df, scales=list(cex=3))

works, but

data(meuse)
vgm1 - variogram(log(zinc)~1, ~x+y, meuse)
plot(vgm1, scales=list(cex=3))

unfortunately doesn't, so more exploration will be needed. I think the 
scales= argument is not passed through in the final brach to xyplot() in 
gstat:::plot.gstatVariogram(). From the examples:

plot(v, group.id = FALSE, auto.key = TRUE, scales=list(cex=2))

works, but

plot(vgm2, scales=list(cex=2))

doesn't.

Roger

 
 R-calls:
 v1-variogram(log(z)~x+y, loc=coordinates(shp1),data=shp1)
 m1-vgm(0.0175, Gau, 20,0.052)
 
 jpeg(file=LOTPLAN_variogram_mod.jpg, bg=white, res=300,
 pointsize=16, width=1200, height=1200, quality=100)
 
  plot(v1,plot.number=F, model=m1, ylim=c(0.04,0.08), col=black,
 cex.axis=1.5)
 
 dev.off()
 
 Thanks Herry
 
 Dr Alexander Herr
 Spatial and statistical analyst
 CSIRO, Sustainable Ecosystems
 Davies Laboratory,
 University Drive, Douglas, QLD 4814 
 Private Mail Bag, Aitkenvale, QLD 4814
  
 Phone/www 
 (07) 4753 8510; 4753 8650(fax)
 Home: http://herry.ausbats.org.au
 Webadmin ABS: http://ausbats.org.au
 Sustainable Ecosystems: http://www.cse.csiro.au/
 
 ___
 R-sig-Geo mailing list
 R-sig-Geo@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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Can I execute the content of a character vector?

2006-11-13 Thread Roger Bivand
On Mon, 13 Nov 2006, Luiz Rodrigo Tozzi wrote:

 Hi
 
 I want to know if there is any possibility of executing the content of a
 vector, for example:
 
 example=c(Test,1,0,0,0,seq(14,42,by=2),0,0,1)
 
 i want to know if there is anything like execute(example[6])

You can say:

eval(parse(text=example[6]))

but it is difficult to avoid shooting people in the feet with it, unless 
that is what you want ...

eval(parse(text=example[1]))


 
 i really need this because this object example is created from a parameter
 file with names, flags and this seq somethimes will be something like
 c(1,99,3) or even c()
 
 executing the content would be an easier step for me
 
 thanks!
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] POSIXlt converted to POSIXct in as.data.frame()

2006-11-09 Thread Roger Bivand
In trying to use as.Date(), I've come across the conversion of POSIXlt to 
POSIXct when a POSIXlt variable is included in a data frame:

my_POSIX - strptime(c(11-09-2006, 11-10-2006, 11-11-2006, 
  11-12-2006, 11-13-2006), %m-%d-%Y)
str(my_POSIX)
my_Date - as.Date(my_POSIX)
str(my_Date)
data - format(my_Date)
str(data)
my_DF - data.frame(my_POSIX)
str(my_DF)
DF_Date - as.Date(my_DF$my_POSIX)
str(DF_Date)
DF_Date

The consequence (for my LC_TIME and machine time zone) is that when 
as.Date() is applied to the data frame column, it dispatches on 
as.Date.POSIXct() not as.Date.POSIXlt(), causing a day shift (actually 60 
minutes, but because as.Date.POSIXct() says floor(), it ends up being a 
whole day). Should data.frame() be changing POSIXlt to POSIXct?

As as.data.frame.POSIXlt() is written, it says:

 as.data.frame.POSIXlt
function (x, row.names = NULL, optional = FALSE, ...) 
{
value - as.data.frame.POSIXct(as.POSIXct(x), row.names, 
optional, ...)
if (!optional) 
names(value) - deparse(substitute(x))[[1]]
value
}
environment: namespace:base

which seems a little brutal. Using I() seems to be a work-around:

my_DF - data.frame(my_POSIXa=I(my_POSIX))
str(my_DF)
class(my_DF$my_POSIXa)
DF_Date - as.Date(my_DF$my_POSIXa)
str(DF_Date)
DF_Date

In the original problem (conversion of a list read from PostgreSQL to 
a data frame with as.data.frame()), having to know that you need to insert 
I() is perhaps unexpected.

Roger

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] wrong fill colors in polygon-map

2006-11-07 Thread Roger Bivand
On Tue, 7 Nov 2006, Frosch, Katharina wrote:

 Dear all,
 
 I would like to produce a map with information about the patenting
 activity in German districts, by coloring districts with different
 degrees of patenting activity in different colors. I work with the
 packages maptools, maps and spdep. The map data is read from an external
 .shp file (+ the corresponding .shx and .dbf files). Plotting a map with
 the IDs or the patenting indicator itself works fine. But coloring the
 map leads to completely odd results (wrong colors for most of the
 regions). I also tried simpler values (just 0 and 1 for different
 regions), same problem. I tried to check whether there is any problem
 with the match of data and district ids, but everything seemed to be
 fine. 
 
 Sample code: 
 
 brks.pat-quantile(patenting$patbus)
 #palette.pat-c(green, blue, grey, darkgrey, red)
 palette.pat-c(rep(green, 4), red)
 plot(iab7.poly, col=palette.pat[findInterval(patenting$patbus,
 brks.pat)])
 legend(1200, -200, fill=palette.pat, legend=round(brks.pat,2), cex=0.6)
 title(main=patenting activity in german districts)
 
 Data:
 **
 Iab7.poly contains the polygons of 343 German districts
 patenting$patbus contains the number of corporate patents per 100.000
 inhabitants for each district

(R-sig-geo may be a more focussed list for this kind of question)

If the polygons in Iab7.poly are in the same order as the rows of
patenting, and the number of polygons is the same as the number of rows,
it is possible that the breakpoints are not quite what you think (if for
example some of the quantiles are equal, which happens with zero-inflated
data). Omitting all.inside=TRUE in findInterval() can also lead to the
insertion of NA values into the vector of colours.

Perhaps have a look at the classInt package for some examples of choosing 
class intervals i.a. for map display.

Roger

 
 Any ideas would be appreciated!
 
 Best regards,
 Katharina
 
 
 
 **
 
 Katharina Frosch
 Rostock Center for the Study of Demographic Change
 Konrad-Zuse-Str. 1
 18057 Rostock
 Tel.: (0381) 2081-148
 Fax: (0381) 2081-448
 Mail: [EMAIL PROTECTED] 
 
 
 
 
 
 
 --
 This mail has been sent through the MPI for Demographic Rese...{{dropped}}
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] wrong fill colors in polygon-map

2006-11-07 Thread Roger Bivand
On Tue, 7 Nov 2006, Frosch, Katharina wrote:

 Dear Roger: Thank you for your help and the hint with the R-sig-geo list
 (next time I'll post directly to it)!
 
 I went again through all points you mentioned: 
 - polygons and rows of data are in the same order
 - the number of polygons and data rows is identical
 - I experimented with different values, and also defined explicit
 breakpoints without using the quantile (no effect)
 - then I added all.inside=TRUE in findIntervall (no effect)
 
 However, adding the forcefill=FALSE option to the plot command led to a
 strange effect: three districts were left blank. Two of these districts
 were districts that are situated around another district (district
 A=city itself, district B=the countryside around). The third problematic
 district is situated close to the Swiss border and next to a big lake. I
 deleted the three districts, to see what happens. The problem is partly
 resolved, but new blank districts appear. 
 
 Could this be caused by a corrupted shape file rathern than by R? I
 loaded the shape-file with the Program Mapviewer in MIF/MID format,
 unionized some districts, then exported it to an ESRI-shapefile and used
 it in R. 

It is at least worth trying. May I suggest reading the MIF/MID file
directly into R using the readOGR() function in the rgdal package? If you
are a Mac OSX user, there is extra help needed installing rgdal, but on
Windows it is available for binary install directly from CRAN (thanks to
Uwe Ligges). The spatial classes used there are more robust, and the data
and polygons can be kept together. Polygons may also be dissolved using
objects of the SpatialPolygons class.

Could I suggest that you move any reply to R-sig-geo, given that the 
details of spatial data formats are not of general interest?

Roger

 
 I don't have any clue to resolve this...so any hint is very welcome!
 Katharina
 
 
 
 **
 Katharina Frosch
 Rostocker Zentrum
 Konrad-Zuse-Str. 1
 18057 Rostock
 Tel.: (0381) 2081-148
 Fax: (0381) 2081-448
 Mail: [EMAIL PROTECTED] 
 
  
 
 
 -Original Message-
 From: Roger Bivand [mailto:[EMAIL PROTECTED] 
 Sent: Dienstag, 7. November 2006 13:27
 To: Frosch, Katharina
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] wrong fill colors in polygon-map
 
 On Tue, 7 Nov 2006, Frosch, Katharina wrote:
 
  Dear all,
  
  I would like to produce a map with information about the patenting
  activity in German districts, by coloring districts with different
  degrees of patenting activity in different colors. I work with the
  packages maptools, maps and spdep. The map data is read from an
 external
  .shp file (+ the corresponding .shx and .dbf files). Plotting a map
 with
  the IDs or the patenting indicator itself works fine. But coloring the
  map leads to completely odd results (wrong colors for most of the
  regions). I also tried simpler values (just 0 and 1 for different
  regions), same problem. I tried to check whether there is any problem
  with the match of data and district ids, but everything seemed to be
  fine. 
  
  Sample code: 
  
  brks.pat-quantile(patenting$patbus)
  #palette.pat-c(green, blue, grey, darkgrey, red)
  palette.pat-c(rep(green, 4), red)
  plot(iab7.poly, col=palette.pat[findInterval(patenting$patbus,
  brks.pat)])
  legend(1200, -200, fill=palette.pat, legend=round(brks.pat,2),
 cex=0.6)
  title(main=patenting activity in german districts)
  
  Data:
  **
  Iab7.poly contains the polygons of 343 German districts
  patenting$patbus contains the number of corporate patents per 100.000
  inhabitants for each district
 
 (R-sig-geo may be a more focussed list for this kind of question)
 
 If the polygons in Iab7.poly are in the same order as the rows of
 patenting, and the number of polygons is the same as the number of rows,
 it is possible that the breakpoints are not quite what you think (if for
 example some of the quantiles are equal, which happens with
 zero-inflated
 data). Omitting all.inside=TRUE in findInterval() can also lead to the
 insertion of NA values into the vector of colours.
 
 Perhaps have a look at the classInt package for some examples of
 choosing 
 class intervals i.a. for map display.
 
 Roger
 
  
  Any ideas would be appreciated!
  
  Best regards,
  Katharina
  
  
  
  **
  
  Katharina Frosch
  Rostock Center for the Study of Demographic Change
  Konrad-Zuse-Str. 1
  18057 Rostock
  Tel.: (0381) 2081-148
  Fax: (0381) 2081-448
  Mail: [EMAIL PROTECTED] 
  
  
  
  
  
  
  --
  This mail has been sent through the MPI for Demographic
 Rese...{{dropped}}
  
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
  
 
 

-- 
Roger Bivand
Economic Geography Section

Re: [R] Re : Draw a circle with a given radius in an existing map

2006-11-06 Thread Roger Bivand
On Tue, 7 Nov 2006, justin bem wrote:

 Try this :
 it-seq(0,2*pi, l=100)
 xt-r*cos(it)
 yt-r*sin(it)
 points(xt,yt,type=l,col=blue)
 
 a circle of radium r is define by
xt=r*cos(t)
yt=r*sin(t) 

Isn't this suggestion on the plane, when the question was about finding
the coordinates on the surface of the sphere (globe) in degrees of
longitude and latitute that are x miles from the centre?

If the area is not large, then projecting the centre point to a suitable 
planar projection, making the circle on the plane as above, and inverse 
projecting back to geographical coordinates should work (function 
project() in package rgdal). If the radius is in thousands of miles, the 
projection distortion would be considerable, though.

 
 Justin BEM
 Elève Ingénieur Statisticien Economiste
 BP 294 Yaoundé.
 Tél (00237)9597295.
 
 
 
 - Message d'origine 
 De : Xiaomei Ma [EMAIL PROTECTED]
 À : R-help@stat.math.ethz.ch
 Envoyé le : Mardi, 7 Novembre 2006, 6h11mn 27s
 Objet : [R] Draw a circle with a given radius in an existing map
 
 
 I have drawn a map in which the X and Y axes are latitude and 
 longitude. Now I need to draw one circle on the map - the center is a 
 point with specific latitude and longitude, but the challenge is that 
 the radius is in miles. Is there a way to do this? I'd very much 
 appreciate your response.
 
 XM
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
   
 
   
   
 ___ 
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
 Profitez des connaissances, des opinions et des expériences des internaut
 
   [[alternative HTML version deleted]]
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Installing a package - and making it work?

2006-11-03 Thread Roger Bivand
On Fri, 3 Nov 2006, Hvidberg, Martin wrote:

 Dear list
  
 - Propoerly a beginner question, so bare with my frustration...

Yes, and posting to R-help three minutes after posting to R-sig-geo, the 
correct list - raises the question about who's time is more important, 
doesn't it?

What does help.search(read.dbf) tell you? 

(hint: read.dbf() in shapefiles calls read.dbf() in the recommended 
foreign package, which is certainly already present in your (unstated) 
Windows binary R 2.4.0 installation.)

  
 I tried install the 'shapefiles' package into R 2.4.0 but it seems that the 
 install had little effect...
  
 
install.packages(c(shapefiles))
   --- Please select a CRAN mirror for use in this session ---
   trying URL 
 'http://cran.dk.r-project.org/bin/windows/contrib/2.4/shapefiles_0.5.zip'
   Content type 'application/zip' length 42335 bytes
   opened URL
   downloaded 41Kb
   package 'shapefiles' successfully unpacked and MD5 sums checked
   The downloaded packages are in
   C:\TEMP\RtmpMz5Pqb\downloaded_packages
   updating HTML package descriptions
 dbf - read.dbf(test.dbf)
   Error: could not find function read.dbf

   
   Note thet the last line contains an error.
 
  
 Is the package installed or not?
 How do I get access to use the functionality it offers??
  
 :-? Martin Hvidberg
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Installing a package - and making it work?

2006-11-03 Thread Roger Bivand
On Fri, 3 Nov 2006, Torsten Hothorn wrote:

 
 On Fri, 3 Nov 2006, Hvidberg, Martin wrote:
 
  Dear list
 
  - Propoerly a beginner question, so bare with my frustration...
 
  I tried install the 'shapefiles' package into R 2.4.0 but it seems that the 
  install had little effect...
 
 
   install.packages(c(shapefiles))
  --- Please select a CRAN mirror for use in this session ---
  trying URL 
  'http://cran.dk.r-project.org/bin/windows/contrib/2.4/shapefiles_0.5.zip'
  Content type 'application/zip' length 42335 bytes
  opened URL
  downloaded 41Kb
  package 'shapefiles' successfully unpacked and MD5 sums checked
  The downloaded packages are in
  C:\TEMP\RtmpMz5Pqb\downloaded_packages
  updating HTML package descriptions
 
 library(shapefiles)
 
dbf - read.dbf(test.dbf)
  Error: could not find function read.dbf
  
 
  Note thet the last line contains an error.
 
 
  Is the package installed or not?
 
 yes. The book (package) is in the library (is is installed). But you need 
 to take it from the shelf and open it to read (load it into R via 
 `library(pkgname)').

Yes, rather a FAQ, and certainly the cause of the questioner's problem. 
Perhaps reading sections 5.2 and 5.3 of the R FAQ? Or looking at the 
Windows Packages menu a bit more carefully? Reading what sessionInfo() 
says?

Roger

 
 Best wishes,
 
 Torsten
 
  How do I get access to use the functionality it offers??
 
  :-? Martin Hvidberg
 
  [[alternative HTML version deleted]]
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to find further informations on specific options?

2006-10-31 Thread Roger Bivand
On Wed, 1 Nov 2006, zhijie zhang wrote:

 Dear friends,
   When i read the R-help , i often find the following case:
 e.g.:surf.gls(np, covmod, x, y, z, nx = 1000, ...)  #Package Spatial:
 
 Arguments:
 
   covmod: function to evaluate covariance or correlation function
* ...: parameters for 'covmod'*
 
 How should i find the further information on *...: parameters for 'covmod'* 
 ?
  I use the ?covmod, but can't find the information.
 Could anybody give me the general method to do so?

The spatial package is documented in full in Venables  Ripley (2002)  
Modern Applied Statistics with S, Chapter 15, section 2, pp. 425-430 (in
the References section of the help page).  However, on ?surf.gls, the See
Also section provides links to help pages describing expcov, gaucov, and
sphercov, so looking at See Also seems to be the general method you need.

 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] for importing data

2006-10-30 Thread Roger Bivand
On Mon, 30 Oct 2006, amna khan wrote:

 *I am a very new user of R. I've spent several hours trying to import
 data, so I feel okay asking the list for help. *
 *I had an Excel file,  then I turned it into a tab-delimited file, as
 instructed by directions My
 filename is lahore.txt I amusing the following commands for read.delim but
 i am getting following mesages. Sir i am sending you my excel data file i
 request you to   please write the right read.delim function for  importing
 data file after transforming it into a tab-delimited form.*
 
 lahore-read.delim(lahore.txt)
 Error in file(file, r) : unable to open connection
 In addition: Warning message:
 cannot open file 'lahore.txt', reason 'No such file or directory'

I am sure that your experience is familiar to many of us, especially those 
using R with beginners. 

From the error messages, you can see that the file is not present where R 
is looking for it. R is looking in your working directory - use getwd() to 
see what that is. setwd() will let you move to the correct directory - 
please use / as the separator on the directory path.

The function list.files() will show the files in the directory. If you are
using Windows, it is further likely that the file is not actually called
what you named it (Windows can add extra .* extensions which you do not
see unless you have told Windows Explorer to show them).

On Windows, you can use file.choose() to find the file visually, but it is 
usually better to learn the direct methods, because they are recorded in 
your session history, which you can save as documentation of your work - 
something that is extremely useful if you return to a project after some 
days, and (like me) cannot remember what you clicked.

Hope this helps,

Roger

 
 Regards
 
 AMINA SHAHZADI*.*
 Department of Statistics
 GC University Lahore, Pakistan.
 Email:
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] any good way to convert sp class objects to splancs object

2006-10-25 Thread Roger Bivand
On Wed, 25 Oct 2006, Dylan Beaudette wrote:

 Greetings:
 
 are there any simple ways to convert an sp class object to a splancs ppp
 class object, outside of reading the coordinates and computing a
 bounding box?

Aren't ppp class objects from the spatstat package? Have you tried the 
spspatstat wrapper package on the R-spatial sourceforge repository? The 
as() coerce method should get you there.

If you really mean splancs, there are not wrappers yet, but are on their 
way.

(Consider posting on R-sig-geo for specific questions like this).

Roger

 
 cheers,
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] one is not one

2006-10-21 Thread Roger Bivand
On Sat, 21 Oct 2006, Patrick Giraudoux wrote:

 Folks,
 
 I have got a strange behaviour when testing this:
 
 sum(x) != 1

FAQ 7.31 Why doesn't R think these numbers are equal?:

print(sum(x), digits=20)
identical(sum(x), 1)
all.equal(sum(x), 1)


 
 let us set
 
 x-c(70,134,1,5,0)
 
 and transform it in a vector of probabilities
 
 x-x/sum(x)
 
 One expect  sum(x) should be equal to 1, which is apparently the case
 
  sum(x)
 [1] 1
 
 However, when I try to test it I get:
 
  if(sum(x) !=1) print(lost) else (OK)
 [1] lost
 
 Which means that actually sum(x) is NOT considered equal to 1...
 
 Any idea about what is going wrong?
 
 Patrick
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ReadLines question

2006-10-21 Thread Roger Bivand
On Sat, 21 Oct 2006, Jonathan Greenberg wrote:

 I'm getting the following error:
 
  headerinfo=readLines(met_station_file,n=8)
  headerinfo
 [1] Plot Title: tahoe met validation ,,,
 [2]Error: invalid multibyte string


 
 met_station_file's first 8 lines are as follows:
 
 Plot Title: tahoe met validation ,,,
 #,Time, GMT-07:00,Temp, ƒF,Coupler Attached,Host Connected,Coupler
 ^^^

or whatever this looks like to you (was ^Ã for me in LC_CTYPE=en_GB) is a 
multibyte string. Is there a mismatch between the encoding (see ?locales) 
of the file and the machine into which you are reading? 

 Detached,Stopped,End Of File
 34,10/1/2005 0:00,49.937,
 35,10/1/2005 0:30,47.266,
 36,10/1/2005 1:00,47.446,
 37,10/1/2005 1:30,47.982,
 38,10/1/2005 2:00,48.517,
 39,10/1/2005 2:30,49.228,
 
 Why am I getting this error?  Are those quotation marks causing the hiccup?
 If so, how do I get around this programmatically?
 
 --j
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ReadLines question

2006-10-21 Thread Roger Bivand
On Sat, 21 Oct 2006, Jonathan Greenberg wrote:

 That looks to me like an infinity sign (I have no idea why that is part of
 the header of this file, but it is there).  How do I modify the encoding to
 read this in? 

The problem is the degree sign. Under linux:

$ file tmp/Marlette_lake_snotel.csv
tmp/Marlette_lake_snotel.csv: ISO-8859 text, with CRLF, CR line terminators

so probably the conversion to multibyte is happening on your reading 
platform. Reading the file into 2.4.0 on Windows with a Norwegian 1252 
setting (Sys.getlocale()), I see the degree sign.

If you know the column names anyway, jump over the header and 
insert them yourself. Alternatively filter the non-ASCII character out 
before reading, it looks predictably like a degree sign. In any case, the 
character is not very practical in a column name.

Roger

 
 --j
 
 
 On 10/21/06 4:33 AM, Roger Bivand [EMAIL PROTECTED] wrote:
 
  On Sat, 21 Oct 2006, Jonathan Greenberg wrote:
  
  I'm getting the following error:
  
  headerinfo=readLines(met_station_file,n=8)
  headerinfo
  [1] Plot Title: tahoe met validation ,,,
  [2]Error: invalid multibyte string
  
  
  
  met_station_file's first 8 lines are as follows:
  
  Plot Title: tahoe met validation ,,,
  #,Time, GMT-07:00,Temp, ƒF,Coupler Attached,Host Connected,Coupler
   ^^^
  
  or whatever this looks like to you (was ^Ã for me in LC_CTYPE=en_GB) is a
  multibyte string. Is there a mismatch between the encoding (see ?locales)
  of the file and the machine into which you are reading?
  
  Detached,Stopped,End Of File
  34,10/1/2005 0:00,49.937,
  35,10/1/2005 0:30,47.266,
  36,10/1/2005 1:00,47.446,
  37,10/1/2005 1:30,47.982,
  38,10/1/2005 2:00,48.517,
  39,10/1/2005 2:30,49.228,
  
  Why am I getting this error?  Are those quotation marks causing the hiccup?
  If so, how do I get around this programmatically?
  
  --j
  
  
 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ReadLines question

2006-10-21 Thread Roger Bivand
On 21 Oct 2006, Peter Dalgaard wrote:

 Roger Bivand [EMAIL PROTECTED] writes:
 
  On Sat, 21 Oct 2006, Jonathan Greenberg wrote:
  
   That looks to me like an infinity sign (I have no idea why that is part of
   the header of this file, but it is there).  How do I modify the encoding 
   to
   read this in? 
  
  The problem is the degree sign. Under linux:
  
  $ file tmp/Marlette_lake_snotel.csv
  tmp/Marlette_lake_snotel.csv: ISO-8859 text, with CRLF, CR line terminators
  
  so probably the conversion to multibyte is happening on your reading 
  platform. Reading the file into 2.4.0 on Windows with a Norwegian 1252 
  setting (Sys.getlocale()), I see the degree sign.
 
 Nono, there is no conversion. R is _expecting_ a multibyte sequence
 (utf8 most likely) and finding something that isn't part of one.  
 
 The fix should be something close to
 
 read.csv(file(tmp/Marlette_lake_snotel.csv), encoding=iso-8859-1) 
 

Yes, thanks:

read.csv(file(tmp/Marlette_lake_snotel.csv, encoding=iso-8859-1), 
 skip=1, check.names=FALSE) 

gives usable results on Linux/en_GB and Win/Norwegian (Bokmål) 1252.


 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] conversion of LL coordenates to UTM problems (ED50-WGS84 format)

2006-10-18 Thread Roger Bivand
On Wed, 18 Oct 2006, Berta wrote:

 Hi R-Users, I have plotted a region whose polygon coordinates are given
 in shp format ED50 UTM (zone=30) ) using readShapePoly in
 library(maptools).
 
 Now I need to plot a set of points in that region (my.dataframe, with X
 and Y geographic coordinates), which have been read using GPS in
 Longitud-Latitud form (using WGS84 system), so I first need to convert
 these Longitud-Latitud data into UTM data. To do so, I use package
 PBSmapping:
 
 attr(my.dataframe,  projection) -LL
 attr(my.dataframe, zone) - 30
 my.dataframe-as.PolySet(my.dataframe)
 my.dataframeUL-convUL(my.dataframe)
 
 obtaining the UTM coordinates. But when I plot them in the polygon
 region, points seem to be badly located.  I suspect it is due to the
 ED50 UTM of the polygon versus WGS84 coordenates of the points. If this
 is the problem, is there a way to convert them into the same format? It
 it is not the problem, what am I doing wrong?

If the differences are in a few hundreds of metres, not transforming 
between ellipsoid definitions is the most likely cause.

If you are willing to use the rgdal package, you will find the ED50 UTM 
zone 30 string is:

+proj=utm +zone=30 +ellps=intl +units=m towgs84=-87,-98,-121,0,0,0,0

and the WGS84/LL string is 

+proj=longlat +datum=WGS84

Then for your GPS data as a SpatialPointsDataFrame with its coordinate 
reference system set, spTransform() should do what you want. See also the 
note by Edzer Pebesma and myself in R News in November 2005 on sp classes.

Please consider following this up on the R-sig-geo list.

 
 Thanks a lot in advance. 
 Berta. 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem loading SpareM package

2006-10-12 Thread Roger Bivand
On Thu, 12 Oct 2006, Coomaren Vencatasawmy wrote:

 Hi,
  I have just installed R 2.4.0 and when I try to load SpareseM, I get
 the following error message
  
 library(SparseM)
 Package SparseM (0.71) loaded.  To cite, see citation(SparseM)
 Error in loadNamespace(package, c(which.lib.loc, lib.loc), keep.source = 
 keep.source) : 
 in 'SparseM' methods specified for export, but none defined: 
 as.matrix.csr, as.matrix.csc, as.matrix.ssr, as.matrix.ssc, as.matrix.coo, 
 as.matrix, t, coerce, dim, diff, diag, diag-, det, norm, chol, backsolve, 
 solve, model.matrix, model.response, %*%, %x%, image
 Error: package/namespace load failed for 'SparseM'
 

Please re-install the package. All contributed packages using new-style 
classes need to be re-installed because the internal representation of 
such classes and methods has changed, see CHANGES TO S4 METHODS in NEWS. 
Doing:

update.packages(checkBuilt = TRUE)

will check your libraries for packages built under previous releases and 
replace them with ones built for the platform release.

  
 I have contacted the package maintainers and they couldn't be of any help.
  
 I do not recall getting this error in older R versions.
  
 Regards
  
 Coomaren
 
 Send instant messages to your online friends http://uk.messenger.yahoo.com 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Rank Function

2006-10-10 Thread Roger Bivand
On Tue, 10 Oct 2006, Gabor Grothendieck wrote:

 Because y[1] and y[5] are not the same in Part1 but are in Part2:
 
  # using y from Part1
  y[5] - y[1]
 [1] 1.110223e-16

Yes, this is FAQ 7.31: Why doesn't R think these numbers are equal?

 i-1.94
 d-2.62-i
 print(0.68, digits=16)
[1] 0.68
 print(d, digits=16)
[1] 0.6802
 identical(d, 0.68)
[1] FALSE
 all.equal(d, 0.68)
[1] TRUE

with the internal rank function ignoring numeric fuzz.

 
 You could round your numbers to 2 digits, say:
 
  rank(round(100*y)) # y is from Part1
 [1] 3.5 5.0 1.0 2.0 3.5
 
 
 On 10/10/06, Li Zhang [EMAIL PROTECTED] wrote:
  Does anyone know why the two rank functions gives
  different results? I need to use the rank function in
  a for loop, so the sequence to be ranked is given
  values in the form of part (1). How can I use
  assignment like in part (1) to get correct ranks as in
  part (2)?
 
  Thank You
 
 
 
  Part (1)
  i-1.94
  b-0.95-i
  c-1.73-i
  d-2.62-i
 
  y-c(0.68,0.95,b,c,d)
 
  y
  0.68  0.95 -0.99 -0.21  0.68
 
  rank(y)
  3 5 1 2 4
 
  Part(2)
  rank(c(0.68,0.95,-0.99,-0.21,0.68))
  3.5 5.0 1.0 2.0 3.5
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Probability of exceedance function question

2006-10-09 Thread Roger Bivand
On Sun, 8 Oct 2006, Thomas P. Colson wrote:

 I am able to convert the flow accumulation grid into an area (for each
 pixel) grid, then import this into R as an ASCII file. The plot(ecdf)
 function in R seems to plot the opposite: curve starts at probability 0, for
 drainage area 0, should be the other way? 

In your initial posting, you asked for P(A  A*), plot(ecdf()) is giving 
P(A = A*), so:

plot(t1, pch=., axes=FALSE)
axis(1) 
box()
axis(2, at=axTicks(2), labels=rev(axTicks(2)))

lets you reverse the vertical axis labels. There is a section on ECDF in 
Jacoby's Statistical graphics for univariate and bivariate data (Sage, 
1997). ECDF are also the hypsometric integral, etc., they just keep 
getting re-invented. See also a helpful reply on the hypsometric interval 
from a couple of years ago:

http://tolstoy.newcastle.edu.au/R/help/03b/2746.html

 
 About 150,000 data points in these sets, ecdf curve plots in about 15
 seconds. 

But are there 150K drainage basins? Mocking this up in GRASS with 
spearfish:

r.mapcalc 'MASK=!isnull(elevation.dem)'
r.watershed elev=elevation.dem threshold=100 stream=stream.map1 basin=basin.map1

and reading the output into R, I have a SpatialGridDataFrame with 302418 
raster cells. To get basin area:

basins - split(basin.map$basin.map1, basin.map$basin.map1)
cell_count - sapply(basins, length)

(just 1422 basins) and multiply by 30*30 (resolution) to get area. I think
your Arc ASCII grid contains basin ID numbers, so you'll need to split on
the IDs first, then count the lengths of the cells in each basin and
multiply by cell area (20ft by 20ft).

By the way, you can read an Arc ASCII grid into a SpatialGridDataFrame 
with function readAsciiGrid() in package maptools, so for you:

basin.map - readAsciiGrid(c:/temp/area.asc, colname=basinID)
basins - split(basin.map$basinID, basin.map$basinID)
length(basins) # sanity check
cell_count - sapply(basins, length)
basin_area - cell_count * 20 * 20
t1 - ecdf(basin_area)
plot(t1, pch=., axes=FALSE) # and set xlab=, ylab=, main=
axis(1)
box()
grid()
axis(2, at=axTicks(2), labels=rev(axTicks(2)))

probably gets you there. There is a list (R-sig-geo) for these kinds of 
questions that you might consider using, there are a fair number of 
people using R with GIS.

Roger

 
 
 Could the problem be, how I'm importing the data from ascii grid? Cellsize
 is 20 ft and z is the drainage area, for each cell (flow weighted)
 
  area - read.table(file = c:/temp/area.asc, sep =  , na.strings =
 -, skip = 6) 
 area - area[,-ncol(area)] 
 xLLcorner - 1985649.0700408898
 yLLcorner - 841301.04004059616
 cellsize -20
 xURcorner - xLLcorner + (cellsize * (ncol(area) - 1)) 
 xLRcorner - xURcorner 
 xULcorner - xLLcorner
 yULcorner - yLLcorner + (cellsize * (nrow(area) - 1)) 
 yURcorner - yULcorner 
 yLRcorner - yLLcorner 
 coordsa - expand.grid(y = seq(yULcorner, yLRcorner, by = -20),x =
 seq(xULcorner, xLRcorner, by = 20))
 area- data.frame(coordsa, tmin = as.vector(c(area,recursive = T))) 
 names(area)-c(x,y,z)
 Plot(ecdf(area$z))
 
 
 -Original Message-
 From: Roger Bivand [mailto:[EMAIL PROTECTED] 
 Sent: Sunday, October 08, 2006 4:37 PM
 To: Thomas P. Colson
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Probability of exceedance function question
 
 On Sun, 8 Oct 2006, Thomas P. Colson wrote:
 
  I'm trying to calculate a cumulative area distribution (graph) of 
  drainage areas. This is defined as P(A  A*). Simple in principle. I 
  can do this in excel, with COUNTIF, which will count the number of 
  cells in the row area that have area A, then determine, for each 
  cell in the row area, how many cells exceede that area, then dividing 
  that number by the total number of cells, which gives me the 
  probability that drainage area A exceeds drainage area A*.
 
 Is this ecdf() of the vector or its suitable subset? If so, it runs very
 fast even for large data sets. For plotting, bear in mind that you are
 generating a lot of output, though:
 
  t0 - runif(10)
  system.time(t1 - ecdf(t0))
 [1] 0.222 0.022 0.248 0.000 0.000
  system.time(plot(t1, pch=.))
 [1] 1.089 0.079 1.186 0.000 0.000
 
 isn't at all bad!
 
  
  E.g, drainage area of 6 sq meters (One DEM grid cell) has a high 
  probability of exceedance(.99), while a drainage area of 100,000 
  square meters has a low probability of exceedance (.001).
  
  I wish to plot this relationship, and we all know that excel is not 
  the tool of choice when working with hundreds of thousands of records. 
  I'd like to port the CAD into a few R functions that I've already 
  developed for other tests as well.
  
  So my challenge, in R, is to
  (1)count the number of rows in column Area that have AREA(*),
  
  (2) determine, by row, how many rows have an area greater than the 
  area given in that one row
  
  (3) divide step 2 by number of rows (how can I do a row count and port 
  that to a variable, as I have to do this on 10 datasets?)
  
  Thanks for any advice you can offer

Re: [R] merge and polylist

2006-10-09 Thread Roger Bivand
On Mon, 9 Oct 2006, Mihai Nica wrote:

 The answer to all your questions is simple. By the time I get a little
 grasp on things, they become deprecated :-). But my programming skills
 are so low, that I find this normal.

 My problem comes from the last two #comment lines :

 #(if data row names do not match polygon IDs, will reorder, or fail if 
 # any differ or absent

 The two data row names differ and some are absent, that's why I used
 merge (and posted on this list, not on r-sig-geo :-)). How else can I
 intersect the two data.frames?

Yes, use merge, but do look carefully at both of the input data frames, 
the by.x= and by.y= columns, and the output data frame. The sp classes 
give an ID to each polygon:

sapply(slot(object, polygons), function(x) slot(x, ID))

and that has to be identical to the row names of the output data frame - 
but can be in a different order. Constructing the SpatialPolygonsDataFrame 
will put the data frame rows in the order of the polygons.

Roger


 Thanks so much for your help!


- Original Message 
From: Roger Bivand [EMAIL PROTECTED]
To: Mihai Nica [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Sent: Sunday, October 8, 2006 3:10:16 PM
Subject: Re: [R] merge and polylist

On Sat, 7 Oct 2006, Mihai Nica wrote:

 Greetings:
 
 I would like to kindly ask for a little help. The rough code is:
 

Maybe R-sig-geo would be a more relevant list. Comments inline.

 #
 
 dat=data.frame(read.delim(file=all.txt, header = TRUE, sep = \t,
 quote=\, dec=.,na.strings = NA))

We do not know if dat is in the same order as the shapefile. If dat$cod is 
malformed wrt. nc$att.data$AREA (very strange choice, in ESRI generated 
files often the polygon area), you are asking for trouble.

 
 nc=read.shape(astae.shp, dbf.data=TRUE, verbose=TRUE)
 
 mappolys=Map2poly(nc)
 
 submap - subset(mappolys, nc$att.data$NAME!=Honolulu, HI)
 
 nc$att.data=subset(nc$att.data, nc$att.data$NAME!=Honolulu, HI)
 

In situations like this, overwriting the input is not advisable, bercause
you destroy your ability to check that the output corresponds to your
intentions.
  
 nc$att.data[,1]=as.numeric(paste(nc$att.data$MSACMSA))
 
 #attributes(nc$att.data)
 
 nc$att.data=merge(nc$att.data, dat, by.x=AREA, by.y=cod, all.x=TRUE,
 sort=FALSE)

Ditto.

 
 #attributes(nc$att.data)
 
 tmp=file(tmp)
 
 write.polylistShape(submap, nc$att.data, tmp)
 

Any good reason for not using the sp class framework? The objects you are 
using here are very low-level and messy.

library(maptools)
nc_1 - readShapePoly(system.file(shapes/sids.shp, package=maptools)[1],
  ID=FIPS) # put shapefile in SpatialPolygonsDataFrame
nc_2 - nc_1[coordinates(nc_1)[,1]  -80,] # subset with [ method
row.names(as(nc_2, data.frame))
as.character(nc_2$FIPS)
tmpfl - paste(tempfile(), dbf, sep=.)
download.file(http://spatial.nhh.no/misc/nc_xtra.dbf;;, tmpfl, mode=wb)
nc.df - read.dbf(tmpfl) # extra data keyed on CNTY_ID
nc_2$CNTY_ID
nc.df$CNTY_ID
nc_df2 - merge(as(nc_2, data.frame), nc.df, by=CNTY_ID, sort=FALSE)
all.equal(nc_df2$CNTY_ID, nc_2$CNTY_ID)
row.names(nc_df2) - nc_df2$FIPS # re-instate IDs
nc_3 - SpatialPolygonsDataFrame(as(nc_2, SpatialPolygons), data=nc_df2)
# (if data row names do not match polygon IDs, will reorder, or fail if 
# any differ or absent
writePolyShape(nc_3, nc_3)

This still isn't as tidy as it could be, but gives much more control than 
the original old-style classes.

Roger


 #_
 
 All works fine, but merge() changes the rownames and the link between the
 polygons and the corresponding rows is lost. I tried numerous other
 solutions (such as to paste back the old rownames), to no avail. After a
 few days, here I am. Please, if you have a moment, send a tip.
 
  Thanks,
 
  mihai
 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.








-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] merge and polylist

2006-10-08 Thread Roger Bivand
On Sat, 7 Oct 2006, Mihai Nica wrote:

 Greetings:
 
 I would like to kindly ask for a little help. The rough code is:
 

Maybe R-sig-geo would be a more relevant list. Comments inline.

 #
 
 dat=data.frame(read.delim(file=all.txt, header = TRUE, sep = \t,
 quote=\, dec=.,na.strings = NA))

We do not know if dat is in the same order as the shapefile. If dat$cod is 
malformed wrt. nc$att.data$AREA (very strange choice, in ESRI generated 
files often the polygon area), you are asking for trouble.

 
 nc=read.shape(astae.shp, dbf.data=TRUE, verbose=TRUE)
 
 mappolys=Map2poly(nc)
 
 submap - subset(mappolys, nc$att.data$NAME!=Honolulu, HI)
 
 nc$att.data=subset(nc$att.data, nc$att.data$NAME!=Honolulu, HI)
 

In situations like this, overwriting the input is not advisable, bercause
you destroy your ability to check that the output corresponds to your
intentions.
  
 nc$att.data[,1]=as.numeric(paste(nc$att.data$MSACMSA))
 
 #attributes(nc$att.data)
 
 nc$att.data=merge(nc$att.data, dat, by.x=AREA, by.y=cod, all.x=TRUE,
 sort=FALSE)

Ditto.

 
 #attributes(nc$att.data)
 
 tmp=file(tmp)
 
 write.polylistShape(submap, nc$att.data, tmp)
 

Any good reason for not using the sp class framework? The objects you are 
using here are very low-level and messy.

library(maptools)
nc_1 - readShapePoly(system.file(shapes/sids.shp, package=maptools)[1],
  ID=FIPS) # put shapefile in SpatialPolygonsDataFrame
nc_2 - nc_1[coordinates(nc_1)[,1]  -80,] # subset with [ method
row.names(as(nc_2, data.frame))
as.character(nc_2$FIPS)
tmpfl - paste(tempfile(), dbf, sep=.)
download.file(http://spatial.nhh.no/misc/nc_xtra.dbf;, tmpfl, mode=wb)
nc.df - read.dbf(tmpfl) # extra data keyed on CNTY_ID
nc_2$CNTY_ID
nc.df$CNTY_ID
nc_df2 - merge(as(nc_2, data.frame), nc.df, by=CNTY_ID, sort=FALSE)
all.equal(nc_df2$CNTY_ID, nc_2$CNTY_ID)
row.names(nc_df2) - nc_df2$FIPS # re-instate IDs
nc_3 - SpatialPolygonsDataFrame(as(nc_2, SpatialPolygons), data=nc_df2)
# (if data row names do not match polygon IDs, will reorder, or fail if 
# any differ or absent
writePolyShape(nc_3, nc_3)

This still isn't as tidy as it could be, but gives much more control than 
the original old-style classes.

Roger


 #_
 
 All works fine, but merge() changes the rownames and the link between the
 polygons and the corresponding rows is lost. I tried numerous other
 solutions (such as to paste back the old rownames), to no avail. After a
 few days, here I am. Please, if you have a moment, send a tip.
 
  Thanks,
 
  mihai
 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Probability of exceedance function question

2006-10-08 Thread Roger Bivand
On Sun, 8 Oct 2006, Thomas P. Colson wrote:

 I'm trying to calculate a cumulative area distribution (graph) of drainage
 areas. This is defined as P(A  A*). Simple in principle. I can do this in
 excel, with COUNTIF, which will count the number of cells in the row
 area that have area A, then determine, for each cell in the row area, how
 many cells exceede that area, then dividing that number by the total number
 of cells, which gives me the probability that drainage area A exceeds
 drainage area A*. 

Is this ecdf() of the vector or its suitable subset? If so, it runs very 
fast even for large data sets. For plotting, bear in mind that you are 
generating a lot of output, though:

 t0 - runif(10)
 system.time(t1 - ecdf(t0))
[1] 0.222 0.022 0.248 0.000 0.000
 system.time(plot(t1, pch=.))
[1] 1.089 0.079 1.186 0.000 0.000

isn't at all bad!

 
 E.g, drainage area of 6 sq meters (One DEM grid cell) has a high probability
 of exceedance(.99), while a drainage area of 100,000 square meters has a low
 probability of exceedance (.001). 
 
 I wish to plot this relationship, and we all know that excel is not the tool
 of choice when working with hundreds of thousands of records. I'd like to
 port the CAD into a few R functions that I've already developed for other
 tests as well.  
 
 So my challenge, in R, is to 
 (1)count the number of rows in column Area that have AREA(*), 
 
 (2) determine, by row, how many rows have an area greater than the area
 given in that one row 
 
 (3) divide step 2 by number of rows (how can I do a row count and port that
 to a variable, as I have to do this on 10 datasets?)
 
 Thanks for any advice you can offer to this endevour
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] (no subject)

2006-10-07 Thread Roger Bivand
  result$dist_m-sqrt(((coord$x_utm-result$x_rdm)^2+
  (coord$y_utm-result$y_rdm)^2))
 result
 
 Best wishes,
 Ted.
 
 
 E-Mail: (Ted Harding) [EMAIL PROTECTED]
 Fax-to-email: +44 (0)870 094 0861
 Date: 07-Oct-06   Time: 09:53:43
 -- XFMail --
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] compiling rgdal package on windows / macos

2006-10-05 Thread Roger Bivand
On Wed, 4 Oct 2006, Dylan Beaudette wrote:

 Greetings:
 
 As I am not a windows user, I cannot try this: is it possible to install
 rgdal on windows without having to compile it from source ?

Andy Jaworski already replied that rgdal Windows binaries are available 
from CRAN mirrors, thanks to Uwe Ligges.

 
 Compilation on MacOS is within my abilities, however each time i try and 
 install the rgdal package it dies complaining that it cannot find 
 gdal-config --- which was recently installed with GRASS. I have updated my 
 PATH environment variable, logged out, but R still cannot find the 
 gdal-config program.
 

For Mac OSX, please consult the detailed instructions on:

http://www.r-project.org/Rgeo - Maps (in the left navigation bar).

Hint: see the configure.args= argument of install.packages() and use 
--with-gdal-config= to get the address right.

No Mac OSX binaries will be provided from CRAN, there are simply too many 
Mac OSX varieties out there to be sure that the installed external 
software harmonises with the rgdal binary build. However, one way of 
getting there is referenced in Rgeo, using William Kyngesburye's 
frameworks (rgdal binaries are provided in harmony with PROJ.4 and GDAL).

By the way:

RSiteSearch(rgdal macosx)

first hit takes you to a recent reply on this topic on the R-sig-geo list.

 any tips on getting the rgdal package up and running on MacOS or Windows
 would be greatly appreciated.
 
 Cheers,
 
 
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (installing on SUSE readline failure)

2006-10-02 Thread Roger Bivand
On Mon, 2 Oct 2006, John Kapsomenakis wrote:

 Dear friends

Please include an informative subject!

 
 I try to install R-project in SUSE 10.0 LINUX. 

Did you read the online version of the R Installation and Administration 
manual at:

http://cran.r-project.org/doc/manuals/R-admin.html

There you will find information in Appendix A about your problem. Please 
also check that you have the development RPMs installed as well as those 
providing readline as such. Appendix A does start with the reminder to:

Remember that some package management systems (such as RPM and deb) make 
a distinction between the user version of a package and the development 
version. The latter usually has the same name but with the extension 
`-devel' or `-dev': you need both versions installed.

 I run the ./configure. The last lines during the run is
 
 checking readline/history.h usability... no
 checking readline/history.h presence... no
 checking for readline/history.h... no
 checking readline/readline.h usability... no
 checking readline/readline.h presence... no
 checking for readline/readline.h... no
 checking for rl_callback_read_char in -lreadline... no
 checking for main in -lncurses... no
 checking for main in -ltermcap... no
 checking for main in -ltermlib... no
 checking for rl_callback_read_char in -lreadline... no
 checking for history_truncate_file... no
 configure: error: --with-readline=yes (default) and headers/libs are not
 available
 
 I'm now hoping for some help
 
 Thanks in advance.
 john
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] autologistic model? - what package?

2006-09-30 Thread Roger Bivand
On Sat, 30 Sep 2006, Sara Mouro wrote:

 Dear all,
 
 Could you pleas advise me on the following?
 
 I need to use general(ized) linear models (binomial distribution + logit
 link function) , to describe the preferred environment of each species (each
 sample is an individual in which I have measured several variables and also
 recorded the species it belongs to) 
 
  
 
 However,  must account for the spatial autrefoocorrelation between
 individuals.
 
  
 
 - So I think I need something like the so called autologistic models.
 isn't it?
 
 - What package would you advise me to use for that?
 

RSiteSearch(autologistic)

tells you what is known about this, which I'm afraid seems to be that no 
such function is available. Your question is very similar to the first hit 
in the site search, and that received no answer. 

If you are willing to try a different framework, the ME() Moran
eigenvector function in the spdep package is a possibility, albeit not yet
well-proven. It adds selected eigenvectors from a centred spatial weights
matrix to the RHS of the glm to whiten out spatial dependence, but it
will also whiten out or paint over other spatially patterned
mis-specification problems.

  
 
 Thank you in advance.
 
  
 
 Best regards,
 
 Sara Mouro
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Loading rgdal library

2006-09-29 Thread Roger Bivand
On Fri, 29 Sep 2006, Michael Rhead Enion wrote:

 I am trying to load the rgdal library in Mac OS X 10.4.7 (pismo g3  
 500 mhz).

This is not an R-help question, rather for R-sig-mac and/or R-sig-geo. 
Please review the archives of those lists, plus comments on the 
rgdal package on the Rgeo (www.R-project.org/Rgeo) site first page and 
under Maps, and if those do not resolve your problem, post to one of 
those lists, possibly also reporting how you solved the problem.

 
 I already loaded sp  and compiled rgdal successfully, such that rgdal  
 shows up in the package manager GUI.  But when I try to load rgdal, I  
 get the following error message:
 
 Error in dyn.load(x, as.logical(local), as.logical(now)) :
   unable to load shared library '/Users/rhead/Library/R/library/rgdal/ 
 libs/ppc/rgdal.so':
dlopen(/Users/rhead/Library/R/library/rgdal/libs/ppc/rgdal.so, 6):  
 no suitable image found.  Did find:
   /Users/rhead/Library/R/library/rgdal/libs/ppc/rgdal.so: mach-o, but  
 wrong architecture
 Error: package/namespace load failed for 'rgdal'
 
 Any help in fixing this problem would be appreciated.
 
 Thanks,
 
 Rhead
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] hcc not found, rcmd build

2006-09-29 Thread Roger Bivand
On Fri, 29 Sep 2006, Patrick Giraudoux wrote:

 
 Working under Windows XP, I am compiling a package called 'pgirmess' 
 with the command
 
 rcmd build --binary --auto-zip pgirmess
 
 I have this message error after having listed: functions text html latex 
 example chm
 
 zipping help file
 hcc: not found
 cp: cannot stat 'c:/TEMP/Rbuild365620874/pgirmess/chm/pgirmess.chm': No 
 such file or directory
 make[1]: *** [chm-pgirmess] Error 1
 make: *** [pkg-pgirmess] Error 2
 *** Installation of pgirmess failed ***
 
 I have recently installed MikTex 2.5 and Perl (I have been obliged to 
 format my hard disk and reinstall everything after a computer crash...).
 
 Has anyone an idea about what means hcc: not found and how to make hcc 
 available to the programme?

See: To build Windows help in:

http://www.murdoch-sutherland.com/Rtools/

where there is also a link to the Microsoft HTML Help Workshop, which 
doesn't seem to be on your path.

 
 Thanks in advance for any hint,
 
 Patrick
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Statistical data and Map-package

2006-09-26 Thread Roger Bivand
On Tue, 26 Sep 2006, Rense Nieuwenhuis wrote:

 Dear helpeRs,
 
 I'm working with the map-package and came upon a problem which I  
 couldn't solve. I hope onee of you can. If not, this can be seen as a  
 suggestion for new versions of the package.
 
 I'm trying to create a map of some European countries, filled with  
 colors corresponding to some values. Let's say I have the following  
 countries and I assign the following colors (fictional):
 
 country2001 - c(Austria, Belgium, Switzerland,  
 Czechoslovakia, Germany, Denmark, Spain, Finland, France,  
 UK, Greece, Hungary, Ireland, Israel, Italy,  
 Luxembourg, Netherlands, Norway, Poland, Portugal,  
 Sweden, Slovenia)
 color2001 - c(green, yellow,red,red, red, red, red,  
 red, green, red, red, red, red, red, red, red,  
 red, blue, red, red, red, orange)
 
 I then let the colors and the values correspond using 'match.map',  
 like this:
 
 match - match.map(world,country2001)
 color - color2001[match]
 
 And finally I plot the map. It works perfectly fine.
 
 map(database=world, fill=TRUE, col=color)
 
 
 But as I mentioned, I want to create a map of Europe. So, I use xlim  
 and ylim to let some parts of the world fall of the map. The syntax  
 becomes like this:
 
 map(database=world, fill=TRUE, col=color, xlim=c(-25,70),ylim=c 
 (35,71))
 
 Now, a problem arises. The regions on the map are colored by the  
 vector 'color'. It needs therefore to correspond to the order in  
 which the polygons are drawn. Since some of the full world-map isn't  
 drawn this time, the color-vector doesn't correspond anymore. This  
 results in the coloring of the wrong countries.
 
 Does anybody know of a way to solve this?

Within the maps package:

europe - map(database=world, fill=TRUE, plot=FALSE, 
  xlim=c(-25,70),ylim=c(35,71))
match - match.map(europe,country2001)
color - color2001[match]
map(database=world, fill=TRUE, col=color, xlim=c(-25,70),ylim=c(35,71))

but I'm afraid the world database precedes the dissolution of the Soviet 
Union, Czechoslovakia, and Yugoslavia, and doesn't code Sicily or Sardinia 
in Italy, so the result is perhaps not yet what you need:

europe$names[grep(Sicily, europe$names)] - Italy:Sicily
europe$names[grep(Sardinia, europe$names)] - Italy:Sardinia
match - match.map(europe,country2001)
color - color2001[match]
map(database=world, fill=TRUE, col=color, xlim=c(-25,70),ylim=c(35,71))

deals with Italy, but you won't get Slovenia. There was a discussion about 
this on the R-sig-geo list in March this year starting here:

http://finzi.psych.upenn.edu/R/Rhelp02a/archive/78303.html

or equivalently:

http://article.gmane.org/gmane.comp.lang.r.geo/299


 
 Thanks very much in advance,
 
 Rense Nieuwenhuis
   [[alternative HTML version deleted]]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
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: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   3   4   5   >