2026-06-08

Introduction: The Daily Commute

  • The Goal: Commuting out in Chandler means dealing with some serious heat swings. I wanted to see exactly how much those rising temperatures slow down my daily 3.5-mile ride.
  • The Gear: My daily commuter is a Felt F95 road bike.
  • The Variables: We will look at how ambient temperature (in Fahrenheit) affects the total commute time (in minutes), and as a bonus headwind (in MPH).
  • The Goal: Use the Simple Linear Regression to model and predict future ride times.

The Mathematical Model

To understand the relationship between temperature and time, we apply a simple linear regression model.

The theoretical model is defined as:

\[Y = \beta_0 + \beta_1X + \epsilon\]

  • \(Y\): The dependent variable (Commute Time)
  • \(X\): The independent variable (Temperature)
  • \(\beta_0\): The y-intercept
  • \(\beta_1\): The slope of the line
  • \(\epsilon\): The random error term

Generating the Data

Here is the R code used to simulate our commute data for the past 50 rides.

# Load necessary libraries
library(ggplot2)
library(plotly)

# Set seed for reproducibility
set.seed(42)

# Simulate 50 days of data
rides <- 50
temperature <- runif(rides, min = 50, max = 105) 

# Simulate time: higher temps slightly slow down the ride (fatigue)
commute_time <- 12 + (temperature * 0.05) + rnorm(rides, mean = 0, sd = 1.5)

# Create a data frame
bike_data <- data.frame(temperature, commute_time)

Initial Visualization

To get a baseline understanding, we can visualize the raw simulated data.

## `geom_smooth()` using formula = 'y ~ x'

Evaluating the Model

To determine how well temperature predicts the commute time, we look at the coefficient of determination, \(R^2\).

\[R^2 = 1 - \frac{RSS}{TSS}\]

  • RSS: Residual Sum of Squares (the variance our model can’t explain)
  • TSS: Total Sum of Squares (the total variance in the data)

A higher \(R^2\) indicates that temperature is a strong, reliable predictor of your commute time!

Are the Predictions Accurate?

To ensure our linear regression is valid, we check the residuals (the difference between the predicted commute time and the actual time).

The Wind Factor (3D Interactive Plot)

Let’s add wind speed into the equation. Headwinds will naturally slow down the ride.