Kim Elmore wrote:
I'm trying to extract a 2-D fit from loess(). The formula is simply
response ~ input, where input has only one variable. Ideally, I'd like
to bootstrap loess(), but I can't even figure out how to explicitly
extract a simple 2-D fit. The function lowess() at least returns the x
and y values explicitly, but I can't fix the length of the returned
vectors. With the original data, I might get a length of n, but a
resampled version might return something different.
I'll happily entertain insights and suggestions about how to proceed.
Kim Elmore
Kim,
The "x" value from your loess fit is simply the "input" you mention
above. Thus, if you use "loess(response ~ input)" then loess will fit at
every point in "input". Here's an example:
x <- data.frame(x = runif(20))
x$y <- exp(-x$x) * sin(pi * x$x) + rnorm(20, 0, .1)
lo <- loess(y ~ x, data = x)
lo$x <- x$x[order(x$x)]
lo$y <- fitted(lo)[order(x$x)]
plot(x$x, x$y)
lines(lo$x, lo$y)
To find fits at more values of "x" then use "predict.loess"
lo$x <- seq(0, 1, length = 100)
lo$y <- predict(lo, data.frame(x = lo$x))
HTH,
-sundar
|