June 2016
Beginner to intermediate
1783 pages
71h 22m
English
In this recipe, we will learn how to fit a linear model and plot the linear regression line on a scatter plot.
All you need for the next recipe is to type it at the R prompt as we will only use some base functions. You can also save the recipe code as a script so that you can use it again later on.
Once again, let's use the mtcars dataset and draw a linear fit line for mpg versus disp:
plot(mtcars$mpg~mtcars$disp) lmfit<-lm(mtcars$mpg~mtcars$disp) abline(lmfit)

We first draw the basic scatter plot of mpg versus disp. Then, we fit a linear model to the data using the lm() function, ...
Read now
Unlock full access