get.mig.parameter.traces {bayesMig}R Documentation

Accessing MCMC Parameter Traces

Description

Functions for accessing traces of the MCMC parameters, either country-independent or country-specific.

Usage

get.mig.parameter.traces(
  mcmc.list,
  par.names = NULL,
  burnin = 0,
  thinning.index = NULL,
  thin = NULL
)

get.mig.parameter.traces.cs(
  mcmc.list,
  country.obj,
  par.names = NULL,
  burnin = 0,
  thinning.index = NULL,
  thin = NULL
)

Arguments

mcmc.list

List of bayesMig.mcmc objects.

par.names

Names of country-independent parameters (in case of get.mig.parameter.traces) or country-specific parameters (in case of get.mig.parameter.traces.cs) to be included. By default all parameters are included, given either by mig.parameter.names() (for global parameters) or mig.parameter.names.cs() (for location-specific parameters).

burnin

Burn-in indicating how many iterations should be removed from the beginning of each chain.

thinning.index

Index of the traces for thinning. If it is NULL, thin is used. thinning.index does not include burnin and should be flattened over all chains. For example, if there are two MCMC chains of length 1000, burnin=200 and we want an equidistantly spaced sample of length 400, then the value should be
thinning.index = seq(1, 1600, length = 400).

thin

An integer value for thinning. It is an alternative to thinning.index. The above example is equivalent to thin=4.

country.obj

Country object (see get.country.object).

Value

Both functions return a matrix with columns being the parameters and rows being the MCMC values, attached to one another in case of multiple chains. get.mig.parameter.traces returns country-independent parameters, get.mig.parameter.traces.cs returns country-specific parameters.

See Also

mig.coda.list.mcmc for another way of retrieving parameter traces; mig.parameter.names and mig.parameter.names.cs for parameter names.

Examples

# Toy simulation for US states
us.mig.file <- file.path(find.package("bayesMig"), "extdata", "USmigrates.txt")
sim.dir <- tempfile()
m <- run.mig.mcmc(nr.chains = 2, iter = 30, thin = 1, my.mig.file = us.mig.file, 
        output.dir = sim.dir, present.year = 2017, annual = TRUE)
# obtain traces of hierarchical parameters     
par.values <- get.mig.parameter.traces(m$mcmc.list, burnin = 5)
dim(par.values) # matrix 50 x 4
hist(par.values[, "mu_global"], main = "mu")

# obtain traces of location-specific traces for California
mig.parameter.names.cs() # allowed parameter names 
par.values.cs <- get.mig.parameter.traces.cs(m$mcmc.list, 
        country.obj = get.country.object("California", meta = m$meta),
        burnin = 5, par.names = "phi_c")
dim(par.values.cs) # matrix 50 x 1
hist(par.values.cs, main = colnames(par.values.cs))
unlink(sim.dir, recursive = TRUE)
    

[Package bayesMig version 0.4-6 Index]