Outreach

Learning statistical programming deeply through teaching.

Quantitative Social Science · University of Tokyo · Summer 2022
Course assistant for Kosuke Imai. I taught tidyverse lectures for social science students.

What I taught, and how

Original lecture slides · click to enlarge

01 One operation, many columns

dplyr · across() · where()

Lecture slide explaining the column-selection and function arguments of across(), with examples of summary functions.

I started with repeated summaries of Florida voter data, then replaced them with across(). Same calculation; less repetition.

Probability I · PDF p. 9 ↗

02 Give repeated code a name

Functions · arguments · code style

Lecture slide revealing a copied variable-name error in repeated rescaling code, motivating reusable functions.

A copy-paste error made the case for functions. We then built one in three steps: name, inputs, body.

Probability II · PDF p. 8 ↗

03 See what the code works on

Vectors · lists · data frames

Lecture slide contrasting homogeneous atomic vectors and heterogeneous lists, with R code and printed results.

I compared atomic vectors and lists side by side, using code and its output to connect data types to their structure.

Uncertainty I · PDF p. 5 ↗

04 Build a loop, then generalize

For loops · functionals · purrr

Lecture slide annotating the output, sequence, and body of a for loop that computes column means.

I unpacked a loop into output, sequence, and body. We then generalized column means to other summaries by passing a function as an argument.

Uncertainty II · PDF p. 10 ↗

05 Make uncertainty visible

ggplot2 · intervals · facets

Lecture slide plotting predicted vote shares against Obama vote shares with 95 percent confidence intervals.

I paired plotting syntax with the figure it produces: vote-share predictions and 95% confidence intervals, followed by faceting examples.

Uncertainty I · PDF p. 26 ↗

06 Write the reasoning, too

R Markdown · LaTeX · Bayes’ rule

Lecture slide expressing an Enigma decoding problem in prose and displaying Bayes’ rule in mathematical notation.

Using the Enigma decoding problem, I showed mathematical source and rendered notation, then how prose and code share one document.

Probability I · PDF p. 21 ↗

Then, put it to work.

The lectures led into in-class QSS assignments: Enigma decoding, women in China, and the file-drawer problem. The sequence was concrete example → reusable idea → application.

Selected from my Probability and Uncertainty decks in our teaching team’s open materials. Examples draw on QSS, R for Data Science, and Advanced R.
Grateful to Kosuke Imai and Connor Jerzak for opportunities to learn and teach.