[S] Using predict() in higher frames.

Zirakzadeh, Alex (alex.zirakzadeh@csfb.com)
Mon, 18 May 1998 16:47:49 -0400


Dear Splus users:

I was hoping one of you can help me determine a way to use the predict
function in a higher frame. For example, in the same frame, I can use the
predict function to get the predicted value of an loess object.

> loess.test_loess(y~x,data=mydata)
> predict(loess.test,newdata=data.frame(x=98))
[1] 31.074

However, if I want to pass the loess object as an argument to another
function and recall the predict from within the function, I get an error. In
the following example, get.value is a function that reads in the loess
object and the newvalue, and it is supposed to return the predicted value.
However, as you can see, it does not work.

>get.value
function(object, ts, newvalue)
{
predict(object, newdata = data.frame(ts = newvalue))
}
> get.value(loess.test,x,98)
Error in loess.matrix(newdata, object$terms): Length of variable 1 is 403 !=
length of row names (1)
Dumped

I can always recreate the loess object again from within the function.
However, I rather not do this duplication.

Any suggestions for doing this? (maybe using one of the attributes of the
loess object??)

The reason for creating such a fucntion is to use finite difference methods
to calculate the slope and the curvature of the loess object.

Regards,

Alex Zirakzadeh

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news