Skip to content
Prev 82282 / 398525 Next

strange behavior of loess() & predict()

On Tue, 2005-12-06 at 18:09 +0100, Leo GÃ¼rtler wrote:
<snip>
Not sure if this is the reason, but there is no argument x in
predict.loess, and:

a <- predict(mod, se = TRUE)

gives you the same results as:

b <- predict(mod, x=X, se=TRUE)

so the x argument appears to be being passed on/in the ... arguments and
ignored? As such, you have no newdata, so mod$x is used.

Now, when you do:

c <- predict(mod, data.frame(x=X), se=TRUE)

You have used an un-named argument in position 2. R takes this to be
what you want to use for newdata and so works with this data rather than
the one in mod$x as in the first case:

# now named second argument - gets ignored as in a and b
d <- predict(mod, x = data.frame(x=X), se=TRUE)

all.equal(a, b) # TRUE
all.equal(a, c) # FALSE
all.equal(a, d) # TRUE

# this time we assign X to x by using (), the result is used as newdata
e <-  predict(mod, (x=X), se=TRUE)

all.equal(c, e) # TRUE

If in doubt, name your arguments and check the help! ?predict.loess
would have quickly shown you where the problem lay.

HTH

G