Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 054
Research workflow/4 steps

Ecological inference (ei)

01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 4 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 4
01
Data prep

Load ei and prepare the 2x2 margins

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Load the package and the matproii data, then specify the formula relating the row margin x to the column margin t.

Formula
T_i = \beta_i^b X_i + \beta_i^w (1 - X_i)
Reads fromNot specified Feeds into#2
Key code
# Install:  install.packages("ei")
library(ei)
data(matproii)
form <- t ~ x

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.

Questions to explore
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

Aggregate unit-level data: for each district, two observed margins (e.g. fraction black and turnout) and the population size.

Show data format & exampleHide example
precinct x_black t_turnout n
1 0.20 0.55 800
2 0.65 0.48 1200
3 0.10 0.61 950
4 0.40 0.52 700
03
Read the evidence

Results & interpretation

1 figure Workflow discussion 0
01FigureAggregate group-specific rates with their logical bounds and 95% intervals.

Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.

The estimate

T_i=\beta_i^{b}\,X_i+\beta_i^{w}\,(1-X_i),\qquad 0\le\beta_i^{b},\beta_i^{w}\le 1

Context & interpretation

⚠️ Unofficial community showcase of ei (docs). Not affiliated with the authors — all credit to Gary King & coauthors; this summarizes public documentation.

What it does: The ei package implements Gary King's solution to the ecological inference problem—estimating unobserved individual-level relationships (e.g. how subgroups voted) using only aggregate data such as precinct or district marginals. How it works: For 2x2 tables it combines the deterministic accounting identity (which bounds each unit's unknowns given its margins) with a statistical model: a truncated bivariate normal distribution over the unit-level parameters, estimated by maximum likelihood and simulation. This yields district-level and aggregate point estimates with uncertainty, while respecting the logical bounds each precinct imposes. Assumptions: The model's distributional form (truncated bivariate normal), no spatial autocorrelation beyond what's modeled, and absence of certain aggregation bias; diagnostics and extended models address some violations. Output: estimated internal cell quantities (e.g. fraction of each group voting), with bounds and credible intervals, at both unit and aggregate levels.

What you get — Estimated internal cell quantities (e.g. group-specific turnout) with bounds, at unit and aggregate levels.

Example output

Maximum likelihood results in scale of estimation (and se's)
           [,1]   [,2]
Zb        0.314  0.184
Zw        0.733  0.114

Aggregate Bounds
         betab betaw
lower    0.025 0.601
upper    0.444 0.762

Estimates of Aggregate Quantities of Interest
        mean     sd
Bb     0.612  0.028
Bw     0.358  0.014

Links: package · paper

Peer notes

Discuss the workflow (0)

  • No comments yet — start the conversation.
IN THE MARGINS

Peer discussion