The Research Question

How does mileage impact the market price of a used car?

  • When buying or selling a used vehicle, odometer mileage is one of the most critical factors.
  • Common intuition suggests that higher mileage leads to lower market value due to wear and tear.
  • Our Goal: Use statistical modeling to quantify this relationship and predict car price based on mileage.
  • Statistical Framework: Simple Linear Regression (\(Y\) predicted by \(X\)).

Exploring the Sample Data

We analyze a sample of 120 used vehicle transactions to inspect price and mileage.

# Create reproducible used car dataset
set.seed(42)
n <- 120
mileage <- round(runif(n, min = 10, max = 150), 1)
# Price formula with realistic variation (in thousands of dollars)
price <- round(38 - 0.16 * mileage + rnorm(n, mean = 0, sd = 2.5), 2)

car_data <- data.frame(
  Mileage_k = mileage,
  Price_k = price
)

head(car_data, 5)
##   Mileage_k Price_k
## 1     138.1   14.99
## 2     141.2   15.87
## 3      50.1   31.44
## 4     126.3   21.29
## 5      99.8   20.21
  • Independent Variable (\(X\)): Mileage (in thousands of miles).
  • Dependent Variable (\(Y\)): Sale Price (in thousands of dollars).

The Statistical Model

We model the relationship between mileage and price using the Simple Linear Regression framework:

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

Where:

  • \(Y_i\) is the price of the \(i\)-th car (in thousands of dollars).
  • \(X_i\) is the mileage of the \(i\)-th car (in thousands of miles).
  • \(\beta_0\) is the intercept (the estimated price of a car with 0 miles).
  • \(\beta_1\) is the slope parameter (the expected change in price for each additional 1,000 miles).
  • \(\varepsilon_i \sim N(0, \sigma^2)\) is the random error term, assumed to be normally distributed.

Ordinary Least Squares (OLS) Mathematics

To find the best fitting line, we minimize the Sum of Squared Residuals (SSR):

\[SSR = \sum_{i=1}^{n} (Y_i - \hat{Y}_i)^2 = \sum_{i=1}^{n} \left(Y_i - (\hat{\beta}_0 + \hat{\beta}_1 X_i)\right)^2\]

Using calculus, the exact closed-form solutions for our estimates are:

\[\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2} = \frac{Cov(X, Y)}{Var(X)}\]

\[\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}\]

  • A negative \(\hat{\beta}_1\) will confirm that car price depreciates as mileage increases.

Fitting the Model in R

We use R’s built-in lm() function to estimate \(\beta_0\) and \(\beta_1\):

# Fit simple linear regression model
car_model <- lm(Price_k ~ Mileage_k, data = car_data)

# Display model coefficients and summary metrics
summary(car_model)$coefficients
##               Estimate  Std. Error   t value      Pr(>|t|)
## (Intercept) 37.3516452 0.461647792  80.90940 3.223260e-105
## Mileage_k   -0.1530658 0.004932836 -31.02998  1.375292e-58
  • Intercept (\(\hat{\beta}_0\)): Baseline estimated price when mileage is 0.
  • Slope (\(\hat{\beta}_1\)): Expected change in price per 1,000 miles.
  • p-value: Tests if mileage has a statistically significant relationship with price (\(H_0: \beta_1 = 0\)).

Visualization 1: Scatter Plot with ggplot2

ggplot(car_data, aes(x = Mileage_k, y = Price_k)) +
  geom_point(color = "#8C1D40", alpha = 0.75, size = 2.5) +
  labs(
    title = "Used Car Price vs. Mileage",
    subtitle = "Initial observation shows an inverse linear trend",
    x = "Mileage (Thousands of Miles)",
    y = "Price (Thousands of USD)"
  ) +
  theme_minimal(base_size = 13)

Visualization 2: Fitted Regression Line (ggplot2)

ggplot(car_data, aes(x = Mileage_k, y = Price_k)) +
  geom_point(color = "#8C1D40", alpha = 0.6, size = 2) +
  geom_smooth(method = "lm", color = "#FFC627", fill = "#8C1D40", alpha = 0.2) +
  labs(
    title = "Fitted OLS Model: Price = 38.08 - 0.16 * Mileage",
    subtitle = "Gold line shows the linear fit; shaded region represents the 95% confidence interval",
    x = "Mileage (Thousands of Miles)",
    y = "Price (Thousands of USD)"
  ) +
  theme_minimal(base_size = 13)

Interactive Exploration with Plotly

Hover over points to inspect specific car observations and test predictions.

p <- ggplot(car_data, aes(x = Mileage_k, y = Price_k,
                          text = paste("Mileage:", Mileage_k, "k<br>Price: $", Price_k, "k"))) +
  geom_point(color = "#8C1D40", alpha = 0.7, size = 2) +
  geom_smooth(method = "lm", color = "#FFC627", se = FALSE) +
  labs(x = "Mileage (k)", y = "Price ($k)") +
  theme_minimal()

ggplotly(p, tooltip = "text")

Insights & Conclusion: What Did We Learn?

1. Key Statistical Findings

  • Negative Correlation: As mileage increases, car market price decreases significantly (\(p < 0.001\)).
  • Depreciation Rate: On average, each additional 1,000 miles reduces the car’s expected resale value by approximately 160 dollars (\(\hat{\beta}_1 \approx -0.16\)).
  • Baseline Value: A theoretical brand-new car (0 miles) in this sample has an estimated value of 38,080 dollars (\(\hat{\beta}_0 \approx 38.08\)).

2. Business & Decision-Making Takeaway

  • Sellers: Timing matters; vehicles approaching major mileage milestones (like 50k or 100k miles) face steep drops in valuation.
  • Buyers: Cars positioned below the regression line represent strong value deals (lower price for their given mileage).