[R] safe prediction from lm

Gabor Grothendieck ggrothendieck at gmail.com
Thu Sep 28 17:57:05 CEST 2006


See ?SafePrediction for how it works in R.

Also the example here:
http://www.mayin.org/ajayshah/KB/R/html/o9.html

On 9/28/06, Spencer Jones <ssj1364 at gmail.com> wrote:
> 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)
>
>
> thanks,
>
> Spencer
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list