2026-10-27

Introduction

A simple linear regression will be used to determine if there is a correlation between engine displacement and horsepower. The study will ask if there is a positive correlation between the two variables. In other words will a larger engine displacement produce a car with more horsepower.

To better understand the relationship between the two variables, we should understand what engine displacment means. Engine displacement is the measure of volume of air and fuel that passes through all of the pistons in one cycle. Generally speaking, the more volume passed should result in the more horsepower. However, the car will likely burn more fuel. (Reference: https://en.wikipedia.org/wiki/Engine_displacement)

The data set utilized is the mtcars data set which is built into R.

The mtcars Data set

The mtcars data set is built into the R programming language. The data from mtcars is derived from the year 1974 from the US magazine Motor Trend. There are 32 car types surveyed in the mtcars dataset.
(Reference: https://www.rdocumentation.org/packages/datasets/versions/3.6.2/topics/mtcars)

The data below will show the first six rows and all the columns from the data set to provide a preview of the data.

##                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

Engine Displacement Bar Plot

Below is a bar plot showing the number of cars with corresponding engine displacement in cubic inches.

What is a simple linear regression?

A simple linear regression is used to understand a relationship between two variables. It will determine if a relationship exists between the two and if so how strong is that relationship.
The x-variable is the independent variable and the y-variable is the dependent. (Reference: https://www.scribbr.com/statistics/simple-linear-regression/)

For this analysis of the mtcars data set we will set engine displacement (cu. in.) as the x-variable and horsepower as the y-variable. We will see if there is a relationship using the regression equation.

Simple Linear Regression Equation

The equation for simple linear regression is:

\[\hat{Y} = a + bX\]

Where:

  • \(\hat{Y}\) = Predictive Horsepower
  • X = Engine Displacement
  • a = Y-intercept
  • b = Slope of the regression line

Engine Displacement vs. Horsepower

The following graph plots horsepower against engine displacement for the 32 automobiles included in the mtcars dataset.

Linear regression - Engine Displacement vs. Horsepower

The regression line shows the relationship between engine displacement and horsepower. The slope of the line is positive so there will be a positive correlation between the two variables.

Simple Linear Regression Line Calculation

The linear regression model function (lm()) from R will be utilized to calculate the linear regression equation. The R code displayed below shows the code used for the plot.

model = lm(hp ~ disp, data = mtcars) 

Results of Simple Regression Line Calculation

## 
## Call:
## lm(formula = hp ~ disp, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -48.623 -28.378  -6.558  13.588 157.562 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  45.7345    16.1289   2.836  0.00811 ** 
## disp          0.4375     0.0618   7.080 7.14e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 42.65 on 30 degrees of freedom
## Multiple R-squared:  0.6256, Adjusted R-squared:  0.6131 
## F-statistic: 50.13 on 1 and 30 DF,  p-value: 7.143e-08

Results of Simple Regression Line Calcuation

The results of the “lm()” command are shown on the prior slide. The estimate for the y-intercept is approxmately 46. The slope of the equation is approximately 0.4. The \(R^2\) value is 0.6 which means that approximately 60% of the variation in horsepower is related to engine displacement. The other 40% of variation is attributable to other factors.

Linear Regression Equation

The linear regression equation relating horsepower to engine displacement is as follows:

\[\hat{Y} = 45.7345 + 0.4375X\]

Where:

  • \(\hat{Y}\) = Predicted horsepower
  • X = Engine displacement (cu. in.)
  • Y-intercept = 45.7345
  • Slope = 0.4375

Interactive Regression Plot

The interactive plot shows the relationship between engine displacement and horsepower.

Move the mouse over the points to see the values of engine displacement and horsepowerfor each automobile.

Conclusion - Car that has the highest horsepower

The presentation helped to show a positive correlation between engine displacement and horsepower. However, there were anomalies. Below is the code determining the car with the largest engine displacement along with horsepower. The Maserati Bora is that particular car. Its two variables lie well above the regression line as an outlier. This outlier shows that other factors can affect horsepower, either improving it or limiting its value.

mtcars[mtcars$disp >= 290 & mtcars$disp <= 310 & mtcars$hp > 300, ]
##               mpg cyl disp  hp drat   wt qsec vs am gear carb
## Maserati Bora  15   8  301 335 3.54 3.57 14.6  0  1    5    8