October 25, 2026

The Question

Does horsepower help explain the price of a car?

  • Cars with more horsepower may cost more.
  • But does the data support this idea?
  • We will use simple linear regression to investigate the relationship.

Our goal: Use data, mathematics, and R to understand the relationship between horsepower and price.

The Statistical Idea

Simple linear regression describes the relationship between two quantitative variables.

  • Explanatory variable: Horsepower
  • Response variable: Price, measured in thousands of dollars
  • Method: Fit a straight line to the observed data.

The slope tells us how much the predicted car price changes for each additional unit of horsepower.

A regression relationship does not automatically mean that horsepower causes a car’s price to change.

Our Data

We use the Cars93 dataset from the MASS package. It contains information about 93 car models.

head(cars[, c("Manufacturer", "Model", "Price", "Horsepower")])
  Manufacturer   Model Price Horsepower
1        Acura Integra  15.9        140
2        Acura  Legend  33.9        200
3         Audi      90  29.1        172
4         Audi     100  37.7        172
5          BMW    535i  30.0        208
6        Buick Century  15.7        110
  • Horsepower measures engine power.
  • Price is measured in thousands of dollars.
  • Each point in our graphs represents one car model.

We will use these observations to study the relationship between horsepower and price.

Mathematics 1: The Regression Model

We model price as a linear function of horsepower:

\[ Y_i = \beta_0 + \beta_1 X_i + \varepsilon_i \]

Where:

  • \(Y_i\) is the price of car \(i\).
  • \(X_i\) is its horsepower.
  • \(\beta_0\) is the intercept.
  • \(\beta_1\) is the population slope.
  • \(\varepsilon_i\) represents unexplained variation.

We estimate the intercept and slope from the sample data to obtain a fitted regression line.

Mathematics 2: Testing the Slope

We test whether horsepower has a linear relationship with car price.

\[ H_0: \beta_1 = 0 \]

\[ H_A: \beta_1 \neq 0 \]

The test statistic for the slope is:

\[ t = \frac{\hat{\beta}_1 - 0}{SE(\hat{\beta}_1)} \]

The p-value measures how unusual the observed result would be if the population slope were zero.

We use a significance level of \(\alpha = 0.05\).

Visualization 1: Horsepower and Price

Each point represents one car model. The line shows the estimated linear trend, and the shaded region represents the confidence band around that line.

What to look for: Do prices tend to increase as horsepower increases? Are the points close to the line, or is there substantial variation?

Visualization 2: Residuals

Residuals are the differences between observed prices and the prices predicted by our regression model.

A random-looking pattern around zero supports the use of a linear model. A clear curve or changing spread may suggest that the model does not capture all the patterns in the data.

R Code: Fit the Model

model <- lm(Price ~ Horsepower, data = cars)
summary(model)
Call:
lm(formula = Price ~ Horsepower, data = cars)

Residuals:
    Min      1Q  Median      3Q     Max 
-16.413  -2.792  -0.821   1.803  31.753 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -1.3988     1.8200  -0.769    0.444    
Horsepower    0.1454     0.0119  12.218   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 5.977 on 91 degrees of freedom
Multiple R-squared:  0.6213,    Adjusted R-squared:  0.6171 
F-statistic: 149.3 on 1 and 91 DF,  p-value: < 2.2e-16

The lm() function estimates the regression line. The summary() function displays the estimated coefficients, standard errors, t-statistics, p-values, and \(R^2\).

We use these results to estimate the relationship and test the slope.

What Is the Fitted Equation?

Our estimated regression equation is:

\[ \widehat{Price} = \hat{\beta}_0 + \hat{\beta}_1(Horsepower) \]

Using the sample data, the fitted equation is:

Predicted Price = -1.399 + 0.1454 × Horsepower

Price is measured in thousands of dollars.

The estimated slope is 0.1454 thousand dollars per horsepower unit. This means that each additional horsepower is associated with an estimated average price difference of 145.37 dollars according to this model.

This describes an association in our dataset, not proof that increasing horsepower causes a car’s price to change.

Interactive Plotly Visualization

Hover over the points to explore individual car models and use the plot controls to zoom or pan.

Hypothesis Test Results

The estimated slope is 0.1454.

The p-value for the horsepower slope is < 2.2e-16.

  • If the p-value is below 0.05, we reject the null hypothesis.
  • If the p-value is at least 0.05, we do not have sufficient evidence to reject the null hypothesis.

Conclusion from the test: The p-value is below 0.05, so we reject the null hypothesis. The data provide evidence of a linear relationship between horsepower and price.

Confidence Interval and Model Fit

The 95% confidence interval for the population slope is:

\[ \hat{\beta}_1 \pm t^* SE(\hat{\beta}_1) \]

For this dataset, the interval is:

(0.1217, 0.169) thousand dollars per horsepower unit.

Under the regression model assumptions, this interval gives a range of plausible values for the population slope.

The model’s \(R^2\) is 0.621, meaning that approximately 62.1% of the observed variation in car prices is explained by the fitted linear relationship with horsepower in this dataset.

The correlation between horsepower and price is 0.788. Correlation describes the direction and strength of the linear association between these two variables.

What Did We Learn?

  • We used simple linear regression to study horsepower and car prices.
  • The estimated slope describes the direction and size of the fitted relationship.
  • The p-value helps us assess evidence against a zero population slope.
  • The confidence interval shows uncertainty in our slope estimate.
  • \(R^2\) describes how much variation in price the model explains.

Important limitation: Horsepower is not the only factor that may be related to price. Brand, vehicle size, features, and other factors may also matter. This analysis shows association, not causation.

References

  • R Core Team. R: A Language and Environment for Statistical Computing.
  • MASS package: Cars93 dataset.
  • ggplot2 package documentation.
  • plotly R package documentation.