[R] Newbie question: plotting regression models
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Wed Nov 3 16:33:09 CET 2004
adelmaas at MUSC.EDU wrote:
> Greetings.
>
> Is there any way to get R to take a regression model object and draw a
> plot of the regression function? How about overlaying that plot over a
> scatterplot of the actual data? Thanks in advance for any help anyone
> can provide.
>
> Aaron
>
Hi Aaron,
What type of "regression function" are your referring to? Linear model?
Non-linear model? The term "regression" is to ambiguous to really answer
your question. However, typically you should be able to do something like:
fit <- lm(y ~ x)
yhat <- predict(fit)
plot(x, y, ylim = range(c(y, yhat)))
lines(x, yhat)
If you are not using lm please provide more information than you already
have. You should read "Introduction to R" or any of the recommended
texts listed on the R website. Also read the posting guide.
--sundar
More information about the R-help
mailing list