s-news
[Top] [All Lists]

Re: How to extract x and y from loess?

To: Kim Elmore <Kim.Elmore@noaa.gov>
Subject: Re: How to extract x and y from loess?
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Mon, 22 Sep 2003 08:25:49 -0500
Cc: S-News <s-news@wubios.wustl.edu>
In-reply-to: <5.2.0.9.2.20030921233351.01ea1560@129.15.69.4>
Organization: PDF Solutions, Inc.
References: <5.2.0.9.2.20030921233351.01ea1560@129.15.69.4>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)


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


<Prev in Thread] Current Thread [Next in Thread>