October 18, 2026

1. Question: Do Hotter Days Have Higher Ozone?

Question: Is daily temperature related to ozone pollution?

  • Response variable: Ozone (Ozone), measured in parts per billion (ppb)
  • Explanatory variable: Temperature (Temp), measured in °F
  • Data: R’s built-in airquality dataset
  • Setting: Daily New York air-quality measurements from May through September 1973

Why it matters: If temperature and ozone move together, statistics can summarize the pattern with one simple equation.

2. What Does the Data Look Like?

A few complete observations from airquality
Ozone (ppb) Temperature (°F) Month Day
1 41 67 5 1
2 36 72 5 2
3 12 74 5 3
4 18 62 5 4
6 28 66 5 6
7 23 65 5 7

There are 116 complete days available for this two-variable analysis.

Because both variables are quantitative, a scatterplot and simple linear regression are appropriate tools.

3. Statistical Idea: Simple Linear Regression

Simple linear regression uses a straight line to describe how the average response changes as an explanatory variable changes.

For this question:

  • Slope: estimated change in ozone for a 1°F increase in temperature
  • Intercept: predicted ozone when temperature is 0°F
  • Residual: observed ozone minus predicted ozone

The line will not explain every day perfectly. It summarizes the overall trend.

4. Mathematics: The Regression Model

Let \(Y_i\) be ozone and \(X_i\) be temperature on day \(i\).

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

where:

  • \(\beta_0\) = population intercept
  • \(\beta_1\) = population slope
  • \(\varepsilon_i\) = random error

For our sample, the fitted equation is:

\[ \widehat{Ozone} = -147 + 2.43(Temperature) \]

5. Mathematics: How Is the Best Line Chosen?

The least-squares slope is

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

and the intercept is

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

The “best” line minimizes the sum of squared residuals:

\[ \sum_{i=1}^{n}(y_i-\hat{y}_i)^2. \]

Meaning: We choose the line whose predictions are, overall, as close to the observed ozone values as possible.

6. Building the Regression Model in R

# Get the intercept from the regression model
intercept <- unname(coef(model)[1])
# Get the slope for temperature
slope <- unname(coef(model)[2])
# Get the R-squared value
r_squared <- model_summary$r.squared
# Get the p-value for the temperature slope
slope_p <- model_summary$coefficients["Temp", "Pr(>|t|)"]
# Get the 95% confidence interval for the temperature slope
slope_ci <- confint(model)["Temp", ]
# Predict the ozone level when temperature is 80°F
pred_80 <- unname(
  predict(model, newdata = data.frame(Temp = 80))
)
# Count the number of complete observations used
n_used <- nrow(air_data)

The main number is the coefficient of Temp.

The estimated slope is 2.43 ppb of ozone per 1°F.

7. ggplot2: Temperature vs. Ozone

What it tells us: The cloud of points generally rises from left to right. Hotter days tend to have higher ozone readings, and the regression line summarizes that positive association.

8. ggplot2: Check the Residuals

What it tells us: Residuals are scattered above and below zero, so the model has both over- and under-predictions. Some large residuals show that temperature does not explain all changes in ozone.

9. Interactive Plotly Visualization

Try it: Hover over any point to see the day, temperature, and ozone level.

10. Results: What Do the Numbers Say?

Quantity Result
Slope 2.43 ppb per 1°F
R-squared 0.488
Slope p-value < 0.001
95% CI for slope [1.97, 2.89]
  • A 1°F increase in temperature is associated with about 2.43 ppb more ozone, on average.
  • Temperature explains about 48.8% of the variation in ozone in these complete observations.
  • At 80°F, the model predicts about 47.3 ppb of ozone.

11. What Did We Learn?

Answer to the question: Yes. In this dataset, hotter days tend to have higher ozone levels.

Main takeaway: Temperature is a meaningful predictor of ozone, with an estimated increase of about 2.43 ppb for every 1°F increase.

Important caution: These are observational data. The regression shows association, not causation. Other weather conditions, such as wind and sunlight, may also influence ozone.

12. Final Takeaway

Hotter days tend to come with higher ozone levels, and simple linear regression gives us a clear way to measure and visualize that relationship.