[R] Mistake with contour...

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Dec 30 09:37:18 CET 2003


On Tue, 30 Dec 2003, v.demart at libero.it wrote:

> I'm reading Ripley-Venables "Modern Applied Statistics with S - Fourth edition" , at the same time trying  the examples proposed in the book using R 1.8.1 under linux.
> 
> Now  I'm trying the following  code from the book (example code of spatial statistics at page 76) with R :
> 
> | data(topo) library("spatial") topo.loess<-loess(z ~ x * y, topo,
> | degree= 2,span=0.25)
> | topo.mar<-list(x=seq(0,6.5,0.2),y=seq(0,6.5,0.2))
> | topo.lo=predict(topo.loess,expand.grid(topo.mar)) 

It does not say that!

> | par(pty="s")
> | contour(topo.mar$x,topo.mar$y,topo.lo,xlab="",ylab="",levels=seq(700,1000,25),cex=0.7)
> 
> and at the "contour" command the following error pops up:
> 
> Error in contour.default(topo.mar$x, topo.mar$y, topo.lo, xlab = "",
> ylab = "",  :
> ~    no proper `z' matrix specified
> 
> Being an R newbye I don't know what to do next to fix the problem.

Look in the R scripts provided to see the R version of the code.
.../library/MASS/scripts/ch04.R contains

topo.loess <- loess(z ~ x * y, topo, degree = 2, span = 0.25)
topo.mar <- list(x = seq(0, 6.5, 0.2), y=seq(0, 6.5, 0.2))
topo.lo <- predict(topo.loess, expand.grid(topo.mar))
topo.lo <- matrix(topo.lo, length(topo.mar$x),length(topo.mar$y))
par(pty = "s")       # square plot
contour(topo.mar$x, topo.mar$y, topo.lo, xlab = "", ylab = "",
  levels = seq(700,1000,25), cex = 0.7)

R's contour is not quite the same as the S original.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list