[R] "Local trend surfaces" Ex from V&R MASS

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Fri Mar 7 16:37:38 CET 2003


On 07-Mar-03 ripley at stats.ox.ac.uk wrote:
> On Fri, 7 Mar 2003 Ted.Harding at nessie.mcc.ac.uk wrote:
>> Trying the "Local trend surfaces" example from p.437 of MASS
>> (3rd edn) by V&R, all goes well until the line
>> 
>> contour(topo.mar$x, topo.mar$y, topo.lo$fit,
>>         levels=seq(700,1000,25), xlab="fi t", ylab="")
>> 
>> which produces the response:
>> 
>>   Error in contour.default(topo.mar$x, topo.mar$y, topo.lo$fit,
>>   levels = seq(700,  : 
>>           no proper `z' matrix specified

Thanks, Brian! The extra command (at [***] below) solved it.

> ... it's an R/S difference in contour/loess (I forget which).

It looks as though the difference is in the behaviour of
"predict=predict.loess"): in S topo.lo$fit is a matrix-like object with
rows labelled as "x=x1", "x=x2" etc., cols labelled as "y=y1" etc., and
entries the fitted values (so it already has the requisite layout), which
from R the value of topo.lo$fit is simply a vector with as many elements
as there are prediction grid-points. Hence it needs to be reshaped into a
matrix (as in your extra command).

> You need to check the R scripts (library/MASS/scripts3 in your R
> installation) which give
> 
> topo.loess <- loess(z ~ x * y, topo, degree=2, span = 0.25,
> normalize=F)
> topo.mar <- list(x = seq(0, 6.5, dif), y=seq(0, 6.5, dif))
> topo.lo <- predict(topo.loess, expand.grid(topo.mar), se=T)
> [***] topo.lo$fit <- matrix(topo.lo$fit, length(topo.mar$x),
>                             length(topo.mar$y))
> contour(topo.mar$x,topo.mar$y,topo.lo$fit, levels = seq(700,1000,25),
>         xlab="fit", ylab="")

Many thanks!
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 07-Mar-03                                       Time: 15:37:38
------------------------------ XFMail ------------------------------



More information about the R-help mailing list