Description Usage Arguments Value Author(s) References See Also Examples
ecoNP
is used to fit the nonparametric Bayesian model (based on a
Dirichlet process prior) for ecological inference in 2 \times 2 tables
via Markov chain Monte Carlo. It gives the insample predictions as well as
outofsample predictions for population inference. The models and
algorithms are described in Imai, Lu and Strauss (2008, 2011).
1 2 3 4 
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 μ of the base prior distribution G_0 (see
Imai, Lu and Strauss (2008, 2011) for detailed descriptions of Dirichlete
prior and the normal base prior distribution) . 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

tau0 
A positive integer representing the scale parameter of the
NormalInverse Wishart prior for the mean and variance parameter
(μ_i, Σ_i) of each observation. The default is 
nu0 
A positive integer representing the prior degrees of freedom of
the variance matrix Σ_i. the default is 
S0 
A positive scalar or a positive definite matrix that specifies the
prior scale matrix for the variance matrix Σ_i. If it is a
scalar, then the prior scale matrix will be a diagonal matrix with the same
dimensions as Σ_i and the diagonal elements all take value of

alpha 
A positive scalar representing a userspecified fixed value of
the concentration parameter, α. If 
a0 
A positive integer representing the value of shape parameter of
the gamma prior distribution for α. The default is 
b0 
A positive integer representing the value of the scale parameter
of the gamma prior distribution for α. The default is 
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 object of class ecoNP
containing the following elements:
call 
The matched call. 
X 
The row margin, X. 
Y 
The column margin, Y. 
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. 
a0 
The prior shape parameter. 
b0 
The prior scale parameter. 
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 
A three dimensional array storing the posterior draws of the population mean parameter, μ. The first dimension indexes the Monte Carlo draws, the second dimension indexes the columns of the table, and the third dimension represents the observations. 
Sigma 
A three dimensional array storing the posterior draws of the population variance matrix, Σ. The first dimension indexes the Monte Carlo draws, the second dimension indexes the parameters, and the third dimension represents the observations. 
alpha 
The posterior draws of α. 
nstar 
The number of clusters at each Gibbs draw. 
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
eco
, ecoML
, predict.eco
, summary.ecoNP
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 33 34 35 36 37 38 39 40 41 42  ## load the registration data
data(reg)
## NOTE: We set the number of MCMC draws to be a very small number in
## the following examples; i.e., convergence has not been properly
## assessed. See Imai, Lu and Strauss (2006) for more complete examples.
## fit the nonparametric model to give insample predictions
## store the parameters to make population inference later
## Not run: res < ecoNP(Y ~ X, data = reg, n.draws = 50, param = TRUE, verbose = TRUE)
##summarize the results
summary(res)
## obtain outofsample prediction
out < predict(res, verbose = TRUE)
## summarize the results
summary(out)
## density plots of the outofsample predictions
par(mfrow=c(2,1))
plot(density(out[,1]), main = "W1")
plot(density(out[,2]), main = "W2")
## load the Robinson's census data
data(census)
## fit the parametric model with contextual effects and N
## using the default prior specification
res1 < ecoNP(Y ~ X, N = N, context = TRUE, param = TRUE, data = census,
n.draws = 25, verbose = TRUE)
## summarize the results
summary(res1)
## outof sample prediction
pres1 < predict(res1)
summary(pres1)
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.