Skip to content
Back to formatted view

Raw Message

Message-ID: <4188FA35.5080801@pdf.com>
Date: 2004-11-03T15:33:09Z
From: Sundar Dorai-Raj
Subject: Newbie question:  plotting regression models
In-Reply-To: <D599F609-2DAA-11D9-9761-000A9591E11C@musc.edu>

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