A parent class for different importance sampling methods.
Source:R/importance_sampling.R
importance_sampling.RdA parent class for different importance sampling methods.
Usage
importance_sampling(log_ratios, method, ...)
# S3 method for class 'array'
importance_sampling(
log_ratios,
method,
...,
r_eff = 1,
cores = getOption("mc.cores", 1)
)
# S3 method for class 'matrix'
importance_sampling(
log_ratios,
method,
...,
r_eff = 1,
cores = getOption("mc.cores", 1)
)
# Default S3 method
importance_sampling(log_ratios, method, ..., r_eff = 1)Arguments
- log_ratios
An array, matrix, or vector of importance ratios on the log scale (for PSIS-LOO these are negative log-likelihood values). See the Methods (by class) section below for a detailed description of how to specify the inputs for each method.
- method
The importance sampling method to use. The following methods are implemented:
- ...
Arguments passed on to the various methods.
- r_eff
Vector of relative effective sample size estimates containing one element per observation. The values provided should be the relative effective sample sizes of
1/exp(log_ratios)(i.e.,1/ratios). This is related to the relative efficiency of estimating the normalizing term in self-normalizing importance sampling. Ifr_effis not provided then the reported PSIS effective sample sizes and Monte Carlo error estimates can be over-optimistic. If the posterior draws are (near) independent thenr_eff=1can be used.r_effhas to be a scalar (same value is used for all observations) or a vector with length equal to the number of observations. The default value is 1. See therelative_eff()helper function for computingr_eff.- cores
The number of cores to use for parallelization. This defaults to the option
mc.coreswhich can be set for an entire R session byoptions(mc.cores = NUMBER). The old optionloo.coresis now deprecated but will be given precedence overmc.coresuntilloo.coresis removed in a future release. As of version 2.0.0 the default is now 1 core ifmc.coresis not set, but we recommend using as many (or close to as many) cores as possible.Note for Windows 10 users: it is strongly recommended to avoid using the
.Rprofilefile to setmc.cores(using thecoresargument or settingmc.coresinteractively or in a script is fine).