Performing linear regression in R
For this section, we are going to perform linear regression in R, both in base R and by way of the tidymodels
framework. In this section, you will learn how to do this on a dataset that has different groups in it. We will do this because if you can learn to do it this way, then doing it in a single group becomes simpler as there is no need to group data and perform actions by group. The thought process here is that by doing it on grouped data, we hope you can learn an extra skill.
Linear regression in base R
The first example we are going to show is using the lm()
function to perform a linear regression in base R. Let’s dive right into it with the iris
dataset.
We will break the code down into chunks and discuss what is happening at each step. The first step for us is to use the library
command to bring in the necessary packages into our development environment:
library(readxl)
In this section, we’re loading a library called...