[R] safe prediction from lm

From: Spencer Jones <ssj1364_at_gmail.com>
Date: Thu 28 Sep 2006 - 15:44:28 GMT

I am fitting a regression model with a bs term and then making predictions based on the model. According to some info on the internet at http://www.stat.auckland.ac.nz/~yee/smartpred/DummiesGuide.txt

there are some problems with using predict.lm when you have a model with terms such as bs,ns,or poly. However when I used one of the examples they said would illustrate the problems I get virtually the same results using the standard predict function and "safe prediction" method they propose. Has lm been updated so that it can handle terms such as bs,ns, and poly automatically? I am using R 2.3.0

this is their example:

n <- 100
set.seed(86) # For reproducibility of the random numbers

x <- sort(runif(n))
y <- sort(runif(n))
fit <- lm(y ~ bs(x, df=5))

plot(x, y,col="blue")
lines(x, fitted(fit), col="black")
newx <- seq(0, 1, len=n)
points(newx, predict(fit, data.frame(x=newx)), type="l", col=red, err=-1)



        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Sep 29 01:48:18 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 28 Sep 2006 - 17:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.