2026-10-18

Scenario & Setup

We want to analyze historical weather data for Tempe, Arizona on Halloween (October 31) to predict the temperature for Halloween 2026 using Simple Linear Regression.

  • Goal: Predict 2026 Halloween High Temperature (°F)
  • Predictor Variable (\(X\)): Year (2015 to 2025)
  • Response Variable (\(Y\)): High Temperature (°F)

Simple Linear Regression Model

The mathematical equation for our simple linear regression model is:

\[y_i = \beta_0 + \beta_1 x_i + \epsilon_i\]

Where:

  • \(y_i\) is the High Temperature (°F) for year \(i\)
  • \(x_i\) is the Year (\(2015, 2016, \dots, 2025\))
  • \(\beta_0\) is the \(y\)-intercept
  • \(\beta_1\) is the slope parameter
  • \(\epsilon_i\) represents the random error term, assumed \(\epsilon_i \sim N(0, \sigma^2)\)

Parameter Estimation & Prediction Equations

We use Ordinary Least Squares (OLS) to estimate the slope (\(\hat{\beta}_1\)) and intercept (\(\hat{\beta}_0\)):

\[\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}\]

\[\hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x}\]

Once we find these values, our prediction equation for Halloween 2026 becomes:

\[\hat{y}_{2026} = \hat{\beta}_0 + \hat{\beta}_1 (2026)\]

Fitting the Linear Model in R

We use the built-in lm() function in R to fit the model:

##                 Estimate  Std. Error   t value   Pr(>|t|)
## (Intercept) -905.8181818 346.4848225 -2.614308 0.02807172
## Year           0.4909091   0.1715269  2.861994 0.01871942

ggplot 1: Historical Trendline Plot

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

ggplot 2: Residual Analysis Plot

Plotly Chart

Predicting Halloween 2026

Now we plug \(X = 2026\) into our trained linear model to get the forecast:

## Predicted High Temp for Halloween 2026: 88.8 °F