| tis {loo} | R Documentation |
Truncated importance sampling (TIS)
Description
Implementation of truncated (self-normalized) importance sampling (TIS), truncated at S^(1/2) as recommended by Ionides (2008).
Usage
tis(log_ratios, ...)
## S3 method for class 'array'
tis(log_ratios, ..., r_eff = 1, cores = getOption("mc.cores", 1))
## S3 method for class 'matrix'
tis(log_ratios, ..., r_eff = 1, cores = getOption("mc.cores", 1))
## Default S3 method:
tis(log_ratios, ..., r_eff = 1)
Arguments
log_ratios |
An array, matrix, or vector of importance ratios on the log scale (for Importance sampling 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. |
... |
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 |
cores |
The number of cores to use for parallelization. This defaults to
the option
|
Value
The tis() methods return an object of class "tis",
which is a named list with the following components:
log_weights-
Vector or matrix of smoothed (and truncated) but unnormalized log weights. To get normalized weights use the
weights()method provided for objects of classtis. diagnostics-
A named list containing one vector:
-
pareto_k: Not used intis, all set to 0. -
n_eff: Effective sample size estimates.
-
Objects of class "tis" also have the following attributes:
norm_const_log-
Vector of precomputed values of
colLogSumExps(log_weights)that are used internally by theweights()method to normalize the log weights. r_eff-
If specified, the user's
r_effargument. tail_len-
Not used for
tis. dims-
Integer vector of length 2 containing
S(posterior sample size) andN(number of observations). method-
Method used for importance sampling, here
tis.
Methods (by class)
-
tis(array): AnIbyCbyNarray, whereIis the number of MCMC iterations per chain,Cis the number of chains, andNis the number of data points. -
tis(matrix): AnSbyNmatrix, whereSis the size of the posterior sample (with all chains merged) andNis the number of data points. -
tis(default): A vector of lengthS(posterior sample size).
References
Ionides, Edward L. (2008). Truncated importance sampling. Journal of Computational and Graphical Statistics 17(2): 295–311.
See Also
-
psis()for approximate LOO-CV using PSIS. -
loo()for approximate LOO-CV. -
pareto-k-diagnostic for PSIS diagnostics.
Examples
log_ratios <- -1 * example_loglik_array()
r_eff <- relative_eff(exp(-log_ratios))
tis_result <- tis(log_ratios, r_eff = r_eff)
str(tis_result)
# extract smoothed weights
lw <- weights(tis_result) # default args are log=TRUE, normalize=TRUE
ulw <- weights(tis_result, normalize=FALSE) # unnormalized log-weights
w <- weights(tis_result, log=FALSE) # normalized weights (not log-weights)
uw <- weights(tis_result, log=FALSE, normalize = FALSE) # unnormalized weights