Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I do a simple linear regression mod <- lm(y ~ x) and I plot its residuals, doing plot(mod$residuals). Two questions:

  1. I need to plot the line of the regression in the chart where I plotted the residuals, how can I do it?

  2. I need to know the points of this line, because I should plot this line in another application, so I need those points (as a vector), how can I do?

Thank you!

share|improve this question

2 Answers

up vote 3 down vote accepted

You can get the points with

predict(mod)
share|improve this answer

You can use abline. In your case, just add

abline(mod)
share|improve this answer
ok thanks! what about the points of that line ? How can I get them? – Dail Oct 2 '11 at 12:37
As long as you have mod stored, you don't need the points. But you can get them with coef(mod), I believe – Peter Flom Oct 2 '11 at 12:41
yes I know but i have to save the data (the list of points) how can i calculate them? is there a function? – Dail Oct 2 '11 at 12:53
You don't need a list of points. Just the coefficients; that's enough to plot a line. – Peter Flom Oct 2 '11 at 13:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.