Does it get smoggier when it’s hot?
I used airquality a dataset already in R. It has daily air data from New York in 1973.
If I know the temperature, can I guess the ozone?
Does it get smoggier when it’s hot?
I used airquality a dataset already in R. It has daily air data from New York in 1973.
If I know the temperature, can I guess the ozone?
head(air[, c("Ozone", "Temp", "Wind")], 5)
Ozone Temp Wind 1 41 67 7.4 2 36 72 8.0 3 12 74 12.6 4 18 62 11.5 7 23 65 8.6
Ozone is in parts per billion, Temp is in Fahrenheit. I used na.omit() to drop the rows with missing values. That leaves 111 days.
Regression draws a straight line through the dots:
\[ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i \]
\(y_i\) is ozone, \(x_i\) is temperature, \(\beta_0\) is intercept, \(\beta_1\) is slope, \(\varepsilon_i\) is error.
\(\beta_1\) is one I care about. It tells me how much ozone goes up per degree.
Model is
\[ \text{Ozone} = \beta_0 + \beta_1 \cdot \text{Temp} + \varepsilon, \quad \varepsilon \sim N(0, \sigma^2) \]
After fitting it, we get
\[ \text{Ozone} = \hat{\beta}_0 + \hat{\beta}_1 \cdot \text{Temp} \]
Hats mean those are estimates. R calculates them.
mod <- lm(Ozone ~ Temp, data = air) summary(mod)
Call:
lm(formula = Ozone ~ Temp, data = air)
Residuals:
Min 1Q Median 3Q Max
-40.922 -17.459 -0.874 10.444 118.078
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -147.6461 18.7553 -7.872 2.76e-12 ***
Temp 2.4391 0.2393 10.192 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 23.92 on 109 degrees of freedom
Multiple R-squared: 0.488, Adjusted R-squared: 0.4833
F-statistic: 103.9 on 1 and 109 DF, p-value: < 2.2e-16
Ozone goes up when it’s hotter. Dots spread out more on the right so the line fits worse up there.
Ozone goes down when its windy. So temperature isn’t the only thing.
Each dot is one day, colored by wind. Worst ozone days are hot with low wind.
Temperature does predict ozone. Slope is 2.4391 and \(R^2\) is 0.488, it explains some of it but not all.
Wind matters too.
This is just one summer in New York in 1973 so it doesn’t say anything about now.