indAggEi (Individual and Aggregate Ecological
Inference) Calculating ecological Inference including
Individual data using the two functions
convertEiData and
runMBayesindAggEi(form, aggr, indi = NULL, IDCols = c("ID"), whichPriori = "gamma",
prioriPars = list(shape = 4, rate = 2), startValsAlpha = NULL,
startValsBeta = NULL, betaVars = NULL, alphaVars = NULL, sample,
burnin = 0, thinning = 1, verbose = 1, retBeta = FALSE, seed = NULL)formula in this format
cbind(column_1,column_2,
...,column_c)~cbind(row_1,row_2,...,row_r))data.frame with aggregate data. One
district per line and one column giving one ID per
district. (see Details)data.frame with individual data. One
district per line and one column giving one ID per
district. (see Details) If no individual data are present
it defaults to NULL"gamma" or "expo"
(see Details)c(rows,columns) giving the starting values for
alpha. If NULL random numbers of rdirichlet with
chosen hyperpriori will be chosen.c(rows,columns,districts) giving the starting
values of beta If NULL random multinomial numbers
will be chosen.+
sample * thinningdefault=0default=1(rows,
columns-1, districts) giving variance of proposal
density for $\beta$-values(rows,
columns) giving variance of proposal density for
$\alpha$-values.TRUE if estimated
$\beta$-parameters should be returned. With large
number of precincts there can be problems with memoryNULL. Can be given the
"seed"-attribute of an eiwild-object to
reproduce an eiwild-object"eiwild" which is a nested
list with elements: drawsrowdforiginal aggregate datacoldforiginal
aggregate data"seed" is also
saved to reproduce the eiwild-objectindi is a districts x [(r*c)+1]
data.frame containing one district per line. One
column gives the ID of the districts which will be
connection to the ID column in the aggr-data.frame.
For example a 2x3 ecological Inference problem with
formula cbind(col1,col2,col3) ~
cbind(row1,row2) will have the row format : [ID,
row1.col1, row1.col2, row1.col3, row2.col1, row2.col2,
row2.col3]
It is important that the formula names correspond to
the exact column number in the indi-data.frame.
The aggr data.frame can have more columns than the
names given in formula as long as the colnames exist
The whichPriori-parameter has the options
"gamma" or "expo" and corresponding
prioriPars-parameters in a "list": "expo"andnumericlist-element called"lam"corresponding to:$\alpha_{rc} \sim
Exp(\lambda)$"expo"andmatrixlist-element called"lam"corresponding to:$\alpha_{rc} \sim Exp(\lambda_{rc})$"gamma"and twonumericlist-element called"shape"and"rate"corresponding to:$\alpha_{rc} \sim Gamma(\lambda_1, \lambda_2)$"gamma"and twomatrixlist-element called"shape"and"rate"corresponding to:$\alpha_{rc} \sim Gamma(\lambda_1^{rc},
\lambda_2^{rc})$"seed" attribute is generated by the
.Random.seed-function.convertEiData,
runMBayes, mcmc
tuneVars# loading some fake election data
data(topleveldat)
form <- cbind(CSU_2, SPD_2, LINK_2, GRUN_2) ~ cbind(CSU_1, SPD_1, Link_1)
set.seed(1234)
res <- indAggEi(form=form, aggr=aggr, indi=indi, IDCols=c("ID","ID"),
sample=1000, thinning=2, burnin=100,verbose=100)
res
summary(res)Run the code above in your browser using DataLab