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 in-sample
predictions as well as out-of-sample predictions for population
inference. The model and algorithm are described in Imai and Lu
(2004).ecoNP(formula, data = parent.frame(), N = NULL, supplement = NULL,
mu0 = c(0,0), tau0 = 2, nu0 = 4, S0 = diag(10,2), alpha = NULL,
a0 = 1, b0 = 0.1, parameter = FALSE, grid = FALSE,
n.draws = 5000, burnin = 0, thin = 0, verbose = FALSE)Y ~ X specifies Y as the
column margin and X as the row margin. Details and specifformula. The default is the environment in which
ecoNP is called.NULL, no additional individual-level data are included c(0,0).2.4.diag(10,2).NULL,
$\alpha$ will be updated at each Gibbs draw, and its prior
parameters a0 and b0 need to be sp1.0.1.TRUE, the Gibbs draws of the population
parameters, $\mu$ and $\Sigma$, are returned in addition to
the in-sample predictions of the missing internal cells,
$W$. The default is FALSE. This needs to be set TRUE, the grid method is used to sample
$W$ in the Gibbs sampler. If FALSE, the Metropolis
algorithm is used where candidate draws are sampled from the uniform
distribution on the tomography line for each 5000.0.0.TRUE, the progress of the gibbs
sampler is printed to the screen. The default is FALSE.ecoNP containing the following elements:parameter = TRUE.eco, predict.eco, summary.ecoNP## load the registration data
data(reg)
## NOTE: convergence has not been properly assessed for the following
## example. See Imai and Lu (2004) for more complete examples.
## fit the nonparametric model to give in-sample predictions
## store the parameters to make population inference later
res <- ecoNP(Y ~ X, data = reg, n.draws = 500, param = TRUE, verbose = TRUE)
##summarize the results
summary(res)
## obtain out-of-sample prediction
out <- predict(res, verbose=TRUE)
## summarize the results
summary(out)
## density plots of the out-of-sample predictions
par(mfrow=c(2,1))
plot(density(out[,1]), main="W1")
plot(density(out[,2]), main="W2")Run the code above in your browser using DataLab