R- Users:
Can someone indicate what I am during wrong? This is a script essentially from
Venerable & Ripley's text on interpolating a surface with loess function
but I can not get it to run.
Thanks.
John Lewis
Professor
McGill University
Montreal
library(MASS)
library(modreg)
data(topo)
par(mfcol=c(2,2), pty="s")
topo.loess <- loess(z ~ x * y, topo, degree=2, span = 0.25, normalize=F)
topo.mar <- list(x = seq(0, 6.5, 0.1), y=seq(0, 6.5, 0.1))
topo.lo <- predict(topo.loess, expand.grid(topo.mar), se=T)
lo.1 <- as.data.frame(topo.lo)
lo.2 <- as.matrix(lo.1$fit)
lo.3 <- as.matrix(lo.1$se.fit)
contour(topo.mar$x,topo.mar$y,lo.2, levels = seq(700,1000,25),
xlab="fit", ylab="")
points(topo)
contour(topo.mar$x,topo.mar$y,lo.3, levels = seq(5, 25, 5),
xlab="standard error", ylab="")
title("Loess degree = 2")
points(topo)
This is the error I keep getting.
"Error in contour.default(topo.mar$x, topo.mar$y, lo.2, levels = seq(700,
:
no proper `z' matrix specified"
I received this same message when I ran the script first without changing
topo.lo
from a list to data.frame etc. as seen below.
contour(topo.mar$x,topo.mar$y,topo.lo$fit, levels = seq(700,1000,25),
xlab="fit", ylab="")
I checked the length of each variable and they are correct.
[[alternative HTML version deleted]]
Comments inline: john lewis wrote:> R- Users: > > Can someone indicate what I am during wrong? This is a script essentially from > Venerable & Ripley's text on interpolating a surface with loess function but I can not get it to run. > > Thanks. > John Lewis > Professor > McGill University > Montreal > > library(MASS) > library(modreg) > data(topo) > par(mfcol=c(2,2), pty="s") > topo.loess <- loess(z ~ x * y, topo, degree=2, span = 0.25, normalize=F) > topo.mar <- list(x = seq(0, 6.5, 0.1), y=seq(0, 6.5, 0.1)) > topo.lo <- predict(topo.loess, expand.grid(topo.mar), se=T) > lo.1 <- as.data.frame(topo.lo) > lo.2 <- as.matrix(lo.1$fit)I just listed "lo.2": It was a 4356 x 1 matrix; in S-Plus 6.1, it was a NULL matrix with 0 rows and 1 column. I recently attempted to upgrade to R 1.7.1 and now I can't get graphics from R. However, the following worked for me in S-Plus 6.1: lo.2 <- matrix(topo.lo$fit, nrow=66) With this, I got a plot that looked sensible (though I didn't compare it with MASS). hope this helps. spencer graves> > lo.3 <- as.matrix(lo.1$se.fit) > > contour(topo.mar$x,topo.mar$y,lo.2, levels = seq(700,1000,25), > > xlab="fit", ylab="") > > points(topo) > > contour(topo.mar$x,topo.mar$y,lo.3, levels = seq(5, 25, 5), > > xlab="standard error", ylab="") > > title("Loess degree = 2") > > points(topo) > > > This is the error I keep getting. > > "Error in contour.default(topo.mar$x, topo.mar$y, lo.2, levels = seq(700, : > no proper `z' matrix specified" > > I received this same message when I ran the script first without changing topo.lo > from a list to data.frame etc. as seen below. > > contour(topo.mar$x,topo.mar$y,topo.lo$fit, levels = seq(700,1000,25), > > xlab="fit", ylab="") > > > I checked the length of each variable and they are correct. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
The 'z' argument to contour must be a matrix with the appropriate dimensions -- lo.2 as defined originally has dimensions 4356 by 1. You can create a matrix of appropriate dimensions as follows: > lo.2 <- array(lo.1$fit, dim=sapply(topo.mar, length)) It's also probably worth changing topo.mar so that the x and y elements have different lengths, to provide a quick check that the x and y dimensions were not swapped somewhere along the way. hope this helps, Tony Plate At Monday 01:45 PM 7/21/2003 -0400, john lewis wrote:>R- Users: > >Can someone indicate what I am during wrong? This is a script essentially >from > >Venerable & Ripley's text on interpolating a surface with loess function >but I can not get it to run. > >Thanks. > >John Lewis > >Professor > >McGill University > >Montreal > > > >library(MASS) > >library(modreg) > >data(topo) > >par(mfcol=c(2,2), pty="s") > >topo.loess <- loess(z ~ x * y, topo, degree=2, span = 0.25, normalize=F) > >topo.mar <- list(x = seq(0, 6.5, 0.1), y=seq(0, 6.5, 0.1)) > >topo.lo <- predict(topo.loess, expand.grid(topo.mar), se=T) > >lo.1 <- as.data.frame(topo.lo) > >lo.2 <- as.matrix(lo.1$fit) > >lo.3 <- as.matrix(lo.1$se.fit) > >contour(topo.mar$x,topo.mar$y,lo.2, levels = seq(700,1000,25), > > xlab="fit", ylab="") > >points(topo) > >contour(topo.mar$x,topo.mar$y,lo.3, levels = seq(5, 25, 5), > > xlab="standard error", ylab="") > >title("Loess degree = 2") > >points(topo) > > >This is the error I keep getting. > >"Error in contour.default(topo.mar$x, topo.mar$y, lo.2, levels = seq(700, : > no proper `z' matrix specified" > >I received this same message when I ran the script first without changing >topo.lo >from a list to data.frame etc. as seen below. > >contour(topo.mar$x,topo.mar$y,topo.lo$fit, levels = seq(700,1000,25), > > xlab="fit", ylab="") > > >I checked the length of each variable and they are correct. > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-helpTony Plate tplate at acm.org
On Mon, 21 Jul 2003 13:45:39 -0400, "john lewis" <john.lewis at sympatico.ca> wrote :>R- Users: > >Can someone indicate what I am during wrong? This is a script essentially from > >Venerable & Ripley's text on interpolating a surface with loess function but I can not get it to run.That's Venables...>topo.lo <- predict(topo.loess, expand.grid(topo.mar), se=T) > >lo.1 <- as.data.frame(topo.lo) > >lo.2 <- as.matrix(lo.1$fit)The problem is here. lo.2 ends up being a matrix with dimensions 4356 by 1, because you didn't say what dimensions to use. Try this instead: lo.2 <- matrix(lo.1$fit, length(topo.mar$x), length(topo.mar$y)) Duncan Murdoch