Title: | Truncated Harmonic Mean Estimator of the Marginal Likelihood |
---|---|
Description: | Implements the truncated harmonic mean estimator (THAMES) of the reciprocal marginal likelihood using posterior samples and unnormalized log posterior values via reciprocal importance sampling. Metodiev, Perrot-Dockès, Ouadah, Irons, & Raftery (2023) <arXiv:2305.08952>. |
Authors: | Nicholas J. Irons [aut, cre]
|
Maintainer: | Nicholas J. Irons <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1 |
Built: | 2025-02-19 03:28:06 UTC |
Source: | https://github.com/cran/thames |
This function computes the THAMES estimate of the reciprocal log marginal likelihood using posterior samples and unnormalized log posterior values.
thames( lps = NULL, params, n_samples = NULL, d = NULL, radius = NULL, p = 0.025, q = 1 - p, lp_func = NULL, bound = NULL, n_simuls = 1e+05 )
thames( lps = NULL, params, n_samples = NULL, d = NULL, radius = NULL, p = 0.025, q = 1 - p, lp_func = NULL, bound = NULL, n_simuls = 1e+05 )
lps |
vector of unnormalized log posterior values of length n_samples (sum of the log prior and the log likelihood) |
params |
matrix of parameter posterior samples of dimension n_samples * d |
n_samples |
integer, number of posterior samples |
d |
integer, dimension of parameter space |
radius |
positive number, radius to use for defining the ellipsoid A |
p |
percentile, used for lower bound of confidence interval |
q |
percentile, used for upper bound of confidence interval |
lp_func |
function to compute unnormalized log posterior values |
bound |
function calculating membership of a point in the posterior support |
n_simuls |
integer, number of Monte Carlo simulations to use in the bounded parameter correction calculation. |
Returns a named list with the following elements:
Metodiev M, Perrot-Dockès M, Ouadah S, Irons N. J., Raftery A. E. (2023) Easily Computed Marginal Likelihoods from Posterior Simulation Using the THAMES Estimator. arXiv preprint.
mu_star = 1 n <- 50 Y = rnorm(n, mu_star, 1) sig2 <- 1 sig2_n <- 1/(n+1/sig2) mn <- sum(Y)/(n + 1/sig2) params <- rnorm(20, mean=mn, (sig2_n)) lps <- sapply(params, function(i){ sum(dnorm(Y,i,1,log = TRUE)) + dnorm(i,0,sig2, log = TRUE)}) thames(lps, params)
mu_star = 1 n <- 50 Y = rnorm(n, mu_star, 1) sig2 <- 1 sig2_n <- 1/(n+1/sig2) mn <- sum(Y)/(n + 1/sig2) params <- rnorm(20, mean=mn, (sig2_n)) lps <- sapply(params, function(i){ sum(dnorm(Y,i,1,log = TRUE)) + dnorm(i,0,sig2, log = TRUE)}) thames(lps, params)