[R] safe prediction from lm
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Thu Sep 28 17:55:02 CEST 2006
Spencer Jones said the following on 9/28/2006 10:44 AM:
> 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.
Hi, Spencer,
That website is for S-PLUS and not R. When I run the code in S-PLUS 6.2,
I do indeed see different curves.
HTH,
--sundar
More information about the R-help
mailing list