10-cs02-intro

Author
Affiliation

Professor Shannon Ellis

UC San Diego
COGS 137 - Fall 2026

Published

October 30, 2026

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)

This case study is adapted from OpenCaseStudies: Wright, Carrie and Meng, Qier and Jager, Leah and Taub, Margaret and Hicks, Stephanie. (2020). https://www.opencasestudies.org/ocs-bp-air-pollution/. Predicting Annual Air Pollution (Version v1.0.0).

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?)

. . .

[source]

More on air pollutants

Some sources are natural while others are anthropogenic (human-derived):

[source]

Major types of air pollutants

  1. Gaseous - Carbon Monoxide (CO), Ozone (O3), Nitrogen Oxides (NO, NO2), Sulfur Dioxide (SO2)
  2. Particulate - small liquids and solids suspended in the air (includes lead; can include certain types of dust)
  3. Dust - small solids (larger than particulates) that can be suspended in the air for some time but eventually settle
  4. Biological - pollen, bacteria, viruses, mold spores

See here for more detail on the types of pollutants in the air.

Particulate size classes

Air pollution particulates are generally described by their size:

  1. Large Coarse Particulate Matter - has diameter of >10 micrometers (10 µm)

  2. Coarse Particulate Matter (called PM10-2.5) - has diameter of between 2.5 µm and 10 µm

  3. Fine Particulate Matter (called PM2.5) - has diameter of < 2.5 µm

PM10 includes any particulate matter <10 µm (both coarse and fine particulate matter)

Common pollutants and their size

[source]

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.

More on health impacts

Exposure to air pollution is:

  • associated with higher rates of mortality in older adults
  • known to be a risk factor for many diseases and conditions including (but not limited to):
  1. Asthma - fine particle exposure (PM2.5) was found to be associated with higher rates of asthma in children
  2. Inflammation in type 1 diabetes - fine particle exposure (PM2.5) from traffic-related air pollution was associated with increased measures of inflammatory markers in youths with Type 1 diabetes
  3. Lung function and emphysema - higher concentrations of ozone (O3), nitrogen oxides (NOx), black carbon, and fine particle exposure (PM2.5) at study baseline were significantly associated with greater increases in percent emphysema per 10 years
  4. Low birthweight - fine particle exposure (PM2.5) was associated with lower birth weight in full-term live births
  5. Viral Infection - higher rates of infection and increased severity of infection are associated with higher exposures to pollution levels including fine particle exposure (PM2.5)

See this review article for more information about sources of air pollution and the influence of air pollution on health.

More from the State of Global Air

The State of Global Air (SoGA) report from the Health Effects Institute communicates the impact of air pollution on public health around the world.

The most recent report, SoGA 2025 (data from 2023), found that:

  • air pollution is the leading environmental risk factor for death worldwide
  • it contributed to 7.9 million deaths in 2023
  • 86% of those deaths were from noncommunicable diseases (e.g., heart disease, COPD, diabetes, dementia)
  • 36% of the world’s population is exposed to PM2.5 levels above even the WHO’s least stringent interim target (35 ug/m3)

The SoGA 2024 report (data from 2021) ranked air pollution as the second leading risk factor for death overall – behind only high blood pressure, and ahead of tobacco.

Estimates differ from report to report, in part because the methods and models used to estimate air pollution’s health impacts keep improving. The overall message is the same: air pollution causes millions of deaths each year.

The State of Global Air 2019 report (which uses data from 2017) stated that:

Air pollution is the fifth leading risk factor for mortality worldwide. It is responsible for more deaths than many better-known risk factors such as malnutrition, alcohol use, and physical inactivity. Each year, more people die from air pollution–related disease than from road traffic injuries or malaria.

[source]

In 2017, air pollution is estimated to have contributed to close to 5 million deaths globally — nearly 1 in every 10 deaths.

[source]

Where is it worst?

The 2019 report shows that the highest levels of fine particulate pollution occur in Africa and Asia and that:

More than 90% of people worldwide live in areas exceeding the World Health Organization (WHO) Guideline for healthy air. More than half live in areas that do not even meet WHO’s least-stringent air quality target.

[source]

Note: the WHO guideline at the time was 10 ug/m3; in 2021, WHO cut it in half, to 5 ug/m3.

Air pollution in the US

US air pollution levels are generally improving: national average concentrations have declined, as shown in the 2019 Our Nation’s Air report from the US Environmental Protection Agency (EPA):

[source]

But it’s still an issue:

  • Regions with higher than national average pollution can, at times, exceed health-based guidelines.
  • Adverse health effects have been seen in populations exposed to levels below current guidelines; particulate composition and demographic factors may put some populations at greater risk (see this article).
  • So we need estimates with high spatial granularity to identify where people are experiencing harmful levels of exposure.

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

More on sparse monitoring

  • Historically, epidemiological studies would assess the influence of air pollution on health outcomes by relying on a number of monitors located around the country.
  • However, these monitors are relatively sparse in certain regions of the country and are not necessarily located near pollution sources.
  • dramatic differences in pollution rates can be seen even within the same city. (In fact, the term micro-environments describes environments within cities or counties which may vary greatly from one block to another.)

Lack of granularity in air pollution monitoring has hindered our ability to discern the full impact of air pollution on health and to identify at-risk locations.

Machine learning offers a solution

An article published in the Environmental Health journal dealt with this issue by using data, including population density and road density, among other features, to model or predict air pollution levels at a more localized scale using machine learning (ML) methods.

[source]

The authors of this article state that:

“Exposure to atmospheric particulate matter (PM) remains an important public health concern, although it remains difficult to quantify accurately across large geographic areas with sufficiently high spatial resolution. Recent epidemiologic analyses have demonstrated the importance of spatially- and temporally-resolved exposure estimates, which show larger PM-mediated health effects as compared to nearest monitor or county-specific ambient concentrations.”

The article above demonstrates that machine learning methods can be used to predict air pollution levels when traditional monitoring systems are not available in a particular area or when there is not enough spatial granularity with current monitoring systems.

Monitor data

  • Monitor data in this case study come from a system of monitors in which roughly 90% are located within cities.
  • There is an equity issue in terms of capturing the air pollution levels of more rural areas.
  • To get a better sense of the pollution exposures for the individuals living in these areas, methods like machine learning can be useful to estimate air pollution levels in areas with little to no monitoring.

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.

Supervised ML

Here, we’ll need:

  1. A continuous outcome variable that we want to predict
  2. A set of feature(s) (or predictor variables) that we use to predict the outcome variable

To build (or train) our model, we use both the outcome and features.

The goal is to identify informative features that can explain a large amount of variation in our outcome variable.

Using this model, we can then predict the outcome from new observations with the same features where we have not observed the outcome.

(More details here)

Limitations

  1. The data do not include information about the composition of particulate matter. Different types of particulates may be more benign or deleterious for health outcomes.
  2. Outdoor pollution levels are not necessarily an indication of individual exposures. People spend differing amounts of time indoors and outdoors and are exposed to different pollution levels indoors. Researchers are now developing personal monitoring systems to track air pollution levels on the personal level.
  3. Our analysis will use annual mean estimates of pollution levels, but these can vary greatly by season, day and even hour. There are data sources that have finer levels of temporal data; however, we are interested in long term exposures, as these appear to be the most influential for health outcomes.
  4. These data are US-focused.

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?

More on the monitors

The monitor data that we will be using comes from gravimetric monitors (see picture below) operated by the US Environmental Protection Agency (EPA).

These monitors use a filtration system to specifically capture fine particulate matter.

[source]

The weight of this particulate matter is manually measured daily or weekly.

For the EPA standard operating procedure for PM gravimetric analysis in 2008, we refer the reader to here.

The units are micrograms of fine particulate matter (PM) that is less than 2.5 micrometers in diameter per cubic meter of air - mass concentration (ug/m3).

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!

Put a green sticky on the front of your computer when you’ve got the code running. Put a pink if you want help/have a question.

All of our data was previously collected by a researcher at the Johns Hopkins School of Public Health who studies air pollution and climate change. (Roger now works at UT Austin)

We have one CSV file that contains both our single outcome variable and all of our features (or predictor variables), which you can download using the OCSdata package (code above).

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

Variable Details
id Monitor number
– the county number is indicated before the decimal
– the monitor number is indicated after the decimal
Example: 1073.0023 is Jefferson county (1073) and .0023 one of 8 monitors
fips Federal information processing standard number for the county where the monitor is located
– 5 digit id code for counties (zero is often the first value and sometimes is not shown)
– the first 2 numbers indicate the state
– the last three numbers indicate the county
Example: Alabama’s state code is 01 because it is first alphabetically
(note: Alaska and Hawaii are not included because they are not part of the contiguous US)
Lat Latitude of the monitor in degrees
Lon Longitude of the monitor in degrees
state State where the monitor is located
county County where the monitor is located
city City where the monitor is located
CMAQ Estimated values of air pollution from a computational model called Community Multiscale Air Quality (CMAQ)
– A computer model (not a set of monitors) that simulates the physics and chemistry of the atmosphere, using emissions and weather data, to predict air pollution
– Does not use any of the PM2.5 gravimetric monitoring data. (There is a version that does use the gravimetric monitoring data, but not this one!)
– Data from the EPA
zcta Zip Code Tabulation Area where the monitor is located
– Postal Zip codes are converted into “generalized areal representations” that are non-overlapping
– Data from the 2010 Census
zcta_area Land area of the zip code area in meters squared
– Data from the 2010 Census
zcta_pop Population in the zip code area
– Data from the 2010 Census
imp_a500 Impervious surface measure
– Within a circle with a radius of 500 meters around the monitor
– Impervious surfaces are roads, concrete, parking lots, buildings
– This is a measure of development
imp_a1000 Impervious surface measure
– Within a circle with a radius of 1000 meters around the monitor
imp_a5000 Impervious surface measure
– Within a circle with a radius of 5000 meters around the monitor
imp_a10000 Impervious surface measure
– Within a circle with a radius of 10000 meters around the monitor
imp_a15000 Impervious surface measure
– Within a circle with a radius of 15000 meters around the monitor
county_area Land area of the county of the monitor in meters squared
county_pop Population of the county of the monitor
Log_dist_to_prisec Log (Natural log) distance to a primary or secondary road from the monitor
– Highway or major road
log_pri_length_5000 Count of primary road length in meters in a circle with a radius of 5000 meters around the monitor (Natural log)
– Highways only
log_pri_length_10000 Count of primary road length in meters in a circle with a radius of 10000 meters around the monitor (Natural log)
– Highways only
log_pri_length_15000 Count of primary road length in meters in a circle with a radius of 15000 meters around the monitor (Natural log)
– Highways only
log_pri_length_25000 Count of primary road length in meters in a circle with a radius of 25000 meters around the monitor (Natural log)
– Highways only
log_prisec_length_500 Count of primary and secondary road length in meters in a circle with a radius of 500 meters around the monitor (Natural log)
– Highway and secondary roads
log_prisec_length_1000 Count of primary and secondary road length in meters in a circle with a radius of 1000 meters around the monitor (Natural log)
– Highway and secondary roads
log_prisec_length_5000 Count of primary and secondary road length in meters in a circle with a radius of 5000 meters around the monitor (Natural log)
– Highway and secondary roads
log_prisec_length_10000 Count of primary and secondary road length in meters in a circle with a radius of 10000 meters around the monitor (Natural log)
– Highway and secondary roads
log_prisec_length_15000 Count of primary and secondary road length in meters in a circle with a radius of 15000 meters around the monitor (Natural log)
– Highway and secondary roads
log_prisec_length_25000 Count of primary and secondary road length in meters in a circle with a radius of 25000 meters around the monitor (Natural log)
– Highway and secondary roads
log_nei_2008_pm25_sum_10000 Tons of emissions from major sources database (annual data) sum of all sources within a circle with a radius of 10000 meters of distance around the monitor (Natural log)
log_nei_2008_pm25_sum_15000 Tons of emissions from major sources database (annual data) sum of all sources within a circle with a radius of 15000 meters of distance around the monitor (Natural log)
log_nei_2008_pm25_sum_25000 Tons of emissions from major sources database (annual data) sum of all sources within a circle with a radius of 25000 meters of distance around the monitor (Natural log)
log_nei_2008_pm10_sum_10000 Tons of emissions from major sources database (annual data) sum of all sources within a circle with a radius of 10000 meters of distance around the monitor (Natural log)
log_nei_2008_pm10_sum_15000 Tons of emissions from major sources database (annual data) sum of all sources within a circle with a radius of 15000 meters of distance around the monitor (Natural log)
log_nei_2008_pm10_sum_25000 Tons of emissions from major sources database (annual data) sum of all sources within a circle with a radius of 25000 meters of distance around the monitor (Natural log)
popdens_county Population density (number of people per kilometer squared area of the county)
popdens_zcta Population density (number of people per kilometer squared area of zcta)
nohs Percentage of people in the zcta where the monitor is located who do not have a high school degree
– Data from the Census
somehs Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was some high school education
– Data from the Census
hs Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was completing a high school degree
– Data from the Census
somecollege Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was completing some college education
– Data from the Census
associate Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was completing an associate degree
– Data from the Census
bachelor Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was a bachelor’s degree
– Data from the Census
grad Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was a graduate degree
– Data from the Census
pov Percentage of people in the zcta where the monitor is located who lived in poverty in 2008
– Data from the Census
hs_orless Percentage of people in the zcta where the monitor is located whose highest formal educational attainment was a high school degree or less (sum of nohs, somehs, and hs)
urc2013 2013 Urban-rural classification of the county where the monitor is located
– 6 category variable - 1 is totally urban 6 is completely rural
– Data from the National Center for Health Statistics
urc2006 2006 Urban-rural classification of the county where the monitor is located
– 6 category variable - 1 is totally urban 6 is completely rural
– Data from the National Center for Health Statistics
aod Aerosol Optical Depth measurement from a NASA satellite
– measured passively from space: how much sunlight is scattered or absorbed by particles in the column of air between the ground and the satellite
– used as a proxy of particulate pollution
– unit-less - higher value indicates more pollution
– Data from NASA

. . .

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?

Put a green sticky on the front of your computer when you’re done. Put a pink if you want help/have a question.

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