10-cs02-intro

Professor Shannon Ellis

UC San Diego
COGS 137 - Fall 2026

2026-10-30

Course Announcements

Due Dates:

  • Lab 05 due tonight 10/30 (11:59 PM)
  • Mid-course survey due for EC tonight 10/30 (11:59 PM)
  • CS01 due Sunday
    • report in GH repo
    • general communication on Canvas
    • cs01 team eval survey
  • Lecture Participation survey “due” after class

Planning Ahead

Group Formation (CS02 + Final Project)

  • CS02 and Final Project are completed in groups (3-5) that you choose
    • CS02 - we choose the topic
    • Final project - you choose the topic
  • You specify that group by submitting your final project proposal (due next Sunday 11/8)
  • I will create repos for CS02 and final project after proposals are submitted
  • You will still submit feedback about your experience working with your group

The final project proposal link (link also on canvas)

Final Project

Carry out a data analysis on a topic and dataset of your choosing

  • not something that has already been done
  • pick a topic you care about
  • asking and answering a small-ish, specific question OR building a model to complete a useful task

Components

  • Proposal | week 6
  • Rough Draft of report | week 8
  • Peer Feedback | week 10
  • Present in class | week 10
  • Final Deliverable | Fri of finals week
    • report (.qmd -> html)
    • general audience communication

Note: CS02 is also due week 8; these will be happening concurrently; that’s why you’re in the same group

CS02: Predicting Air Pollution (Data)

The Problem

What we have: measurements at monitors

[source]

What we want: estimates everywhere

[source]

We have data at the dots. How would you fill in everywhere else?

What is PM2.5?

Fine particulate matter: particles less than 2.5 µm in diameter (PM10 includes everything under 10 µm)

In relation to a piece of human hair:

[source]

  Which do you think is most detrimental to our health? (and why?)

Why It Matters

The most recent State of Global Air report (2025, data from 2023):

  • air pollution is the leading environmental risk factor for death worldwide
  • it contributed to 7.9 million deaths in 2023

Exposure is linked to asthma, lung disease, heart disease, diabetes, low birth weight, infections, dementia, and more.

Why We Need to Predict It

  • Monitors are sparse, and roughly 90% are in cities: an equity issue, since exposure in rural areas is poorly measured
  • Pollution can vary a lot even within the same city, and monitors aren’t necessarily near pollution sources
  • Health effects show up even at levels below guidelines, so we need fine spatial granularity to find who is at risk
  • Researchers have used machine learning with features like population density and road density to predict pollution where there are no monitors

So…we’re going to do the same

Question

With what accuracy can we predict US annual average air pollution concentrations?

This will specifically be at the granularity of zip code regional levels using predictors such as data about population density, urbanization, road density, as well as satellite pollution data and chemical modeling data.

Data

Outcome

value: the 2008 annual average PM2.5 (ug/m3) at each of 876 EPA gravimetric monitors, which capture fine particles on a filter that is then weighed

[image courtesy of Kirsten Koehler]

How do these values compare to health guidelines? Thresholds for annual average PM2.5 have become stricter over time:

When these data were collected (2008) Today
WHO guideline 10 ug/m3 (2005 guideline) 5 ug/m3 (2021 update)
EPA standard (primary NAAQS) 15 ug/m3 9 ug/m3 (2024 update)

We’ll come back to this during EDA: how many of our monitors exceed each threshold?

Get The Data

# install.packages("OCSdata")
OCSdata::raw_data("ocs-bp-air-pollution", outpath = getwd())
pm <- read_csv("OCS_data/data/raw/pm25_data.csv")

Read the data in so you can follow along now!

What Would You Use?

Think about where you grew up. If you had to guess its annual PM2.5 level, what sort of thing/measurements are you thinking about to come up with that guess?

PM 2.5 Data

  • 876 monitors
  • 50 columns
    • value | outcome variable
pm |>
  glimpse()
Rows: 876
Columns: 50
$ id                          <dbl> 1003.001, 1027.000, 1033.100, 1049.100, 10…
$ value                       <dbl> 9.597647, 10.800000, 11.212174, 11.659091,…
$ fips                        <dbl> 1003, 1027, 1033, 1049, 1055, 1069, 1073, …
$ lat                         <dbl> 30.49800, 33.28126, 34.75878, 34.28763, 33…
$ lon                         <dbl> -87.88141, -85.80218, -87.65056, -85.96830…
$ state                       <chr> "Alabama", "Alabama", "Alabama", "Alabama"…
$ county                      <chr> "Baldwin", "Clay", "Colbert", "DeKalb", "E…
$ city                        <chr> "Fairhope", "Ashland", "Muscle Shoals", "C…
$ CMAQ                        <dbl> 8.098836, 9.766208, 9.402679, 8.534772, 9.…
$ zcta                        <dbl> 36532, 36251, 35660, 35962, 35901, 36303, …
$ zcta_area                   <dbl> 190980522, 374132430, 16716984, 203836235,…
$ zcta_pop                    <dbl> 27829, 5103, 9042, 8300, 20045, 30217, 901…
$ imp_a500                    <dbl> 0.01730104, 1.96972318, 19.17301038, 5.782…
$ imp_a1000                   <dbl> 1.4096021, 0.8531574, 11.1448962, 3.867647…
$ imp_a5000                   <dbl> 3.3360118, 0.9851479, 15.1786154, 1.231141…
$ imp_a10000                  <dbl> 1.9879187, 0.5208189, 9.7253870, 1.0316469…
$ imp_a15000                  <dbl> 1.4386207, 0.3359198, 5.2472094, 0.9730444…
$ county_area                 <dbl> 4117521611, 1564252280, 1534877333, 201266…
$ county_pop                  <dbl> 182265, 13932, 54428, 71109, 104430, 10154…
$ log_dist_to_prisec          <dbl> 4.648181, 7.219907, 5.760131, 3.721489, 5.…
$ log_pri_length_5000         <dbl> 8.517193, 8.517193, 8.517193, 8.517193, 9.…
$ log_pri_length_10000        <dbl> 9.210340, 9.210340, 9.274303, 10.409411, 1…
$ log_pri_length_15000        <dbl> 9.630228, 9.615805, 9.658899, 11.173626, 1…
$ log_pri_length_25000        <dbl> 11.32735, 10.12663, 10.15769, 11.90959, 12…
$ log_prisec_length_500       <dbl> 7.295356, 6.214608, 8.611945, 7.310155, 8.…
$ log_prisec_length_1000      <dbl> 8.195119, 7.600902, 9.735569, 8.585843, 9.…
$ log_prisec_length_5000      <dbl> 10.815042, 10.170878, 11.770407, 10.214200…
$ log_prisec_length_10000     <dbl> 11.88680, 11.40554, 12.84066, 11.50894, 12…
$ log_prisec_length_15000     <dbl> 12.205723, 12.042963, 13.282656, 12.353663…
$ log_prisec_length_25000     <dbl> 13.41395, 12.79980, 13.79973, 13.55979, 13…
$ log_nei_2008_pm25_sum_10000 <dbl> 0.318035438, 3.218632928, 6.573127301, 0.0…
$ log_nei_2008_pm25_sum_15000 <dbl> 1.967358961, 3.218632928, 6.581917457, 3.2…
$ log_nei_2008_pm25_sum_25000 <dbl> 5.067308, 3.218633, 6.875900, 4.887665, 4.…
$ log_nei_2008_pm10_sum_10000 <dbl> 1.35588511, 3.31111648, 6.69187313, 0.0000…
$ log_nei_2008_pm10_sum_15000 <dbl> 2.26783411, 3.31111648, 6.70127741, 3.3500…
$ log_nei_2008_pm10_sum_25000 <dbl> 5.628728, 3.311116, 7.148858, 5.171920, 4.…
$ popdens_county              <dbl> 44.265706, 8.906492, 35.460814, 35.330814,…
$ popdens_zcta                <dbl> 145.716431, 13.639555, 540.887040, 40.7189…
$ nohs                        <dbl> 3.3, 11.6, 7.3, 14.3, 4.3, 5.8, 7.1, 2.7, …
$ somehs                      <dbl> 4.9, 19.1, 15.8, 16.7, 13.3, 11.6, 17.1, 6…
$ hs                          <dbl> 25.1, 33.9, 30.6, 35.0, 27.8, 29.8, 37.2, …
$ somecollege                 <dbl> 19.7, 18.8, 20.9, 14.9, 29.2, 21.4, 23.5, …
$ associate                   <dbl> 8.2, 8.0, 7.6, 5.5, 10.1, 7.9, 7.3, 8.0, 4…
$ bachelor                    <dbl> 25.3, 5.5, 12.7, 7.9, 10.0, 13.7, 5.9, 17.…
$ grad                        <dbl> 13.5, 3.1, 5.1, 5.8, 5.4, 9.8, 2.0, 8.7, 2…
$ pov                         <dbl> 6.1, 19.5, 19.0, 13.8, 8.8, 15.6, 25.5, 7.…
$ hs_orless                   <dbl> 33.3, 64.6, 53.7, 66.0, 45.4, 47.2, 61.4, …
$ urc2013                     <dbl> 4, 6, 4, 6, 4, 4, 1, 1, 1, 1, 1, 1, 1, 2, …
$ urc2006                     <dbl> 5, 6, 4, 5, 4, 4, 1, 1, 1, 1, 1, 1, 1, 2, …
$ aod                         <dbl> 37.36364, 34.81818, 36.00000, 33.08333, 43…

There are 48 features with values for each of the 876 monitors (observations).

The data comes from the US Environmental Protection Agency (EPA), the National Aeronautics and Space Administration (NASA), the US Census, and the National Center for Health Statistics (NCHS).

Features

Besides value, there are 49 columns. Grouped (full descriptions are in the notes):

Group Variables
IDs & location id, fips, zcta, Lat, Lon, state, county, city
Chemical model CMAQ
Satellite aod
Development (impervious surface) imp_a500 … imp_a15000 (5 radii)
Roads Log_dist_to_prisec, log_pri_length_* (4 radii), log_prisec_length_* (6 radii)
Emissions log_nei_2008_pm25_sum_*, log_nei_2008_pm10_sum_* (3 radii each)
Population zcta_area, zcta_pop, county_area, county_pop, popdens_county, popdens_zcta
Education & poverty nohs, somehs, hs, somecollege, associate, bachelor, grad, hs_orless, pov
Urbanicity urc2006, urc2013

Which of your ideas are here? What’s missing?

Many of these features have to do with the circular area around the monitor called the “buffer”. These are illustrated in the following figure:

[source]

Where Are the Monitors?

pm |>
  ggplot(aes(x = lon, y = lat, color = value)) +
  geom_point(size = 2) +
  coord_quickmap() +
  scale_color_gradient(low = "#9ecae1", high = "#08306b") +
  labs(color = "PM2.5\n(ug/m^3)") +
  theme_minimal()

Where are the gaps? Where is PM2.5 highest?

Your Turn

Scroll through the data and consider:

  1. Are these data in a tidy, usable format? Are any columns stored as numbers that aren’t really measurements?
  2. Which variables do you think may be most helpful in building a model to predict annual air pollution?
  3. Which variables seem redundant – capturing nearly the same information as another variable?

Recap

  • We have PM2.5 measurements at 876 monitors, mostly in cities
  • We want estimates everywhere, so we’ll build a model that predicts PM2.5 from features we do have everywhere
  • Next: EDA on these data