Learn R Programming

eiwild (version 0.6.7)

runMBayes: Metropolis Algorithm for ecological Inference

Description

This function is a wrapper function which calls the appropriate Metropolis algorithm depending on the hyperpriori which is chosen.

Usage

runMBayes(convList, 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

convList
output of convertEiData-function.
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 $\beta$-values
alphaVars
matrix of dimensions (rows, columns) giving variance of proposal density for $\alpha$-values.
retBeta
logical TRUE if estimated $\beta$-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

Value

list-Object with elements:
  • alphaDraws mcmc-object
  • cellCounts mcmc-object
  • betaDraws mcmc-object
  • betaAcc "numeric" with Acceptance ratios
  • alphaAcc "numeric" with Acceptance ratios
  • alphaVars matrix with variances for proposal density
  • betaVars array with variances for proposal density

Details

The whichPriori-parameter has the options "gamma" or "expo" and corresponding prioriPars-parameters in a "list":
  • "expo" and numeric list-element called "lam" corresponding to: $\alpha_{rc} \sim Exp(\lambda)$
  • "expo" and matrix list-element called "lam" corresponding to: $\alpha_{rc} \sim Exp(\lambda_{rc})$
  • "gamma" and two numeric list-element called "shape" and "rate" corresponding to: $\alpha_{rc} \sim Gamma(\lambda_1, \lambda_2)$
  • "gamma" and two matrix list-element called "shape" and "rate" corresponding to: $\alpha_{rc} \sim Gamma(\lambda_1^{rc}, \lambda_2^{rc})$

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

See Also

convertEiData, runMBayes, mcmc tuneVars, indAggEi

Examples

Run this code
## 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)
# conv <- convertEiData(form=form, aggr=aggr, indi=indi, IDCols=c("ID","ID"))
# set.seed(1234)
# res <- runMBayes(conv, sample=1000, thinning=2, burnin=100,verbose=100)
# 
# ## !!! not an eiwild object !!!
# class(res)
# 
# # better to use indAggEi
# set.seed(12345)
# res2 <- indAggEi(form=form, aggr=aggr, indi=indi, IDCols=c("ID","ID"),
#                  sample=1000, thinning=2, burnin=100,verbose=100)
# class(res2)
# summary(res2)
# 
# # 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)

Run the code above in your browser using DataLab