On 4/16/07, Paul Lynch <[EMAIL PROTECTED]> wrote:
> Suppose you have a vector of data in x and response values in y.  How
> do you plot together both the points (x,y) and the curve that results
> from the fitted model, if the model is not y ~ x, but a higher order
> polynomial, e.g. y~poly(x,2)?  (In other words, abline doesn't work
> for this case.)

I like the following scheme because it's concise:

u = rnorm(100)
v = u^2 + rnorm(100, sd = .2)

plot(u, v)
curve(predict(lm(v ~ poly(u, 2)), newdata = list(u = x)), add = TRUE)

The last line will only make sense when you realize that the symbol
'x' is special in curve().

-Deepayan

______________________________________________
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.

Reply via email to