run_mcmc: Posterior sampling using differential evolution

Description Usage Arguments Examples

View source: R/sample_wrapper.R

Description

powder Runs power posterior sampling using differential evolution markov chain monte carlo

Usage

1
2
3
4
5
run_mcmc(model, pars = NULL, data, sampler = "de", num_samples = NULL,
  num_chains = NULL, migration_start = NULL, migration_end = NULL,
  migration_freq = NULL, randomize_phi = TRUE, update = 100,
  init_theta = NULL, init_phi = NULL, return_as_mcmc = TRUE,
  parallel_backend = "none", n_cores = NULL, benchmark = FALSE)

Arguments

model

A function. Defines a Bayesian model. See example below.

pars

A list. Specifies the names of parameters along with their initialization bounds and blocks. See example below.

data

A list. Specifies the data to be modeled. See example.

sampler

A character. Specifies the name of the sampler to be used. de is the only built-in sampler.

num_samples

A numeric. The total number of samples to collect.

num_chains

A numeric. The number of chains to run.

migration_freq

A numeric. Number of iterations to wait between each migration step. If NULL, migration is not done.

randomize_phi

A logical. Should the correlational structure between level-1 and level-2 parameters be ignored.

update

A numeric. Specifies the number of iterations before printing the current iteration number to the console.

init_theta

A list where each element contains a named vector of parameter initial start values for each subject.

init_phi

A named vector parameter initial start values

parallel_backend

A character vector either 'MPI', 'doParallel', or 'none' indicating backend for parallelization. Default is none.

n_cores

A numeric. Number of cores when parallel_backend is specified.

benchmark

A logical. Produces compute times benchmark purposes. Oftentimes, ignoring this correlation will lead to better sampling.

migration.start

A numeric. Iteration to start migrating. This should be after chains are burned in. If NULL, migration is not done.

migration.end

A numeric. Iteration to stop migrating. Migration should stop well before sampling is finished. If NULL, migration is not done.

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: 
library(derp)
#### Simulate data
data = list(response = rnorm(100,2,1))
#### Model parameters
pars = list(
'mu' =    list('init'=c(1,10)),
'sd' =    list('init'=c(.1,5))
)
#### Define model
model = function() {
    normal_lpdf(mu, 0, 3)
    gamma_lpdf(sd, 1, 1)
    normal_lpdf(response, mu, sd)
}
#### Run the sampler
samples = run_mcmc(model, pars, data,
                  migration_start = 500, migration_end = 700,
                  migration_freq = 10, num_samples=3000)
mcmc_snip = snip(samples,burnin=1000,thin=1)
summary(mcmc_snip)

## End(Not run)

jeff324/derp documentation built on Dec. 5, 2019, 11:46 p.m.