relative_eff {loo}R Documentation

Convenience function for computing relative efficiencies

Description

relative_eff computes the the MCMC effective sample size divided by the total sample size.

Usage

relative_eff(x, ...)

## Default S3 method:
relative_eff(x, chain_id, ...)

## S3 method for class 'matrix'
relative_eff(x, chain_id, ...,
  cores = getOption("mc.cores", 1))

## S3 method for class 'array'
relative_eff(x, ..., cores = getOption("mc.cores", 1))

## S3 method for class 'function'
relative_eff(x, chain_id, ...,
  cores = getOption("mc.cores", 1), data = NULL, draws = NULL)

Arguments

x

A vector, matrix, 3-D array, or function. See the Methods (by class) section below for details on the shape of x. For use with the loo function, the values in x (or generated by x if x is a function) should be likelihood values (i.e., exp(log_lik), not on the log scale). For generic use with psis, the values in x should be the reciprocal of the importance ratios (i.e., exp(-log_ratios)).

chain_id

A vector of length NROW(x) containing MCMC chain indexes for each each row of x (if a matrix) or each value in x (if a vector). No chain_id is needed if x is a 3-D array. If there are C chains then valid chain indexes are values in 1:C.

cores

The number of cores to use for parallelization.

data, draws, ...

Same as for the loo function method.

Value

A vector of relative effective sample sizes.

Methods (by class)

Examples

LLarr <- example_loglik_array()
LLmat <- example_loglik_matrix()
dim(LLarr)
dim(LLmat)

rel_n_eff_1 <- relative_eff(exp(LLarr))
rel_n_eff_2 <- relative_eff(exp(LLmat), chain_id = rep(1:2, each = 500))
all.equal(rel_n_eff_1, rel_n_eff_2)


[Package loo version 2.1.0 Index]