POLS 1600

Statistical Inference
and Course Review

Updated Apr 22, 2025

WebR Status

Installing package 1 out of 2: dplyr

Overview

Class Plan

  • Announcements
  • Feedback
  • Course Review
  • Statistical Inference
  • Final Projects

Annoucements

  • Lab 11/Assignment 3 this week
  • Next Tuesday, April 22, Work on Presentations/Drafts
  • Assignment 4 now due April 25.
  • April 29, Final Workshop
  • May 1 Class Presentations

Setup: Packages for today

## Pacakges for today
the_packages <- c(
  ## R Markdown
  "kableExtra","DT","texreg","htmltools",
  ## Tidyverse
  "tidyverse", "lubridate", "forcats", "haven", "labelled",
  ## Extensions for ggplot
  "ggmap","ggrepel", "ggridges", "ggthemes", "ggpubr", 
  "patchwork",
  "GGally", "scales", "dagitty", "ggdag", "ggforce",
  # Data 
  "COVID19","maps","mapdata","qss","tidycensus", "dataverse", 
  # Analysis
  "DeclareDesign", "easystats", "zoo"
)

## Define a function to load (and if needed install) packages

ipak <- function(pkg){
    new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
    if (length(new.pkg)) 
        install.packages(new.pkg, dependencies = TRUE)
    sapply(pkg, require, character.only = TRUE)
}

## Install (if needed) and load libraries in the_packages
ipak(the_packages)
   kableExtra            DT        texreg     htmltools     tidyverse 
         TRUE          TRUE          TRUE          TRUE          TRUE 
    lubridate       forcats         haven      labelled         ggmap 
         TRUE          TRUE          TRUE          TRUE          TRUE 
      ggrepel      ggridges      ggthemes        ggpubr     patchwork 
         TRUE          TRUE          TRUE          TRUE          TRUE 
       GGally        scales       dagitty         ggdag       ggforce 
         TRUE          TRUE          TRUE          TRUE          TRUE 
      COVID19          maps       mapdata           qss    tidycensus 
         TRUE          TRUE          TRUE          TRUE          TRUE 
    dataverse DeclareDesign     easystats           zoo 
         TRUE          TRUE          TRUE          TRUE 

Review

Three Modes of Inference

  • Descriptive

  • Causal

  • Predictive

Descriptive Inference

Summarize distributions and relationships in data

  • You should know how to:
    • Calculate and interpret measures:
    • Central Tendency
    • Dispersion
    • Association
  • Load, look at, wrangle, and describe data using:
    • Tables
    • Figures

Data Wrangling

The process of transforming data into a useable format

You should know how to:

  • Load, look at,and transform data into R
  • Get a HLO of the raw data:
    • Unit of observation
    • Dimensions of the data
    • Quickly summarize the distributions and values of variables
  • Recode the data to:
    • Replace values as NAs
    • Create categories, indicators (0,1), and factors
    • Transform predictors (e.g. standardizing predictors)
  • Reshape the data
    • Pivoting columns and rows
    • Joining data sets together.
  • Aggregate the data into summaries

Data Visualization

A tool for describing distributions and relationships

You should know:

  • The grammar of graphics:
    • Data
    • Aesthetic mappings
    • Geometries
  • How to generate common plots to describe:
    • Distributions
    • Relationships

Causal Inference

Causal Inference requires counterfactual comparisons

You should know:

  • Potential outcomes and DAGs

  • The fundamental problem of causal inference

  • Bias caused by:

    • Confounding (Coffee and Cancer)
    • Colliding (Dating Jerks)
  • Casual Identification in:

    • Experimental designs
    • Observational designs

Prediction with Linear Models

Linear regression provides a linear estimate of the conditional expectation function

You should know:

  • How linear regression works

  • What it means to control for predictors in a multiple regression

  • When and why we should control for predictors.

  • How to translate substantive claims into empirical expectations for our models

  • How to estimate and interpret these models using tables and figures

  • How to quantify uncertainty about these estimates using confidence intervals and hypothesis tests.

Quantifying Uncertainty

Probability

  • Probability describes the likelihood of an event

  • Random variables assign numeric values to all the events that could occur.

  • Probability distributions assign probabilities to every value of a random variable. Can be:

    • discrete
    • continuous
    • characterized by their expected values and variances
    • used to:
    • describe the data generating process
    • quantify uncertainty about estimates

Sampling Distributions and Standard Errors

  • A sampling distribution is a theoretical probability distribution of estimates obtained from taking repeated samples of size n from some population

    • A distribution of what we could have seen
  • A standard error is simply the standard deviation (σ) of the sampling distribution

    • A measure of how much our estimate could have varied.
  • Law of Large Numbers: As N→∞ x¯→μ

  • Central Limit Theorem: As N→∞ x¯∼N(μ,σ2)

Confidence Intervals

Confidence intervals provide a range of plausible values for our estimate

  • Three components:
    • Point Estimate (i.e. a mean, or coefficient)
    • Confidence Level (Often 95 percent by convention)
    • Margin of Error (+/- some range (typically 2*SD for 95 percent CI))
  • Confidence is about the interval
    • 95 percent of the intervals construct in this manner would contain the truth.

Hypothesis Testing

  • A hypothesis test quantifies how likely it is that we would observe what we did (our test statistic), if some claim about the world were true (our hypothesis, typically a null ).

  • If our claim were true, then under this null hypothesis, our test statistic would have a distribution centered around the truth.

  • A p-value which describes the probability of observing a test statistic as extreme or more extreme in a world where our null hypothesis was true

    • If our p-value is small (p<0.05), we reject the null hypothesis

      If our p-value is large (p>0.05), we fail to reject the null, or retain the null hypothesis

Relationship between CIs and Hypothsis Testing

  • Concept
  • Code
  • Table
  • Figure

We can think of a confidence interval as a range of hypotheses we would fail to reject with p<α

# Load Data
load(url("https://pols1600.paultesta.org/files/data/nes24.rda"))

# Fit Model
m1 <- lm_robust(dv_participation ~   education + income, df,
                se = "classical")

# Range of hypotheses for education
pval_ci_df <- tibble(
  # Hypothesized Betas for Education
  Hypothesis = seq(0, .32, length.out = 100),
  # Test Statistics
  Statistic = (m1$coefficients["education"] - Hypothesis) /
  m1$std.error["education"],
  # P-value for two sided test
  `p-value` = 2*pt(abs(Statistic), df = m1$df,lower.tail = F)
)

fig_pval_ci <- pval_ci_df %>% 
  ggplot(aes(Hypothesis, `p-value`))+
  geom_line()+
  geom_vline(xintercept = m1$coefficients["education"],
             linetype = "solid",
             col = "red")+
  geom_vline(xintercept = m1$conf.low["education"],
             linetype = "dotted")+
  geom_vline(xintercept = m1$conf.high["education"],
             linetype = "dotted")+
  geom_hline(yintercept = 0.05,
             linetype = "dashed")+
  labs(
    x = "Hypothesized Education, Coefficent",
    title = "Confidence intervals are a range\nof plausible hypotheses"
  )+
  theme_minimal()
Statistical models
  Model 1
(Intercept) 0.31*
  [ 0.14; 0.48]
education 0.17*
  [ 0.12; 0.21]
income 0.01
  [-0.01; 0.03]
R2 0.04
Adj. R2 0.04
Num. obs. 1687
RMSE 1.29
* 0 outside the confidence interval.

Four Possible Outcomes of a hypothesis Test

  • False Positive: (Type I Error)
    • Rejecting a True H0.
    • τ=0, but τ^ has a p<0.05
    • Probability=α
  • True Positive: (Correct Decision)
    • Rejecting a false H0:
    • τ≠0, and τ^ has a p<0.05
    • Occurs with Probability = 1−β
  • True Negative: (Correct Decision)
    • Failing to reject a True H0:
    • τ=0, and τ^ has a p>0.05
    • Occurs with Probability = 1−α
  • False Negative: (Type II Error)
    • Failing to reject a false H0.
    • τ≠0 but τ^ has a p>0.05
    • Occurs with Probability= β

Type 1 and 2 Errors

Source

Statistical Power

Installing package 1 out of 2: dplyr

  • Concept
  • Power
  • Comments
  • Consider two distributions of statistics under
    • a null of no effect (H0)
    • an effect of τ (H1)
  • For a significance threshold of α we would:
    • Fail to reject the null β (Type II Errors)
    • Correctly reject the null 1−β (Statistical Power)

Try changing τ (the effect size), and se (the standard deviation of the effect)

1
power_function(tau = 2, se = 1, pval = 0.05)

Power is a function of:

  • Sample size (N)
    • Larger samples, smaller standard errors (LLN)
  • Effect size (τ)
    • Bigger effects less overlap
  • Significance threshold (α)
    • Decrease Type 1 (False Positives) error leads to increased Type 2 (False Negatives)
  • The distribution of the data
    • Variance, asympotitc approximations

Final Projects

Strucutre of Final Paper and Drafts

Assignment 4: Seven sections

  1. Introduction (5 percent, ~ 4 paragraphs)
  2. Theory and Expectations (10 percent, ~4+ paragraphs)
  3. Data (20 percent ~ 4+ paragraphs)
  4. Design (25 percent ~ 5+ paragraphs)
  5. Results (25 percent ~ 5+ paragraphs)
  6. Conclusion (5 percent ~ 3+ paragraphs)
  7. Appendix (10 percent ~ Variable codebook and all the R code for your project)

For Thursday

  • Assignment 3

  • Download template

  • Create shared google drive.

  • Make progress on:

      1. Data (20 percent ~ 4+ paragraphs)
      1. Design (25 percent ~ 5+ paragraphs)
      1. Results (25 percent ~ 5+ paragraphs)

Motivating Questions

In the reset of today’s class, we’ll get some practice putting together the various skills you need for your drafts by exploring the following:

  • How does partisanship shape American’s perceptions of vaccines?

  • Who is skeptical of the benefits of vaccination?

  • Have these perceptions about vaccines changed over time?

Tasks:

To explore these questions, we need to

  • Get setup to work

  • Load our data

  • Recode our data

  • Summarize our data

  • Specify our expectations

  • Estimate models to test these expectations

  • Present and interpret results using

    • Tables
    • Figures
    • Confidence intervals
    • Hypothesis tests

New packages

To easily load survey data for our question, we’ll need the anesr package, which loads data from the American National Election Studies into R

# # Uncomment to uninstall package to download NES survey data
# library(devtools)
# install_github("jamesmartherus/anesr")
require(anesr)

Packages for today

## Pacakges for today
the_packages <- c(
  ## R Markdown
  "kableExtra","DT","texreg","htmltools",
  ## Tidyverse
  "tidyverse", "lubridate", "forcats", "haven", "labelled",
  ## Extensions for ggplot
  "ggmap","ggrepel", "ggridges", "ggthemes", "ggpubr", 
  "patchwork",
  "GGally", "scales", "dagitty", "ggdag", "ggforce",
  # Data 
  "COVID19","maps","mapdata","qss","tidycensus", "dataverse", 
  # Analysis
  "DeclareDesign", "easystats", "zoo"
)

## Define a function to load (and if needed install) packages

ipak <- function(pkg){
    new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
    if (length(new.pkg)) 
        install.packages(new.pkg, dependencies = TRUE)
    sapply(pkg, require, character.only = TRUE)
}

## Install (if needed) and load libraries in the_packages
ipak(the_packages)
   kableExtra            DT        texreg     htmltools     tidyverse 
         TRUE          TRUE          TRUE          TRUE          TRUE 
    lubridate       forcats         haven      labelled         ggmap 
         TRUE          TRUE          TRUE          TRUE          TRUE 
      ggrepel      ggridges      ggthemes        ggpubr     patchwork 
         TRUE          TRUE          TRUE          TRUE          TRUE 
       GGally        scales       dagitty         ggdag       ggforce 
         TRUE          TRUE          TRUE          TRUE          TRUE 
      COVID19          maps       mapdata           qss    tidycensus 
         TRUE          TRUE          TRUE          TRUE          TRUE 
    dataverse DeclareDesign     easystats           zoo 
         TRUE          TRUE          TRUE          TRUE 

Data

Now that we have anesr installed, let’s load data from the 2016 and 2020 National Election Studies:

# Load data
data(timeseries_2016, package = "anesr")
data(timeseries_2020, package = "anesr")

And copy those data frames into new dataframes with shorter names

# Rename datasets
nes16 <- timeseries_2016
nes20 <- timeseries_2020

Finding variables: Outcomes

Our primary outcome of interest are beliefs about vaccines.

Variables V162162x in the 2016 NES and V202383x in the 2020 NES will serve as our primary outcome of interest, summarizing respondents answer to the following question:

Do the health benefits of vaccinations generally outweigh the risks, do the risks outweigh the benefits, or is there no difference?

Finding variables: Predictors

Similarly, V161158x in the 2016 NES and V201231x in the 2020 NES will serve our key predictor (respondent’s partisanship).

Finally, we’ll control respondents’ age, using V161267 in the 2016 NES and V201507x in the 2020 NES

Examine Distributions: Vaccine Beliefs

The variables in the NES datasets are of a class labelled which allows numeric values to have substantive labels

class(nes16$V162162x)
[1] "haven_labelled"

Our outcome variable has the following labels:

labelled::val_labels(nes16$V162162x)
                                   -9. Refused 
                                            -9 
                                -8. Don't know 
                                            -8 
-7. No post data, deleted due to incomplete IW 
                                            -7 
                -6. No post-election interview 
                                            -6 
                      1. Benefits much greater 
                                             1 
                2. Benefits moderately greater 
                                             2 
                  3. Benefits slightly greater 
                                             3 
                              4. No difference 
                                             4 
                     5. Risks slightly greater 
                                             5 
                   6. Risks moderately greater 
                                             6 
                         7. Risks much greater 
                                             7 

And distribution of responses:

table(nes16$V162162x)

  -9   -8   -7   -6    1    2    3    4    5    6    7 
  21   28   86  536 1687  726  258  539   96  211   82 

Recoding outcome variables

  • Tasks
  • Code

What transformations do we need to make to V162162x in nes16 and V202383x in nes20 so that these variables are suitable for analysis?

  • Recode negative values to be NA

  • Reverse code so that higher values indicate greater belief vaccines benefits

  • Create an indicator of people who are vaccine skeptics

nes16 %>%
  mutate(
    # Make Negative values NA, Reverse Code So Higher Values = Benefits > Risks
    vaccine_benefits = ifelse(V162162x < 0, NA, (V162162x-8)*-1),
    # Indicator of vaccine skepticism (Risks > Benefits)
    vaccine_skeptic01 = case_when(
      vaccine_benefits > 4 ~ 0,
      vaccine_benefits <= 4 ~ 1,
      TRUE ~ NA_real_
    )
  ) -> nes16 # Save recodes to nes16

nes20 %>%
  mutate(
    # Make Negative values NA, Reverse Code So Higher Values = Benefits > Risks
    vaccine_benefits = ifelse(V202383x < 0, NA, (V202383x-8)*-1),
    # Indicator of vaccine skepticism (Risks > Benefits)
    vaccine_skeptic01 = case_when(
      vaccine_benefits > 4 ~ 0,
      vaccine_benefits <= 4 ~ 1,
      TRUE ~ NA_real_
    )
  ) -> nes20 # Save recodes to nes20

Recoding Predictors

  • Tasks
  • Code

Now we repeat this process for our key predictor, partisanship.

  • Recode partisanship variables V161158x in nes16 and V201231x in nes20

  • Create indicators from this recoded variable that classify partisanship as categorical variable (with Democrats as the reference category)

And our covariate, age variables V161267 in nes16 and V201507x in nes20

  • Recode negative values to be NA
nes16 %>%
  mutate(
    pid = ifelse(V161158x < 0, NA, V161158x),
    pid3cat = case_when(
      pid < 4 ~ "Democrat",
      pid == 4 ~ "Independent",
      pid > 4 ~ "Republican",
      TRUE ~ "Independent"
    ) %>% factor(., levels = c("Democrat","Independent","Republican")),
    age = ifelse(V161267 < 0, NA, V161267)
  ) -> nes16

## Recoding Partisanship (V201231x) in 2020 NES

nes20 %>%
  mutate(
    pid = ifelse(V201231x < 0, NA, V201231x),
    pid3cat = case_when(
      pid < 4 ~ "Democrat",
      pid == 4 ~ "Independent",
      pid > 4 ~ "Republican",
      TRUE ~ "Independent"
    ) %>% factor(., levels = c("Democrat","Independent","Republican")),
    age = ifelse(V201507x < 0, NA, V201507x)
  ) -> nes20

Progress Report

To explore these questions, we need to

  • Get setup to work ✅

  • Load our data ✅

  • Recode our data ✅

  • Summarize our data📥

  • Specify our expectations

  • Estimate models to test these expectations

  • Presenting and interpreting results using

    • Tables
    • Figures
    • Confidence intervals
    • Hypothesis tests

Descriptive statistics (2016)

  • Tasks
  • Code
  • Table
  1. Create the_vars

  2. Select these variables

  3. Pivot the data

  4. Calculate summary statistics

  5. Format as an html table

# 1. Create a object with the names of the variables you want to summarize
the_vars <- c("vaccine_skeptic01","pid","age")
# 2. Select these variables
nes16 %>%
  select(all_of(the_vars)) %>%
# 3. Pivot the data
  pivot_longer(
    cols = all_of(the_vars),
    names_to = "Variable"
  )%>%
  mutate(
    Variable = factor(Variable, levels = the_vars)
  )%>%
  arrange(Variable)%>%
  dplyr::group_by(Variable)%>%
  # 3. Calculate summary statistics
  dplyr::summarise(
    min = min(value, na.rm=T),
    p25 = quantile(value, na.rm=T, prob = 0.25),
    Median = quantile(value, na.rm=T, prob = 0.5),
    mean = mean(value, na.rm=T),
    p75 = quantile(value, na.rm=T, prob = 0.25),
    max = max(value, na.rm=T),
    missing = sum(is.na(value))
  ) -> sum_df 

sum_tab <- 
knitr::kable(sum_df,
             caption = "Descriptive Statistics",
             digits = 2) %>%
  kableExtra::kable_styling() %>%
  kableExtra::pack_rows("Outcome", start_row = 1, end_row =1) %>%
  kableExtra::pack_rows("Key Predictors", start_row = 2, end_row =2) %>%
  kableExtra::pack_rows("Covariates", start_row = 3, end_row =3)
Descriptive Statistics
Variable min p25 Median mean p75 max missing
Outcome
vaccine_skeptic01 0 0 0 0.26 0 1 671
Key Predictors
pid 1 2 4 3.86 2 7 23
Covariates
age 18 34 50 49.58 34 90 121

Progress Report

To explore these questions, we need to

  • Get setup to work ✅

  • Load our data ✅

  • Recode our data ✅

  • Summarize our data ✅

  • Specify our expectations 📥

  • Estimate models to test these expectations

  • Presenting and interpreting results using

    • Tables
    • Figures
    • Confidence intervals (review)
    • Hypothesis tests (new!)

Specificying Expecations

Consider our first two motivating questions

  • How does partisanship shape American’s perceptions of vaccines?

  • Who is skeptical of the benefits of vaccination?

And some illustrative stereotypes:

  • “Republicans are anti-science”
  • “Liberal always fall for Goopy pseudo-science”
  • “Independents love to do their own research”

What are the empirical implications of these claims?

Specificying Expecations

Similarly, consider our third question:

  • Have these perceptions about vaccines changed over time?

And some similar simplified claims:

  • “The Covid-19 vaccine is a miracle of modern science”
  • “Social media is rife with misinformation about the Covid-19 vaccine”
  • “Politicians are politicizing vaccine politics for political benefits”

What are the empirical implications of these claims?

Specificying Expecations

Our goal is to take claims/conventional wisdom/theories, and derive their empirical implications:

  • H1: Partisan Differences in Vaccine Skepticism
    • H1a: Republicans will be the most skeptical of vaccines
    • H1b: Democrats will be the most skeptical of vaccines
    • H1c: Independents will be the most skeptical of vaccines

Specificying Expecations

  • H2: Temporal Differences in Vaccine Skepticism
    • H2a: Vaccine skepticism will decrease from 2016 to 2020 with the widespread roll out of the Covid-19 vaccine
    • H2b: Vaccine skepticism will increase from 2016 to 2020 with increased amounts of misinformation about the Covid-19 vaccine
  • H3: Partisan Difference in Vaccine Skepticism Over Time Partisan differences in Vaccine Skepticism will increase from 2016 to 2020 with the politicization of Covid-19 policies

Motivating your expectations

In your final papers, unlike in these slides, your expectations should be grounded in existing theory, research, and evidence. For the present question, we might cite sources such as:

  • Enders, Adam M., and Steven M. Smallpage. “Informational cues, partisan-motivated reasoning, and the manipulation of conspiracy beliefs.” Political Communication 36.1 (2019): 83-102.

  • Stecula, Dominik A., and Mark Pickup. “How populism and conservative media fuel conspiracy beliefs about COVID-19 and what it means for COVID-19 behaviors.” Research & Politics 8.1 (2021): 2053168021993979.

  • Jennings, Will, et al. “Lack of trust, conspiracy beliefs, and social media use predict COVID-19 vaccine hesitancy.” Vaccines 9.6 (2021): 593.

  • Hollander, Barry A. “Partisanship, individual differences, and news media exposure as predictors of conspiracy beliefs.” Journalism & Mass Communication Quarterly 95.3 (2018): 691-713.

Model Specification

Translate these expectations into empirical models requires choices about how to specify our models

  • How should we measure/operationalize our outcome

    • Should we measure beliefs about vaccines with 7-point ordinal scale or as a binary indicator of vaccine skepticism
  • How should we measure/operationalize our key predictor(s)

    • Should we measure partisanship using a 7 point scale or as categorical variable?
  • What should we control for in our model?

    • Factors likely to predict both our outcome and our key predictor of interest
  • There are rarely definitive answers to these questions. Instead, we will often estimate multiple models to try and show that our findings are robust to alternative specifications

Model Specification

For your projects, every group will almost surely estimate some form of the following:

  1. Baseline bivariate model: The simplest test of the relationship between your outcome and key predictor

  2. Multiple regression model: A test of the robustness of this relationship, controlling for alternative explanations

Model Specification

In practice, I suspect you may estimate multiple regression models such as:

  • Alternative specifications/operationalizations of outcomes and predictors

  • Interaction models to test conditional relationships

  • Polynomial models to test non-linear relationships

Translating Theoretical Claims into Empirical Expectations

Before we estimate our models in R, we will write down our models formally and empirical implications of our theoretical expectations in terms of the coefficients of our model.

For example, our baseline model might be:

Vaccine Skepticism=β0+β1PID7pt+Xβ+ϵ

If β1 is positive this is consistent with H1a (greater skepticism among Republicans), - If β2 is negative this is consistent with H1b (greater skepticism among Democrats),

  • But how could we test H1c – greater skepticism among Independents, who are “4s” on PID7pt?

Translating Theoretical Claims into Empirical Expectations

We could fit a polynomial regression, including both partisanship and “partissanship squared” to allow the relationship between partisanship and vaccine skepticism to vary non-linearly

Vaccine Skepticism=β0+β1PID7pt+β2PID7pt2+Xβ+ϵ

Translating Theoretical Claims into Empirical Expectations

Or we could estimate a model treating Partisanship as a categorical variable rather than an ordinal interval variable.

In our recoding, we set "Democrat" to be the first level of the variable pid3cat, so the model R will estimate by default is:

Vaccine Skepticism=β0+β1PIDInd+β2PIDRep+Xβ+ϵ

Testing differences over time

Testing Hypotheses 2 and 3 involve making comparisons across models estimated on data from different surveys.

Formally, testing these expectations is a little more complicated

  • we could pool our two surveys together include an interaction term for survey year

For our purposes, we’ll treat these as more qualitative/exploratory hypotheses:

  • H2a/b implies overall rates of vaccine skepticism will be lower/higher in 2020 compared to 2016

  • H3 implies that whatever partisan differences we find in 2016 should be larger in 2020.

Progress Report

To explore these questions, we need to

  • Get setup to work ✅

  • Load our data ✅

  • Recode our data ✅

  • Specify our expectations ✅

  • Estimate models to test these expectations 📥

  • Presenting and interpreting results using

    • Tables
    • Figures
    • Confidence intervals
    • Hypothesis tests

Estimating Empirical Models

Having derived empirical implications of our theoretical expectations expressed in terms of linear regressions, now we simply have to estimate our models in R.

When estimating the same model on different datasets we can write the formulas once

f1 <- formula(vaccine_skeptic01 ~ pid + age)
f2 <- formula(vaccine_skeptic01 ~ pid + I(pid^2) + age)
f3 <- formula(vaccine_skeptic01 ~ pid3cat + age)

Estimating Empirical Models

And then pass it to lm() with different data arguments:

m1_2016 <- lm(formula = f1, data = nes16)
m1_2020 <- lm(formula = f1, data = nes20)
m2_2016 <- lm(formula = f2, data = nes16)
m2_2020 <- lm(formula = f2, data = nes20)
m3_2016 <- lm(formula = f3, data = nes16)
m3_2020 <- lm(formula = f3, data = nes20)

Estimating Empirical Models

If you’ve:

  • coded your data correctly

  • developed clear testable implications from your theoretical expectations

Specifying and estimating empirical models is straightforward. Literally a few lines of code.

Progress Report

To explore these questions, we need to

  • Get setup to work ✅

  • Load our data ✅

  • Recode our data ✅

  • Specify our expectations ✅

  • Estimate models to test these expectations ✅

  • Present our results 📥

    • Tables
    • Figures
    • Confidence intervals
    • Hypothesis testing

Presenting and Interpreting Your Results

Presenting and interpreting your results is requires both art and science.

Your goal is to tell a story with your results,

Let’s start by producing a regression table, which provides a concise summary of multiple regression models.

Regression Tables

  • Tasks
  • Code
  • Basic
  • Fetch
  • Giving the variables in substantive names

  • Reporting coefficients to 3 decimal places

  • Using a single significance threshold of p<0.05

  • Giving the models custom names

  • Adding a header to group models by year

  • Changing the caption of the table

# Basic
tab_basic <- texreg::htmlreg(
  list(m1_2016,m2_2016,m3_2016,
       m1_2020,m2_2020,m3_2020)
)

# Formatted
tab_fetch <- texreg::htmlreg(
  list(m1_2016,m2_2016,m3_2016,
       m1_2020,m2_2020,m3_2020),
  # Reporting coefficients to 3 decimal places
  digits = 3,
  # Using a single significance threshold 
  stars = 0.05,
  # Giving the variables in substantive names
  custom.coef.names = c(
    "(Intercept)",
    "PID (7pt)",
    "Age",
    "PID<sup>2</sup> (7pt)",
    "Independent",
    "Republican"
  ),
  # Use SE instead o CIs
  include.ci = F,
  # Giving the models custom names
  custom.model.names = paste("(",c(1:6),")", sep=""),
  # Adding a header to group models by year
  custom.header = list("NES 2016" = 1:3, "NES 2020" = 4:6),
  # Changing the caption of the table
  caption = "Partisanship and Vaccine Skepticism"
)
Statistical models
  Model 1 Model 2 Model 3 Model 4 Model 5 Model 6
(Intercept) 0.46*** 0.35*** 0.42*** 0.34*** 0.32*** 0.35***
  (0.02) (0.04) (0.02) (0.02) (0.02) (0.02)
pid -0.00 0.06***   0.02*** 0.04***  
  (0.00) (0.02)   (0.00) (0.01)  
age -0.00*** -0.00*** -0.00*** -0.00*** -0.00*** -0.00***
  (0.00) (0.00) (0.00) (0.00) (0.00) (0.00)
pid^2   -0.01***     -0.00  
    (0.00)     (0.00)  
pid3catIndependent     0.17***     0.20***
      (0.02)     (0.02)
pid3catRepublican     -0.02     0.10***
      (0.02)     (0.01)
R2 0.02 0.03 0.04 0.03 0.03 0.05
Adj. R2 0.02 0.03 0.04 0.03 0.03 0.04
Num. obs. 3494 3494 3507 7041 7041 7052
***p < 0.001; **p < 0.01; *p < 0.05
Partisanship and Vaccine Skepticism
  NES 2016 NES 2020
  (1) (2) (3) (4) (5) (6)
(Intercept) 0.458* 0.350* 0.417* 0.343* 0.318* 0.352*
  (0.025) (0.035) (0.023) (0.018) (0.024) (0.016)
PID (7pt) -0.005 0.064*   0.021* 0.037*  
  (0.003) (0.016)   (0.002) (0.011)  
Age -0.004* -0.003* -0.004* -0.004* -0.004* -0.003*
  (0.000) (0.000) (0.000) (0.000) (0.000) (0.000)
PID2 (7pt)   -0.009*     -0.002  
    (0.002)     (0.001)  
Independent     0.175*     0.200*
      (0.023)     (0.016)
Republican     -0.016     0.100*
      (0.016)     (0.011)
R2 0.023 0.028 0.042 0.032 0.032 0.045
Adj. R2 0.022 0.027 0.042 0.032 0.032 0.045
Num. obs. 3494 3494 3507 7041 7041 7052
*p < 0.05

Telling a Story with Regression

First, provide an overview the models presented in the table

  • Explain what each model is doing conceptually

Then start with your simplest model (first column)

  • Use this as a chance to explain core concepts from the course
    • What is regression
    • How should I interpret a coefficient substantively
    • How should I interepret the statistical signficance of a give coefficient
  • As you move from left to right (simple to more complex)
    • you need not interpret every single coefficient in the model
    • instead highlight the factors that are important for the reader to note (e.g. a comparison between one coefficient in model or another.)

Example

Table 1 presents the results of three specifications exploring the relationship between partisanship and vaccine skepticism using data from the 2016 (Models 1-3) and 2020 (Models 4-5) National Election Studies.

Models 1 and 4 operationalize partisanship as a 7-point scale, where 1 corresponds to Strong Democrats, 4 to Indepndents, and 7 to Strong Republicans in the 2016 (Model 1) and 2020 (Model 2) surveys.

Models 2 and 5 allow the relationship between partisanship and vaccine skepticism to vary non-linear again for the 2016 (Model 2) and 2020 (Model 5) elections.

Models 3 and 6 treat partisanship as categorical variable, describing how Independents and Republicans differ from Democrats, the reference category in these models.

All models control age, since (put in substantive justification for controlling for age here)

Story: Testing for Partisan Differences

  • The results from Model 1 provide little initial evidence for partisan differences in vaccine skepticism in the 2016 Election.

    • The coefficient on the partisanship variable is -0.005, suggesting that a unit increase in partisanship (going from being a Strong Democrat to just a Democrat, or an Independent to an independent who leans Republican), is associated with just a 0.5 percentage point increase in the probability of being a vaccine skeptic (believing that the risks of vaccination outweigh the benefits or that their is no difference in the risks versus benefits).
  • Furthermore the 95-percent confidence interval for this estimate (-0.011, 0.002) brackets 0, suggesting the true population estimate from this model could be either positive or negative. Similarly, we fail to reject the null hypothesis that the true coefficient on partisanship in this model is 0 as the test statistic for this estimate ( -1.38) corresponds to a p-value of 0.168 suggesting that we would see test statistics this large or larger fairly often when the true relationship was 0.

  • In sum, the results from Model 1 provide little support for any of the expectations described by H1

Testing for Partisan Differences: Model 2

  • While coefficients from Model 1 suggest little evidence of partisan differences in vaccine skepticism, the coefficients on both partisanship, and partisanship squared are statistically significant (p < 0.05).

Interpreting Model 2

  • Task
  • Figure
  • Interpretation
  • The coefficients from polynomial regressions can be difficult to interpret jointly and so Figure 1 presents the predicted values from Model 2, holding age constant at its sample mean.
pred_df_m2 <- expand_grid(
  pid = 1:7,
  age = mean(nes16$age, na.rm=T)
)
pred_df_m2 <- cbind(pred_df_m2, predict(m2_2016,pred_df_m2, interval ="confidence"))

fig_m2 <- pred_df_m2 %>%
  ggplot(aes(pid, fit, ymin =lwr, ymax =upr))+
  geom_line()+
  geom_ribbon(alpha=.2, fill="grey")+
  theme_bw()+
  labs(x = "Partisanship",
       y = "Predicted Vaccine Skepticism",
       title = "Independents are the most skeptical of vaccines",
       subtitle = "Data: 2016 NES"
       )
fig_m2

We see from Model 2 that 29.7 percent [27.3%, 32.1%] of Independents in the 2016 NES were predicted to be vaccine skeptics compared to 23.7 percent [20.8%, 26.5%] of Strong Democrats and only 20.1 percent [16.9%, 23.3%] of Strong Republicans.

Interpreting Model 3

  • Interpretation
  • Code

Model 3 tells a similar story to model 2. Again, adjusting for differences in vaccine skepticism explained by age, Model 3 predicts that 41.7 percent [37.7%, 45.6%] of Independents in the 2016 NES are vaccine skeptics compared to 24.2 percent [22.1%, 26.2%] of Democrats, and 22.6 percent [20.4%, 24.8%] of Republicans.

Note the coefficients from Model 3 imply that the differences between Independents and Democrats are statistically significant (βInd=0.175,p<0.05), the differences between Republicans and Democrats are not (βRep=−0.004,p=0.31)

pred_df_m3 <- expand_grid(
  pid3cat = c("Democrat", "Independent","Republican"),
  age = mean(nes16$age, na.rm=T)
)
pred_df_m3 <- cbind(pred_df_m3, predict(m3_2016,pred_df_m3, interval ="confidence"))
pred_df_m3
      pid3cat      age       fit       lwr       upr
1    Democrat 49.58231 0.2419547 0.2211228 0.2627867
2 Independent 49.58231 0.4169043 0.3773539 0.4564547
3  Republican 49.58231 0.2261496 0.2038046 0.2484947

tab_fetch
Partisanship and Vaccine Skepticism
  NES 2016 NES 2020
  (1) (2) (3) (4) (5) (6)
(Intercept) 0.458* 0.350* 0.417* 0.343* 0.318* 0.352*
  (0.025) (0.035) (0.023) (0.018) (0.024) (0.016)
PID (7pt) -0.005 0.064*   0.021* 0.037*  
  (0.003) (0.016)   (0.002) (0.011)  
Age -0.004* -0.003* -0.004* -0.004* -0.004* -0.003*
  (0.000) (0.000) (0.000) (0.000) (0.000) (0.000)
PID2 (7pt)   -0.009*     -0.002  
    (0.002)     (0.001)  
Independent     0.175*     0.200*
      (0.023)     (0.016)
Republican     -0.016     0.100*
      (0.016)     (0.011)
R2 0.023 0.028 0.042 0.032 0.032 0.045
Adj. R2 0.022 0.027 0.042 0.032 0.032 0.045
Num. obs. 3494 3494 3507 7041 7041 7052
*p < 0.05

Testing for Differences Over Time

The results for the 2016 NES suggest political independents are most skeptical of vaccines.

The results for 2020 suggest the relationship between partisanship and vaccine skepticism has changed overtime.

  • The coefficient on partisanship in model 4 is now positive and statistically significant (p < 0.05), suggesting that as respondents become more Republican, they are more likely to be skeptical of vaccines

  • The coefficients from Model 5 suggest the relationship between partisanship skepticism is non linear, which is confirmed by model 6.

  • In Model 6, we see that independents remain the most skeptical of vaccines in 2020 (β=0.20,p<0.05), but that Republicans now tend to be more skeptical of vaccines than Democrats (β=0.10,p<0.05)

Regression Discontinuity Design

Motivating Example

  • Do Members of Parliament in the UK get richer from holding office (QSS Chapter 4.3.4)

Eggers and Hainmueller (2009) ]

Logic of the Regression Discontinuity Design (RDD)

  • What’s the effect of holding elected office in the UK on personal wealth?

  • People who win elections differ in many ways from people who lose elections.

  • Logic of an RDD:

    • Just look at the wealth of individuals who either narrowly won or lost elections.

    • Candidates close to 50 percent cutoff (discontinuity) should be more comparable (better counterfactuals)

Eggers and Hainmueller (2009)

  • Data
  • Variables
library(qss)
data(MPs)
glimpse(MPs)
Rows: 427
Columns: 10
$ surname    <chr> "Llewellyn", "Morris", "Walker", "Walker", "Waring", "Brown…
$ firstname  <chr> "David", "Claud", "George", "Harold", "John", "Ronald", "Le…
$ party      <chr> "tory", "labour", "tory", "labour", "tory", "labour", "tory…
$ ln.gross   <dbl> 12.13591, 12.44809, 12.42845, 11.91845, 13.52022, 12.46052,…
$ ln.net     <dbl> 12.135906, 12.448091, 10.349009, 12.395034, 13.520219, 9.63…
$ yob        <int> 1916, 1920, 1914, 1927, 1923, 1921, 1907, 1912, 1905, 1920,…
$ yod        <int> 1992, 2000, 1999, 2003, 1989, 2002, 1987, 1984, 1998, 2004,…
$ margin.pre <dbl> NA, NA, -0.057168204, -0.072508894, -0.269689620, 0.3409586…
$ region     <chr> "Wales", "South West England", "North East England", "Yorks…
$ margin     <dbl> 0.05690404, -0.04973833, -0.04158868, 0.02329524, -0.230005…
Variable Description
surname surname of the candidate
firstname first name of the candidate
party party of the candidate (labour or tory)
ln.gross log gross wealth at the time of death
ln.net log net wealth at the time of death
yob year of birth of the candidate
yod year of death of the candidate
margin.pre margin of the candidate’s party in the previous election electoral
region region
margin margin of victory (vote share)
MPs %>%
  ggplot(aes(margin, ln.net))+
  geom_point(shape=1)+
  facet_grid(~party)+
  geom_smooth(data =MPs %>%
                filter(margin <0),
              method = "lm")+
  geom_smooth(data =MPs %>%
                filter(margin >0),
              method = "lm")+
  theme_bw() -> fig_rdd

RDD Notation

  • X is a forcing variable
  • Treatment D is a determined by X

Di=1{Xi>c}

  • X is the margin variable in the example data, and D=1 if margin is greater than 0 (i.e. the candidate won the election)

  • Interested in the differences in the outcome at the threshold

limx↓cE[Yi|X=x]−limx↑cE[Yi|X=x]

Causal Identification with an RDD

If we assume E[Yi(0)|X=x] and E[Yi(1)|X=x] are continuous in x, then we can estimate a (local) ATE at the threshold:

ATERDD=E[Y(1)−Y(0)|Xi=c]=E[Y(1)|Xi=c]−E[Y(0)|Xi=c]=limx↓cE[Yi|X=x]−limx↑cE[Yi|X=x]

Continuity Assumption

Cunningham (2022)

Causal Identification with an RDD

  • The continuity assumption is a formal way of saying that observations close to the threshold are good counterfactuals for each other

  • We can’t prove this assumption

  • But if it holds, we should observe

    • no sorting around the cutoff (no self selection)

    • similar distributions of covariates around the cutoff (balance tests)

    • no effect of treatment on things measured pre-treatment (placebo tests)

Instrumental Variables

Instrumental Variables

Instrumental variables are an economists favorite tool for dealing with omitted variable bias

  • We have some non random treatment whose effects we’d like to assess
  • We’re worried that these effects are confounded by some unobserved, omitted variable, that influences both the treatment and the outcome
  • We find an instrumental variable that satisfies the following:
    • Randomization
    • Excludability
    • First-stage relatioship
    • Monotonicity
  • Allowing us estimate a Local Average Treatment Effect (LATE) using the only the variation in our treatment is exogenous (uncorrelated with ommited variables)

IV Assumption: Randomization

  • No path from U to Z

Source

IV Assumption: Excludability

  • No path from Z to Y

Source

IV Assumption: First Stage

  • Path from Z to D

Source

IV Assumption: Monotonicity

  • Di(Z=1)≥Di(Z=0)
  • “No Defiers”

Source

Compliance

With a binary treatment, D and binary instrument Z there are four types of compliance

Type Di(Z=1) Di(Z=0)
Always Takers 1 1
Never Takers 0 0
Compliers 1 0
Defiers 0 1
  • Assuming Monotonicity means there are “No Defiers”

Estimating the Local Average Treatment Effect

If we believe our assumptions of:

  • Randomization
  • Excludability
  • First-stage relationship
  • Monotonicity

Then we can estimate Local Average Treatment Effect (LATE) sometimes called the Complier Average Treatment Effect (CATE)

Estimating the Local Average Treatment Effect

It can be shown that the LATE:

LATE=E[Y|Z=1]−E[Y|Z=0]E[D|Z=1]−E[D|Z=0]=ATEZ→YATEZ→D

Where:

  • ATEZ→Y is the known as the “Intent to Treat” effect (ITT) (i.e. the effect of being assigned to treatment)

  • ATEZ→D is the “effect” of being assigned to treatment on actually receiving treatment

Example: Earnings and Military Service

Adapted from Edward Rubin

Example: If we want to estimate the effect of veteran status on earnings,

(1)Earningsi=β0+β1Veterani+ui

We would love to calculate Earnings1i−Earnings0i, but we can’t.

And OLS will likely be biased for (1) due to selection/omitted-variable bias.

Introductory example

Imagine that we can split veteran status into an exogenous (as-if random, unbiased) part and an endogenous (non-random, biased) part…

(1)Earningsi=β0+β1Veterani+ui=β0+β1(VeteraniExog.+VeteraniEndog.)+ui=β0+β1VeteraniExog.+β1VeteraniEndog.+ui⏟wi=β0+β1VeteraniExog.+wi

We could use this exogenous variation in veteran status to consistently estimate β1.

Q: What would exogenous variation in veteran status mean?

Introductory example

Q: What would exogenous variation in veteran status mean?

A1 Choices to enlist in the military that are essentially random—or at least uncorrelated with omitted variables and the disturbance.

A2 .No selection bias:

E⁡(Earnings0i∣Veterani=1)−E⁡(Earnings0i∣Veterani=0)=0

Instruments

  • Q: How do we isolate this exogenous variation in our explanatory variable?

  • A: Find an instrument (an instrumental variable).

  • Q: What’s an instrument?

  • A: An instrument is a variable that is

    1. correlated with the explanatory variable of interest (relevant),
    2. uncorrelated with the error term (exogenous).

Instruments

So if we want an instrument zi for endogenous veteran status in

Earningsi=β0+β1Veterani+ui

  1. Relevant: Cov⁡(Veterani,zi)≠0
  2. Exogenous: Cov⁡(zi,ui)=0

Instruments: Relevance

Relevance: We need the instrument to cause a change in (correlate with) our endogenous explanatory variable.

We can actually test this requirement using regression and a t test.

Example: For the veteran status, consider three potential instruments:

  1. Social security number

  2. Physical fitness

  3. Vietnam War draft

  • Probably not relevant uncorrelated with military service

  • Potentially relevant service may correlate with fitness

  • Relevant being drafted led to service

Instruments: Exogeneity

Exogeneity: The instrument to be independent of omitted factors that affect our outcome variable—as good as randomly assigned.

zi must be uncorrelated with our disturbance ui. Not testable.

Example: For the veteran status, consider three potential instruments:

  1. Social security number

  2. Physical fitness

  3. Vietnam War draft

  • Exogenous SSN essentially random

  • Not Exogenous fitness correlated with many things

  • Exogenous draft via lottery

Venn diagram explanation

In the following figures (Venn diagrams)

  • Each circle illustrates a variable.
  • Overlap gives the share of correlatation between two variables.
  • Dotted borders denote omitted variables.

Relevant and Exogenous

Relevant, Not Exogenous

Not Relevant and Not Exogenous

Relevant, Not Exogenous

Take-aways

  • Figure 1: Valid instrument (relevant; exogenous, e.g. draft lotto number)
  • Figure 2: Invalid instrument (relevant; not exogenous, e.g. physical fitness)
  • Figure 3: Invalid instrument (not relevant; not exogenous)
  • Figure 4: Invalid instrument (relevant; not exogenous)

IV Applications

IV Summary

Instrumental variables require a number of assumptions to yield credible causal claims:

  • Randomization
  • Excludability
  • First-stage relationship
  • Monotonicity

Estimation and inference of IVs is beyond the scope of this course.

  • See Edward Rubin’s excellent slides

  • And Matt Blackwells notes

  • Understanding the identifying assumptions of IV can help you critique a study (even if the you don’t fully understand the math)

Summary

What you need to know

  • Causal inference in observational and experimental studies is about counterfactual comparisons
  • In observational studies, to make causal claims we generally make some assumption of conditional independence:

Yi(1),Yi(0),⊥Di|Xi

  • The credibility of this assumption depends less on the data, and more on how the data were generated.
  • Selection on Observables is rarely a credible assumption
  • Observational designs that produce credible causal inference, leverage aspects of the world that create natural experiments
  • You should be able to describe the logic and assumptions of common designs in social science
    • Difference-in-Differences: Parallel Trends
    • Regression Discontiniuity: Continuity at the cutoff
    • Instrumental Variables: Instruments need to be Relevant and Exogenous

POLS 1600

1
POLS 1600 Statistical Inference and Course Review Updated Apr 22, 2025 WebR Status 🟡 Loading...

  1. Slides

  2. Tools

  3. Close
  • POLS 1600
  • Overview
  • Class Plan
  • Annoucements
  • Setup: Packages for today
  • Review
  • Three Modes of Inference
  • Descriptive Inference
  • Data Wrangling
  • Data Visualization
  • Causal Inference
  • Prediction with Linear Models
  • Quantifying Uncertainty
  • Probability
  • Sampling Distributions and Standard Errors
  • Confidence Intervals
  • Hypothesis Testing
  • Relationship between...
  • Four Possible Outcomes of a hypothesis Test
  • Type 1 and 2 Errors
  • Statistical Power
  • Final Projects
  • Strucutre of Final Paper and Drafts
  • For Thursday
  • Motivating Questions
  • Tasks:
  • New packages
  • Packages for today
  • Data
  • Finding variables: Outcomes
  • Finding variables: Predictors
  • Examine Distributions: Vaccine Beliefs
  • Recoding outcome variables
  • Recoding Predictors
  • Progress Report
  • Descriptive statistics (2016)
  • Progress Report
  • Specificying Expecations
  • Specificying Expecations
  • Specificying Expecations
  • Specificying Expecations
  • Motivating your expectations
  • Model Specification
  • Model Specification
  • Model Specification
  • Translating Theoretical...
  • Translating Theoretical...
  • Translating Theoretical...
  • Testing differences over time
  • Progress Report
  • Estimating Empirical Models
  • Estimating Empirical Models
  • Estimating Empirical Models
  • Progress Report
  • Presenting and Interpreting Your Results
  • Regression Tables
  • Telling a Story with Regression
  • Example
  • Story: Testing for Partisan Differences
  • Testing for Partisan Differences: Model 2
  • Interpreting Model 2
  • Interpreting Model 3
  • tab_fetch Partisanship...
  • Testing for Differences Over Time
  • Regression Discontinuity Design
  • Motivating Example
  • Logic of the Regression Discontinuity Design (RDD)
  • Eggers and Hainmueller (2009)
  • RDD Notation
  • Causal Identification with an RDD
  • Continuity Assumption
  • Causal Identification with an RDD
  • Instrumental Variables
  • Instrumental Variables
  • IV Assumption: Randomization
  • IV Assumption: Excludability
  • IV Assumption: First Stage
  • IV Assumption: Monotonicity
  • Compliance
  • Estimating the Local Average Treatment Effect
  • Estimating the Local Average Treatment Effect
  • Example: Earnings and Military Service
  • Introductory example
  • Introductory example
  • Instruments
  • Instruments
  • Instruments: Relevance
  • Instruments: Exogeneity
  • Venn diagram explanation
  • Relevant and Exogenous
  • Relevant, Not Exogenous
  • Not Relevant and Not Exogenous
  • Relevant, Not Exogenous
  • Take-aways
  • IV Applications
  • IV Summary
  • Summary
  • What you need to know
  • f Fullscreen
  • s Speaker View
  • o Slide Overview
  • e PDF Export Mode
  • r Scroll View Mode
  • b Toggle Chalkboard
  • c Toggle Notes Canvas
  • d Download Drawings
  • ? Keyboard Help