[R] getting panel.loess to use updated version of loess.smooth

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Tue Jul 12 20:44:21 CEST 2005



Benjamin Tyner wrote:
> I'm updating the loess routines to allow for, among other things, 
> arbitrary local polynomial degree and number of predictors. For now, 
> I've given the updated package its own namespace. The trouble is, 
> panel.loess still calls the original code in package:stats instead of 
> the new loess package, regardless of whether package:loess or 
> package:lattice comes first in the search list. If I export panel.loess 
> from the new package, then it can't see grid.lines anymore.
> 
> I've tried using fixInNamespace to change the loess.smooth in 
> package:stats to point to the updated simpleLoess, but it is locked. At 
> http://tolstoy.newcastle.edu.au/R/help/04/05/0428.html it was suggested 
> to write a new panel function. However I still need to be able to access 
> grid.lines, and getFromNamespace("grid.lines","grid") is not the way to 
> do this.
> 
> Any ideas? This seems simple but I'm stumped.
> 
> Thanks,
> Ben
> 

Can you show us what you tried? It seems as simple as defining a new 
panel function:

panel.loess2 <- function (x, y, span = 2/3, degree = 1,
                           family = c("symmetric", "gaussian"),
                           evaluation = 50, lwd = add.line$lwd,
                           lty = add.line$lty, col,
                           col.line = add.line$col, ...) {
   x <- as.numeric(x)
   y <- as.numeric(y)
   if (length(x) > 0) {
       if (!missing(col)) {
           if (missing(col.line))
               col.line <- col
       }
       add.line <- trellis.par.get("add.line")
       #smooth <- loess.smooth(x, y, span = span, family = family,
       #                       degree = degree, evaluation = evaluation)
       smooth <- simpleLoess(x, y, span = span, family = family,
                             degree = degree, evaluation = evaluation)
       grid.lines(x = smooth$x, y = smooth$y, default.units = "native",
                  gp = gpar(col = col.line, lty = lty, lwd = lwd))
   }
}


--sundar




More information about the R-help mailing list