R examples

Probability and Statistics (for Policy Analysis), MIR, SPEGA, IE University, Term 1, SEP-2026 S-2.

Prof. Dae-Jin Lee, daelee@faculty.ie.edu, IE University — Scitech.

Each session is one folder. Open that folder in RStudio and knit the files in the order below. Knit from inside the folder, so read_csv("data/...") finds the CSV that sits next to the script.

Run the same examples in the browser (no R install): iedaejin.github.io/mir-prob-stats-webrarian. That site runs .R scripts (each .Rmd has a matching .R). Open a session folder so read_csv("data/...") works. Sessions 1–2: use 01-unpop-csv.R / 02-resume-csv.R, not library(qss). Knit the .Rmd files here in RStudio or Posit Cloud.

Once, before the first knit

install.packages(c("rmarkdown", "knitr", "tidyverse", "devtools"))

# if you have not installed the `devtools` package
# install.packages("devtools")
library("devtools")
install_github("kosukeimai/qss-package", build_vignettes = TRUE)

Sessions 1 and 2 load datasets with library(qss). Later sessions use the CSV in that session’s data/ folder. Those CSV files are course examples. They are not the QSS authors’ files. The QSS files used in the Posit Cloud labs are in mir-prob-stats.

Run the chunk, then say what the number means. A slope, a p-value, or an interval does not by itself make the claim causal.

Source: github.com/iedaejin/mir-prob-stats-r-examples.

Session 1 — Introduction

Datasets come from the qss package (UNpop).

Session 2 — Causation

Datasets come from the qss package (resume, and social for the later GOTV file).

Session 3 — One variable

Reads data/country_indicators.csv in this folder.

Session 4 — Correlation, part 1

Reads data/country_indicators.csv in this folder.

Session 5 — Correlation, part 2

Reads data/country_indicators.csv in this folder. No new required chapter; same idea as session 4.

Session 6 — Regression, part 1

Reads data/country_indicators.csv in this folder. Description and prediction, not a cause.

Session 7 — Regression, part 2

Reads data/country_indicators.csv in this folder.

Session 9 — Probability, part 1

Reads data/survey_attitudes.csv in this folder.

Session 10 — Probability, part 2

10-survey-rv.Rmd reads data/survey_attitudes.csv. The other two files simulate coin-toss style draws.

Session 11 — Estimation and uncertainty

Reads data/survey_attitudes.csv in this folder.

Session 12 — Hypothesis testing

Reads data/survey_attitudes.csv in this folder.

Session 13 — Reversion to the mean

13-countries.Rmd reads data/country_indicators.csv. The other two files simulate.

Session 14 — Correlation and causation

Reads data/country_indicators.csv and data/survey_attitudes.csv in this folder.

Session 16 — Randomized experiments, part 1

Reads data/diplomacy_experiment.csv in this folder. The QSS social-pressure file is 02-causation/02-social.Rmd.

Session 17 — Randomized experiments, part 2

Reads data/diplomacy_experiment.csv in this folder.

Session 18 — Confounders, part 1

Reads data/aid_observational.csv in this folder.

Session 19 — Confounders, part 2

Reads data/aid_observational.csv in this folder.

Session 20 — Mechanisms

Reads data/mechanism_diplomatic_contact.csv in this folder.