Putting it all together, what did you learn from your data and your
model performance?
Answer the Primary Questions posed above, citing any supporting
statistics, visualizations, or results from the data or your
models.
1. Based on test set performance, at what locations does your
model give predictions that are closest and furthest from the observed
values? What do you hypothesize are the reasons for the good or bad
performance at these locations?
# Create table with smallest and largest rmse
rmse_table <- rf_fit %>%
extract_fit_parsnip() %>%
augment(new_data = test_prep_dat) %>%
mutate(.resid = .pred - value) %>%
arrange(abs(.resid)) %>%
slice(c(1, n()))
rmse_table
## # A tibble: 2 × 8
## .pred lat lon pov zcta_pop CMAQ value .resid
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 7.70 40.2 -105. -0.0216 0.890 -1.35 7.69 0.0110
## 2 9.56 33.0 -112. -1.02 0.554 1.03 19.5 -9.90
# Create table with state and county
location_table <- dat %>%
select(lat, lon, state, county, city) %>%
arrange(desc(lat))
location_table
## # A tibble: 876 × 5
## lat lon state county city
## <dbl> <dbl> <chr> <chr> <chr>
## 1 48.4 -114. Montana Flathead Whitefish
## 2 48.4 -116. Montana Lincoln Libby
## 3 48.4 -114. Montana Flathead Columbia Falls
## 4 48.2 -122. Washington Snohomish Darrington
## 5 48.2 -114. Montana Flathead Kalispell
## 6 48.1 -122. Washington Snohomish Marysville
## 7 47.7 -117. Washington Spokane Spokane
## 8 47.6 -115. Montana Sanders Thompson Falls
## 9 47.6 -122. Washington King Seattle
## 10 47.6 -122. Washington King Seattle
## # ℹ 866 more rows
# Merge tables to find location
merged_table <- location_table %>%
inner_join(rmse_table, by = c("lat", "lon"))
merged_table
## # A tibble: 2 × 11
## lat lon state county city .pred pov zcta_pop CMAQ value .resid
## <dbl> <dbl> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 40.2 -105. Colorado Boulder Longm… 7.70 -0.0216 0.890 -1.35 7.69 0.0110
## 2 33.0 -112. Arizona Pinal Maric… 9.56 -1.02 0.554 1.03 19.5 -9.90
Based on the test set performance, the model’s predictions are
closest to the observed values in , Colorado, as evidenced by the lowest
RMSE. On the contrary, Maricopa in Pinal county, Arizona, exhibits the
highest RMSE, indicating the largest deviation between the model’s
predictions and the actual values. A factor to consider when looking at
the reliability of predicted vs. observed values, is the funding that
goes into the monitors that help improve the accuracy of a regions PM2.5
levels. With cities like Huntsville, which contain mountains and overall
a greater biodiversity, there is a possibility that the government has
more incentive to allocate more monitors potentially affecting the
better estimation of PM2.5 levels. Another factor to consider when
looking at the accuracy of the monitors would be that of the condition
and life span of these monitors. There is a possibility that cities like
Maricopa may have a greater number of monitors but the condition of the
monitors is finite and has the possibility of producing an inaccurate
result of PM2.5 levels. This may be due to when the adopted the practice
of using the monitors, as it is expected the older the monitor the more
maintenance it requires.
2. What variables might predict where your model performs
well or not? For example, are their regions of the country where the
model does better or worse? Are there variables that are not included in
this dataset that you think might improve the model performance if they
were included in your model?
Seen through the histogram, there is a difference between RMSEs for
every state. The differences in RMSE could be due to variables that
include the allocation of funds each state has to implement said models
that predict the proper performance. In areas such as New Mexico having
a much greater RMSE than Montana, there is a possibility that there is a
greater incentive to have more monitors in Montanta than that of New
Mexico, having a smaller overall RMSE value. A variable not included in
the dataset that may improve the model’s performance would be the number
of monitors in each region. By including the number of monitors in the
region that would then help us note which regions have a likely chance
of producing a better performance, as with more monitors results in more
data to accurately depict the values of PM2.5 levels.
# Aggregate model performance metrics (e.g., RMSE) by region
performance_by_region <- rf_fit %>%
extract_fit_parsnip() %>%
augment(new_data = test_prep_dat) %>%
mutate(.resid = .pred - value) %>%
inner_join(location_table, by = c("lat", "lon")) %>%
group_by(state) %>%
summarize(mean_rmse = mean(.resid)) %>%
arrange(abs(mean_rmse))
performance_by_region
## # A tibble: 46 × 2
## state mean_rmse
## <chr> <dbl>
## 1 Massachusetts 0.0334
## 2 Connecticut 0.0455
## 3 Virginia -0.105
## 4 Michigan 0.124
## 5 Colorado 0.130
## 6 Indiana -0.174
## 7 Alabama -0.190
## 8 North Dakota -0.216
## 9 Pennsylvania -0.221
## 10 Florida 0.227
## # ℹ 36 more rows
# Visualize regional variations
ggplot(performance_by_region, aes(x = reorder(state, mean_rmse), y = mean_rmse)) +
geom_bar(stat = "identity", fill = "skyblue") +
labs(title = "Model Performance by State", x = "State", y = "Mean RMSE") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) # Rotate x-axis labels

3. There is interest in developing more cost-effect
approaches to monitoring air pollution on the ground. Two candidates for
replacing the use of ground-based monitors are numerical models like
CMAQ and satellite-based observations such as AOD. How well do CMAQ and
AOD predict ground-level concentrations of PM2.5? How does the
prediction performance of your model change when CMAQ or aod are
included (or not included) in the model?
# without CMAQ
without_cmaq_rec <- train_dat %>%
recipe(value ~ lat + lon + pov + zcta_pop) %>%
step_normalize(all_numeric_predictors(),-lat, -lon)
# Prepare test data (also work for other models)
test_prep_dat <- without_cmaq_rec %>%
prep(train_dat) %>%
bake(new_dat = test_dat)
## Set workflow
without_cmaq_rf_wf <- workflow() %>%
add_recipe(without_cmaq_rec) %>%
add_model(tune_spec_rf)
## Tune model
without_cmaq_rf_res <- without_cmaq_rf_wf %>%
tune_grid(
resamples = folds,
grid = rf_grid)
## Find the best set of hyperparameter based on RMSE
without_cmaq_best_rf <- without_cmaq_rf_res %>%
show_best("rmse") %>%
slice(1)
## Finalize workflow after tuning
without_cmaq_final_wf_rf <- without_cmaq_rf_wf %>%
finalize_workflow(without_cmaq_best_rf)
# Fit model to training data
without_cmaq_rf_fit <- fit(without_cmaq_final_wf_rf, data = train_dat)
# Evaluate model on test data and calculate RMSE without CMAQ
without_cmaq_rmse <- without_cmaq_rf_fit %>%
extract_fit_parsnip() %>%
augment(new_data = test_prep_dat) %>%
mutate(.resid = .pred - value) %>%
summarize(rmse = sqrt(mean(.resid ** 2)))
# with AOD
aod_rec <- train_dat %>%
recipe(value ~ lat + lon + pov + zcta_pop + aod) %>%
step_normalize(all_numeric_predictors(),-lat, -lon)
# Prepare test data (also work for other models)
test_prep_dat <- aod_rec %>%
prep(train_dat) %>%
bake(new_dat = test_dat)
## Set workflow
aod_rf_wf <- workflow() %>%
add_recipe(aod_rec) %>%
add_model(tune_spec_rf)
## Tune model
aod_rf_res <- aod_rf_wf %>%
tune_grid(
resamples = folds,
grid = rf_grid)
## Find the best set of hyperparameter based on RMSE
aod_best_rf <- aod_rf_res %>%
show_best("rmse") %>%
slice(1)
## Finalize workflow after tuning
aod_final_wf_rf <- aod_rf_wf %>%
finalize_workflow(aod_best_rf)
# Fit model to training data
aod_rf_fit <- fit(aod_final_wf_rf, data = train_dat)
# Evaluate model on test data and calculate RMSE with AOD
aod_rmse <- aod_rf_fit %>%
extract_fit_parsnip() %>%
augment(new_data = test_prep_dat) %>%
mutate(.resid = .pred - value) %>%
summarize(rmse = sqrt(mean(.resid ** 2)))
without_cmaq_rmse
## # A tibble: 1 × 1
## rmse
## <dbl>
## 1 1.79
aod_rmse
## # A tibble: 1 × 1
## rmse
## <dbl>
## 1 1.79
When CMAQ and AOD are not included in the model, we see an RMSE of
1.777764, slightly lower than that of when we included CMAQ in the
original model (1.784971). This shows us that not including CMAQ and
solely relying on ground-based predictors yields a better performance.
When considering the AOD model, the RSME is even higher than the
previous two models, with a value of 1.803389. This shows us that not
considering AOD as a predictor yields a better performance. When
comparing the two models (with CMAQ or with AOD) we observe a lower RMSE
when the model included CMAQ versus AOD. This suggests that we should
consider CMAQ as a better cost-effective approach to monitor air
pollution on the ground.
4. The dataset here did not include data from Alaska or
Hawaii. Do you think your model will perform well or not in those two
states? Explain your reasoning.
We think our model will not perform well due to the predictors that
were picked to provide the RMSE values. Alaska has low zcta_pop, due to
the nature characteristics that prevent people from moving to Alaska in
the first place. The conglomeration of population in Alaska would then
produce much lower zcta_pop in areas where there is a small population,
as a majority of Alaskans live in communities. This gives no incentives
to have monitors in areas where the zcta_pop is so low which may give us
a false performance. Another reasoning would be the CMAQ value, as the
systems takes into account multiple variables which Alaska or Hawaii may
not have the proper data to give an effective CMAQ value. This can be
due to the climate and terrain of each state which makes it harder to
harvest data.