indAggEi: Ecological Inference including Individual Data

Description Usage Arguments Details Value See Also Examples

Description

indAggEi (Individual and Aggregate Ecological Inference) Calculating ecological Inference including Individual data using the two functions convertEiData and runMBayes

Usage

1
2
3
4
indAggEi(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)

Arguments

form

formula in this format cbind(column_1,column_2, ...,column_c)~cbind(row_1,row_2,...,row_r))

aggr

data.frame with aggregate data. One district per line and one column giving one ID per district. (see Details)

indi

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

IDCols

vector of length 2 giving the column-names or numbers of ID column

whichPriori

character string specifying the chosen hyperpriori. Options are "gamma" or "expo" (see Details)

prioriPars

vector or matrix of parameters for the specified hyperpriori in whichPriori

startValsAlpha

matrix with dimension c(rows,columns) giving the starting values for alpha. If NULL random numbers of rdirichlet with chosen hyperpriori will be chosen.

startValsBeta

array with dimension c(rows,columns,districts) giving the starting values of beta If NULL random multinomial numbers will be chosen.

sample

the sample size to be saved in output. Total length of chain will be burnin + sample * thinning

burnin

number of draws to be cut away from the beginning of the Markov-Chain. default=0

thinning

number specifying the thinning interval. default=1

verbose

an integer specifying whether the progress of the sampler is printed to the screen (defaults to 0). If verbose is greater than 0, the iteration number is printed to the screen every verboseth iteration

betaVars

array-object with dimensions (rows, columns-1, districts) giving variance of proposal density for β-values

alphaVars

matrix of dimensions (rows, columns) giving variance of proposal density for α-values.

retBeta

logical TRUE if estimated β-parameters should be returned. With large number of precincts there can be problems with memory

seed

Default is NULL. Can be given the "seed"-attribute of an eiwild-object to reproduce an eiwild-object

Details

indi 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":

The "seed" attribute is generated by the .Random.seed-function.

Value

object of class "eiwild" which is a nested list with elements:

An Attribute called "seed" is also saved to reproduce the eiwild-object

See Also

convertEiData, runMBayes, mcmc tuneVars

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
# 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)

# with individual alpha-hyperpriori-parameters
hypMat <- list(shape = matrix(c(30,4,4,4,
                                4,30,4,4,
                                4,4,30,4), nrow=3, ncol=4, byrow=TRUE),
               rate = matrix(c(1,2,2,2,
                               2,1,2,2,
                               2,2,1,2), nrow=3, ncol=4, byrow=TRUE))
set.seed(12345)
res2 <- indAggEi(form=form, aggr=aggr, indi=indi, IDCols=c("ID","ID"),
                 sample=1000, thinning=2, burnin=100, verbose=100,
                 prioriPars=hypMat, whichPriori="gamma")

## End(Not run)

eiwild documentation built on May 2, 2019, 6:43 a.m.

Related to indAggEi in eiwild...