Built using Zelig version 5.1.0.90000


Ecological Inference Model by Maximum Likelihood with eiml in ZeligEI.

Syntax

The EI models accept several different formula syntaxes. If \(C1\) and \(C2\) are the column totals, and \(R1\) and \(R2\) are the row totals, and \(N=R1_i + R2_i = C1_i + C2_i\) is the total in unit \(i\), then the formula can be expressed with just one row and one column, with the totals provided separately as:

z.out <- zelig(C1 ~ R1, N = N, data = data)

The argument N can be either a numeric vector of the total in each i-th unit, or the character name of a variable in the dataset that contains these values.

Or with both rows and columns coupled together, and omitting the totals:

z.out <- zelig(cbind(C1,C2) ~ cbind(R1,R2), data = data)

Additionally, if C1, C2, R1, R2 are percentages rather than counts, then either formula method above is acceptable, however, N must always be provided.

First load packages:

library(zeligverse)

Here is an example of all the syntax for the analysis using the first syntax method, and the direct use of the reference classes:

z5 <- zeiml$new()
z5$zelig(C1 ~ R1, N = myN, weights = w, data = myData)
z5$setx()
z5$sim()

With the Zelig 4 compatibility wrappers this looks like:

z.out <- zelig(C1 ~ R1, N=N, model = "eiml", weights = w, data = myData)
x.out <- setx(z.out)
s.out <- sim(z.out, x = x.out)

Examples

We’ll use a dataset from the ei package, of black and non-black turnout in 141 precincts.

library("ei", quietly=TRUE)
data(sample)

Here is the model estimated in Zelig.

z.out <- zeiml$new()
z.out$zelig(t ~ x, N = "n", data = sample)
## [1] "Running 2x2 ei"
## Maximizing likelihood
## Importance Sampling..
summary(z.out)
## Model: 
## $Erho
## [1] 0.5
## 
## $Esigma
## [1] 0.5
## 
## $Ebeta
## [1] 0.5
## 
## $N
## [1] 75
## 
## $Resamp
## [1] 21
## 
## $`Maximum likelihood results in scale of estimation (and se's)`
##         Bb0       Bw0       sigB       sigW       rho Zb Zw
##  -1.1533874 0.8214529 -2.2860101 -1.8816375 0.4128279  0  0
##   0.1018115 0.1017286  0.2494434  0.1572393 0.3651596  0  0
## 
## $`Untruncated psi's`
##         BB        BW        SB        SW       RHO
##  0.1955265 0.7227119 0.1069191 0.1531497 0.3520577
## 
## $`Truncated psi's (ultimate scale)`
##         BB        BW         SB        SW       RHO
##  0.2031422 0.7139941 0.09837747 0.1418888 0.2960979
## 
## $`Aggregate Bounds`
##            betab     betaw
## lower 0.09549504 0.3979843
## upper 0.60893461 0.8031228
## 
## $`Estimates of Aggregate Quantities of Interest`
##         mean          sd
## Bb 0.2028756 0.012304964
## Bw 0.7183923 0.009709447
## 
## $precision
## [1] 4
## 
## attr(,"class")
## [1] "summary"
## Next step: Use 'setx' method

See also

This model is part of the ei package by Gary King and Molly Roberts. Advanced users may wish to refer to help(ei) in the ei package.

King G (1997). A Solution to the Ecological Inference Problem: Reconstructing Individual Behavior from Aggregate Data. Princeton University Press, Princeton.

King G and Roberts M (2016). ei: Ecological Inference. R package version 1.3-3, <URL: https://CRAN.R-project.org/package=ei>.