eco
is used to fit the parametric Bayesian model
(based on a Normal/InverseWishart prior) for ecological inference
in 2 \times 2 tables via Markov chain Monte Carlo. It gives
the insample predictions as well as the estimates of the model
parameters. The model and algorithm are described in Imai, Lu and
Strauss (2008, 2011).
1 2 3 4 5 
formula 
A symbolic description of the model to be fit,
specifying the column and row margins of 2 \times
2 ecological tables. 
data 
An optional data frame in which to interpret the variables
in 
N 
An optional variable representing the size of the unit; e.g.,
the total number of voters. 
supplement 
An optional matrix of supplemental data. The matrix
has two columns, which contain additional individuallevel data such
as survey data for W_1 and W_2, respectively. If

context 
Logical. If 
mu0 
A scalar or a numeric vector that specifies the prior mean
for the mean parameter μ for (W_1,W_2) (or for
(W_1, W_2, X) if 
tau0 
A positive integer representing the scale parameter of the
NormalInverse Wishart prior for the mean and variance parameter
(μ, Σ). The default is 
nu0 
A positive integer representing the prior degrees of
freedom of the NormalInverse Wishart prior for the mean and
variance parameter (μ, Σ). The default is 
S0 
A positive scalar or a positive definite matrix that specifies
the prior scale matrix of the NormalInverse Wishart prior for the
mean and variance parameter (μ, Σ) . If it is
a scalar, then the prior scale matrix will be a diagonal matrix with
the same dimensions as Σ and the diagonal elements all take
value of 
mu.start 
A scalar or a numeric vector that specifies the
starting values of the mean parameter μ.
If it is a scalar, then its value will be repeated to
yield a vector of the length of μ, otherwise,
it needs to be a vector of same length as μ.
When 
Sigma.start 
A scalar or a positive definite matrix
that specified the starting value of the variance matrix
Σ. If it is a scalar, then the prior scale
matrix will be a diagonal matrix with the same dimensions
as Σ and the diagonal elements all take value
of 
parameter 
Logical. If 
grid 
Logical. If 
n.draws 
A positive integer. The number of MCMC draws.
The default is 
burnin 
A positive integer. The burnin interval for the Markov
chain; i.e. the number of initial draws that should not be stored. The
default is 
thin 
A positive integer. The thinning interval for the
Markov chain; i.e. the number of Gibbs draws between the recorded
values that are skipped. The default is 
verbose 
Logical. If 
An example of 2 \times 2 ecological table for racial voting is given below:
black voters  white voters  
vote  W_{1i}  W_{2i}  Y_i  
not vote  1W_{1i}  1W_{2i}  1Y_i  
X_i  1X_i 
where Y_i and X_i represent the observed margins, and W_1 and W_2 are unknown variables. In this exmaple, Y_i is the turnout rate in the ith precint, X_i is the proproption of African American in the ith precinct. The unknowns W_{1i} an dW_{2i} are the black and white turnout, respectively. All variables are proportions and hence bounded between 0 and 1. For each i, the following deterministic relationship holds, Y_i=X_i W_{1i}+(1X_i)W_{2i}.
An object of class eco
containing the following elements:
call 
The matched call. 
X 
The row margin, X. 
Y 
The column margin, Y. 
N 
The size of each table, N. 
burnin 
The number of initial burnin draws. 
thin 
The thinning interval. 
nu0 
The prior degrees of freedom. 
tau0 
The prior scale parameter. 
mu0 
The prior mean. 
S0 
The prior scale matrix. 
W 
A three dimensional array storing the posterior insample predictions of W. The first dimension indexes the Monte Carlo draws, the second dimension indexes the columns of the table, and the third dimension represents the observations. 
Wmin 
A numeric matrix storing the lower bounds of W. 
Wmax 
A numeric matrix storing the upper bounds of W. 
The following additional elements are included in the output when
parameter = TRUE
.
mu 
The posterior draws of the population mean parameter, μ. 
Sigma 
The posterior draws of the population variance matrix, Σ. 
Kosuke Imai, Department of Politics, Princeton University, kimai@Princeton.Edu, http://imai.princeton.edu; Ying Lu,Center for Promoting Research Involving Innovative Statistical Methodology (PRIISM), New York University, ying.lu@nyu.Edu
Imai, Kosuke, Ying Lu and Aaron Strauss. (2011). “eco: R Package for Ecological Inference in 2x2 Tables” Journal of Statistical Software, Vol. 42, No. 5, pp. 123. available at http://imai.princeton.edu/software/eco.html
Imai, Kosuke, Ying Lu and Aaron Strauss. (2008). “Bayesian and Likelihood Inference for 2 x 2 Ecological Tables: An Incomplete Data Approach” Political Analysis, Vol. 16, No. 1 (Winter), pp. 4169. available at http://imai.princeton.edu/research/eiall.html
ecoML
, ecoNP
, predict.eco
, summary.eco
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  ## load the registration data
## Not run: data(reg)
## NOTE: convergence has not been properly assessed for the following
## examples. See Imai, Lu and Strauss (2008, 2011) for more
## complete analyses.
## fit the parametric model with the default prior specification
res < eco(Y ~ X, data = reg, verbose = TRUE)
## summarize the results
summary(res)
## obtain outofsample prediction
out < predict(res, verbose = TRUE)
## summarize the results
summary(out)
## load the Robinson's census data
data(census)
## fit the parametric model with contextual effects and N
## using the default prior specification
res1 < eco(Y ~ X, N = N, context = TRUE, data = census, verbose = TRUE)
## summarize the results
summary(res1)
## obtain outofsample prediction
out1 < predict(res1, verbose = TRUE)
## summarize the results
summary(out1)
## End(Not run)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.