Skip to contents

Importance weights w_i = exp(log p - log g) (max-shifted), then m resampled draws with replacement, P(i) proportional to w_i, via one uniform per draw and inverse-CDF on the unnormalized cumulative weights (bit-identical to the Python arm).

Usage

Bayisr(samples, log_target, log_proposal, m, seed = 0L)

Arguments

samples

Draws from the proposal (vector or list of vectors).

log_target, log_proposal

Log densities up to constants.

m

Resample size.

seed

SplitMix64 seed.

Value

List with resample, indices (0-based, matching the Python arm), weights, ess, n, m, seed, method.

References

Rubin, D. B. (1988), in Bayesian Statistics 3, Oxford UP, 395-402; Smith, A. F. M. and Gelfand, A. E. (1992), The American Statistician 46(2), 84-88.

Examples

set.seed(1)
xs <- rnorm(500, 0, 2)
r <- Bayisr(xs, log_target = function(x) -0.5 * x^2,
            log_proposal = function(x) -0.5 * (x / 2)^2 - log(2),
            m = 100)
str(r, max.level = 1)
#> List of 8
#>  $ resample:List of 100
#>  $ indices : int [1:100] 208 12 480 46 150 78 375 115 472 187 ...
#>  $ weights : num [1:500] 2.19e-03 3.75e-03 1.38e-03 8.68e-05 3.35e-03 ...
#>  $ ess     : num 334
#>  $ n       : int 500
#>  $ m       : int 100
#>  $ seed    : int 0
#>  $ method  : chr "SIR weighted bootstrap (Rubin 1988; Smith-Gelfand 1992)"