The question

Do hotter days have more ozone in the air?

I’ll use a small New York City dataset to look at the relationship between temperature and ozone.

Ozone is just one measure of air quality, not all pollution.

The data

R’s built-in airquality data come from May–September 1973.

  • 153 days in total
  • 37 missing ozone readings, leaving 116 days for analysis
  • Temp = temperature (°F); Ozone = ozone level (ppb)

I left out missing readings instead of counting them as zero.

Temperature and ozone

The trend goes up, but ozone still varies a lot at similar temperatures.

Linear regression

I used a straight line to describe the relationship:

\[ \text{Ozone}_i = \beta_0 + \beta_1\text{Temp}_i + \varepsilon_i \]

  • \(\beta_0\): intercept
  • \(\beta_1\): change in predicted ozone for 1°F higher temperature
  • \(\varepsilon_i\): what the line does not explain

What the line says

R estimated:

\[ \widehat{\text{Ozone}} = -147 + 2.43\,\text{Temp} \]

For each 1°F increase, the line predicts about 2.43 ppb more ozone.

This is an association, not proof of cause and effect.

How well does it fit?

I used \(R^2\) to measure how much variation the line explains:

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

Here, \(R^2\) = 0.488. Temperature explains about 49% of the variation in these observations.

R code

Here is the code used for the regression:

model <- lm(Ozone ~ Temp, data = aq)
coef(model)
## (Intercept)        Temp 
## -146.995491    2.428703
summary(model)$r.squared
## [1] 0.4877072

lm() fits the line, and summary() gives \(R^2\).

Cool and hot days

Days 80°F or hotter generally have higher ozone, but the values are spread out.

Interactive plot

Limits and conclusion

Warmer days usually had more ozone in these data. But days at the same temperature could be very different.

This dataset is from one city in 1973, and some readings are missing. Wind and sunlight may also matter.

My conclusion: Temperature helps explain ozone levels, but it cannot predict them by itself.

Source: R built-in airquality dataset (?airquality).