In this introduction, we’ll explore simple linear regression using the built-in mtcars dataset, which includes attributes like car weight and fuel efficiency.
Our goal is to examine the relationship between car weight (wt) and miles per gallon (mpg). Why is this relationship important? Understanding how car weight affects fuel efficiency can provide insights into vehicle performance and energy consumption. If you’re in the market for a brand new car, this is data that could very well concern you. Let’s explore these insights using simple linear regression.
We start by loading the dataset and fitting a linear regression model where mpg is the dependent variable and wt is the independent variable.
# Load the 'mtcars' dataset
data("mtcars")
# Fit the linear model
model <- lm(mpg ~ wt, data = mtcars)
Let’s look at a summary of the model that we’ve constructed.