Computes importance weights \(w_i = p(x_i)/g(x_i)\) for draws
from a proposal and resamples m of them with probability
proportional to the weights (Rubin 1988; Smith and Gelfand 1992).
The reported effective sample size
\(1/\sum \bar w_i^2\) is the usual diagnostic: it falls towards 1
when a single draw dominates, which is the signal that the
proposal is too far from the target for the resample to be usable.
References
Smith, A. F. M. and Gelfand, A. E. (1992). Bayesian statistics without tears. The American Statistician, 46(2), 84-88.
Examples
set.seed(1)
morie_bayisr(samples = as.list(rnorm(100)), log_target = function(x) -0.5 * x^2,
log_proposal = function(x) -0.5 * x^2, m = 20)
#> $resample
#> $resample[[1]]
#> [1] 0.5566632
#>
#> $resample[[2]]
#> [1] -0.8356286
#>
#> $resample[[3]]
#> [1] -0.5732654
#>
#> $resample[[4]]
#> [1] 1.511781
#>
#> $resample[[5]]
#> [1] 0.3876716
#>
#> $resample[[6]]
#> [1] 0.9438362
#>
#> $resample[[7]]
#> [1] 0.001105352
#>
#> $resample[[8]]
#> [1] 0.6198257
#>
#> $resample[[9]]
#> [1] 0.5584864
#>
#> $resample[[10]]
#> [1] 0.7631757
#>
#> $resample[[11]]
#> [1] -0.4432919
#>
#> $resample[[12]]
#> [1] 0.3411197
#>
#> $resample[[13]]
#> [1] 1.9804
#>
#> $resample[[14]]
#> [1] 0.4755095
#>
#> $resample[[15]]
#> [1] -0.6120264
#>
#> $resample[[16]]
#> [1] -0.1123462
#>
#> $resample[[17]]
#> [1] -0.4432919
#>
#> $resample[[18]]
#> [1] 0.9189774
#>
#> $resample[[19]]
#> [1] 0.5939462
#>
#> $resample[[20]]
#> [1] 0.3329504
#>
#>
#> $indices
#> [1] 43 2 97 10 32 17 77 24 95 39 76 52 55 70 51 48 76 20 84 85
#>
#> $weights
#> [1] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#> [16] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#> [31] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#> [46] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#> [61] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#> [76] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#> [91] 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01
#>
#> $ess
#> [1] 100
#>
#> $n
#> [1] 100
#>
#> $m
#> [1] 20
#>
#> $seed
#> [1] 0
#>
#> $method
#> [1] "SIR weighted bootstrap (Rubin 1988; Smith-Gelfand 1992)"
#>
