Including a regression line

In Chapter 2, Advanced Functions in Base Graphics, we will cover Ordinary Least Squares (OLS) regressions and plotting regression lines. However, if you are curious as to how to include a regression line, this is how it is done. Use the abline() command (which draws lines) in conjunction with the lm() command, which performs a regression.

The syntax for performing a regression on the two variables is lm(Y ~ X), where the tilde sign instructs R to perform the regression, with Y as the dependent variable and X as the independent variable. Now include the following syntax on the command line:

abline(lm(Y ~ X))

The following is your plot with a regression line:

Including a regression line

We will cover more about regressions in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset