Skip to content

save LOESS regression line values in R

3 messages · Dragos Zaharescu, Owen Jones, Kingsford Jones

#
Hi Dragos,

It's not entirely clear what you'd like to do, but assuming you're
using stats::loess to create the fit, you can use the predict function
to generate predictions and then dput (or dump, save, write.table ...)
to save the output.  For example,

cars.lo <- loess(dist ~ speed, cars)
str(pred <- predict(cars.lo, data.frame(speed = seq(5, 30, 1)), se = TRUE))

List of 4
 $ fit           : num [1:26] 7.81 10.04 12.57 15.37 18.43 ...
 $ se.fit        : num [1:26] 7.57 5.94 4.98 4.52 4.32 ...
 $ residual.scale: num 15.3
 $ df            : num 44.6


# predict.loess has returned a list and the 'fit' element contains the
fitted values.
# dput can write these out to a text file:


dput(pred$fit, file = 'predfile.txt')


# And to retrieve, use dget

ret.pred <- dget(file = 'predfile.txt')


If you'd rather save a workspace with the object, see ?save.  To write
out a data frame see ?write.table.


hope it helps,

Kingsford Jones
On Mon, Dec 8, 2008 at 8:16 AM, Dragos Zaharescu <zaha_dragos at yahoo.com> wrote: