2026-10-19

The Question

Does hotter weather mean more ozone pollution?

  • Ground-level ozone is a type of air pollution that can form on hot, sunny days.
  • I will use simple linear regression to study the relationship between temperature (\(X\)) and ozone levels (\(Y\)).
  • I will look at the slope, p-value, confidence interval, and \(R^2\) to understand the relationship and see how well temperature explains changes in ozone levels.

The process I will follow: Research Question → Linear Regression → Mathematics → R Analysis → Visualization → Findings

Images generated using Adobe Firefly (Beta).

The Data: airquality

  • Dataset: the data comes from R’s built-in airquality dataset. It has details on air quality in New York from May to September 1973.
  • Variables: I selected Ozone (in ppb) and Temp (in degrees Fahrenheit). The dataset also has wind speed in mph.
  • Missing values: some days have no ozone reading (marked NA in R). Out of 153 observations, 37 had missing ozone values. I deleted them because I need both temperature and ozone for my analysis.
  • Final dataset: 116 observations are used in the analysis.

Snapshot of the data:

  Ozone Temp Wind Month Day
1    41   67  7.4     5   1
2    36   72  8.0     5   2
3    12   74 12.6     5   3
4    18   62 11.5     5   4
5    NA   56 14.3     5   5

Observations:

  • I want to examine the relationship between temperature and ozone levels.
  • On 1 May, the ozone level was 41 ppb and the maximum temperature was 67°F.

Source: Chambers et al. (1983). airquality, R datasets documentation.

Regression Model — Mathematics

The regression model relates ozone to temperature:

\[ \text{Ozone} = \beta_0 + \beta_1 \cdot \text{Temp} + \varepsilon, \quad \varepsilon \sim N(0, \sigma^2) \]

Least squares chooses the line that minimizes

\[ \sum_{i=1}^{n} \left(y_i - \beta_0 - \beta_1 x_i\right)^2 \]

which gives

\[ \hat{\beta}_1 = \frac{\sum (x_i-\bar{x})(y_i-\bar{y})}{\sum (x_i-\bar{x})^2} = r\,\frac{s_y}{s_x}, \quad \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]

References: Soch (2021), Proof P271; Statistics Fundamentals Team (2026).

Inference and Fit — Mathematics

Is the slope really different from zero?

\[ H_0: \beta_1 = 0 \quad \text{vs.} \quad H_a: \beta_1 \neq 0, \quad t = \frac{\hat{\beta}_1}{SE(\hat{\beta}_1)} \sim t_{n-2} \]

A 95% confidence interval for the slope:

\[ \hat{\beta}_1 \pm t_{n-2,\,0.975}\, SE(\hat{\beta}_1) \]

How much variation does the line explain?

\[ R^2 = 1 - \frac{\sum (y_i-\hat{y}_i)^2}{\sum (y_i-\bar{y})^2} = r^2 \]

References: Statistics Fundamentals Team (2026); Bobbitt (2022).

Ozone Distribution

What does this graph show? How ozone levels are spread across days.

  • Each bar represents the number of days a certain amount of ozone was in the air, with each bar separated by 10 ppb.
  • The majority of the days have low amounts of ozone, as seen by the large bars clustered on the left side of the graph, between 10 and 30 ppb, with the median being 31.5 ppb.
  • There are also a few days with very high values of ozone, which is represented by the tail on the right side of the graph, with the highest value being 168 ppb (so the distribution is skewed right).
  • The mean is 42.1 ppb, which is higher than the median due to the outliers on the right end of the graph.

Ozone vs. Temperature

  • Higher temperatures tend to be associated with higher ozone levels. The points show a positive relationship, although there is quite a bit of variation.
  • The black line is the regression line, showing the overall trend predicted by the linear model.
  • The gold shaded area represents the 95% confidence band around the fitted line, showing the uncertainty in the estimated relationship.

Key takeaway: Ozone levels generally increase as temperature rises, but temperature alone does not explain all the variation in ozone levels.

Regression in R

  • I am using lm(Ozone ~ Temp, data = dat) to fit a linear regression model, with temperature as \(X\) and ozone level as \(Y\).
  • I am using summary() to examine the slope, p-value, and \(R^2\), and confint() to calculate the 95% confidence interval for the model coefficients.
mod <- lm(Ozone ~ Temp, data = dat)
print(summary(mod), digits = 3)
Call:
lm(formula = Ozone ~ Temp, data = dat)

Residuals:
   Min     1Q Median     3Q    Max 
-40.73 -17.41  -0.59  11.31 118.27 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -146.995     18.287   -8.04  9.4e-13 ***
Temp           2.429      0.233   10.42  < 2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 23.7 on 114 degrees of freedom
Multiple R-squared:  0.488, Adjusted R-squared:  0.483 
F-statistic:  109 on 1 and 114 DF,  p-value: <2e-16
confint(mod)
                  2.5 %      97.5 %
(Intercept) -183.222241 -110.768741
Temp           1.966871    2.890536

Understanding the Results

  • Slope = 2.43 (95% CI: 1.97 to 2.89). The p-value is less than 0.001, indicating a significant, positive association between temperature and ozone.
  • What this means: A 1°F increase in temperature is associated with a 2.43 ppb increase in ozone. The model predicts that each 1°F increase will raise ozone by about 2.43 ppb on average.
  • \(R^2\) = 0.488: About 48.8% of the variability in ozone is explained by temperature. There are other factors that contribute to the differences in ozone levels.
  • Example prediction: At a temperature of 90°F, the model predicts about 72 ppb of ozone.

Background image generated using Adobe Firefly (Beta).

Interactive Regression Plot — Plotly

  • Each dot in the scatter plot represents a day of measurements, colored by month.
  • The black line shows the regression: as temperature increases, the ozone rises.
  • The individual data points can be examined by hovering over the dots.
  • It can also be zoomed in to focus on specific regions, or the legend can be used to hide data for particular months.

3D Scatter Plot — Adding Wind

  • Each dot on the plot represents a day’s data, with temperature, wind speed and ozone level.
  • The three axes are temperature, wind speed, and ozone. By rotating the plot, I can see how the variables relate to each other.

Key takeaway: It’s noticeable that higher ozone levels seem to occur on hotter days with less wind. It seems that temperature and wind speed are factors that affect the amount of ozone in the air.

What I Learned From This Analysis

Although ozone is higher on hotter days, this analysis does not prove that temperature causes higher ozone levels.

  • Positive trend: When the temperature increases by 1°F, ozone levels rise by approximately 2.43 ppb on average. The p-value is below 0.001, so there is a significant relationship between temperature and ozone levels.
  • \(R^2\): The share of the variation in ozone that is explained by temperature is approximately 0.49.
  • Other variables: Based on the 3D plot, ozone levels appear to be higher on hot days with little wind. Therefore, multiple regression may reveal a deeper relationship between other variables, including wind, and ozone levels.
  • Limitations: The analysis shows a positive association between temperature and ozone levels (correlation \(r\) = 0.7), but it does not prove causation. It also includes only one summer of data from New York in 1973.

References