adMCMC: Estimate a continuous posterior distribution via adaptive...

Description Usage Arguments Value Examples

Description

The function is intended to be used with computationally expensive likelihoods, and little attention has been giving to speed up the adaptive MCMC algorithm itself. The underlying algorithm is an adaptive MCMC sampler with adaptive global scaling and using the empirical covariance matrix to generate proposals.

Usage

1
2
adMCMC(inits, logLik, logPrior, nIter, nThin, logScaleMCMC = TRUE,
  blocks = NULL, ...)

Arguments

inits

Vector of initial parameter values. The log likelihood function and prior need to have finite values for these parameters.

logLik

A function giving the log likelihood value for the model. The function should take parameter values to be estimated via an argument called pars.

logPrior

A function giving the log prior density for the parameters. The function should take a single argument named pars. For parameter values that are out of range the function should return -Inf.

nIter

The size of the MCMC sample.

nThin

The number of thining iterations in between each saved sample.

logScaleMCMC

If true, the MCMC is run on the log scale of all parameters. Requires that all parameters are positive.

blocks

May be used for blocking MCMC updates. In this case a vector of integers of the same length as inits where each unique integer represents a block. If NULL, no blocking is applied.

...

Further arguments passed to logLik.

Value

An mcmc object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Simulate a cohort with four stages, sampled at 15 occasions with 30 initial individuals in
## each sample.

cdata = simMNCohort(seq(1,50, length.out=15), N0 = 30, rGammaSD,
                    mu = c(5, 15, 8), cv = c(.5,.5,.5), mortRate = c(0.01, 0.01,0.01,0.01),
                    Narg = "N")

## Define a likelihood function using the function mnLogLik and rGammaSD.
## Note that it must have the argument named 'pars'.

exLogLik = function(pars, data, nSim) {
  mnLogLik(data, rStageDur = rGammaSD, mu = pars[1:3], cv = rep(pars[4], 3),
        mortRate = rep(pars[5], 4),  N = nSim)
}

## Define the log-prior function using bounded uniform priors.

exLogPrior = function(pars) {
 mu = pars[1:3]
 cv = pars[4]
 mr = pars[5]
 sum(log(all(c(cv < 2,mu < 30,mr < 1,cv > 0,mu > 0,mr > 0))))
}

## Not run: 
## Fit model
inits = c(10,10,10,1,.001)
names(inits) = c(paste0("mu", 1:3), "cv", "mr")
mcmc = adMCMC(inits, exLogLik, exLogPrior, nIter = 1000, nThin = 10,
                    data = cdata, nSim = 1000)
plot(mcmc)

## End(Not run)

jknape/stageFreq documentation built on May 19, 2019, 11:42 a.m.