MCMC.add.samples: Add samples to an existing chain.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/Adaptive_MCMC.R

Description

Add samples to an existing chain produced by MCMC or MCMC.parallel.

Usage

1
MCMC.add.samples(MCMC.object, n.update, ...)

Arguments

MCMC.object

a list produced by MCMC or MCMC.parallel with option list = TRUE.

n.update

number of additional samples.

...

further arguments passed to p.

Details

Only objects generated with the option list = TRUE can be updated.

A list of chains produced by MCMC.parallel can be updated. However, the calculations are not performed in parallel (i.e. only a single CPU is used).

Value

A updated version of MCMC.object.

Author(s)

Andreas Scheidegger, andreas.scheidegger@eawag.ch or scheidegger.a@gmail.com

See Also

MCMC, MCMC.parallel

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## ----------------------
## Banana shaped distribution

## log-pdf to sample from
p.log <- function(x) {
  B <- 0.03                              # controls 'bananacity'
  -x[1]^2/200 - 1/2*(x[2]+B*x[1]^2-100*B)^2
}


## ----------------------
## generate 200  samples

samp <- MCMC(p.log, n=200, init=c(0, 1), scale=c(1, 0.1),
               adapt=TRUE, acc.rate=0.234, list=TRUE)


## ----------------------
## add 200 to the existing chain
samp <- MCMC.add.samples(samp, n.update=200)

str(samp)

Example output

Loading required package: parallel
Loading required package: coda
Loading required package: Matrix
  generate 200 samples 
  generate 200 samples 
List of 7
 $ samples            : num [1:400, 1:2] 0 0.859 -1.963 -2.241 -2.776 ...
 $ log.p              : num [1:400] -2 -2.76 -2.42 -2.6 -2.06 ...
 $ cov.jump           : num [1:2, 1:2] 84.73 -3.18 -3.18 8.45
 $ n.sample           : num 400
 $ acceptance.rate    : num 0.319
 $ adaption           : logi TRUE
 $ sampling.parameters:List of 3
  ..$ sample.density:function (x)  
  ..$ acc.rate      : num 0.234
  ..$ gamma         : num 0.5

adaptMCMC documentation built on March 29, 2021, 9:11 a.m.