Type: | Package |
Title: | Truncated Harmonic Mean Estimator of the Marginal Likelihood |
Version: | 0.1.2 |
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, Latouche, & Raftery (2024). Bayesian Analysis. <doi:10.1214/24-BA1422>. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Imports: | stats |
Suggests: | knitr, markdown, rmarkdown, mvtnorm |
VignetteBuilder: | knitr, rmarkdown |
NeedsCompilation: | no |
Packaged: | 2025-07-14 14:21:32 UTC; njirons |
Author: | Nicholas J. Irons |
Maintainer: | Nicholas J. Irons <nicholasjonirons@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-14 19:10:02 UTC |
Dirichlet parameter bound function
Description
Function calculating membership of a point in the interior of the simplex.
Usage
bound_dirichlet(theta)
Arguments
theta |
point to check |
Value
Boolean specifying whether theta lies in the interior of the simplex.
Examples
theta_ext <- runif(100)
theta_ins <- runif(100) / 100
bound_dirichlet(theta_ext)
bound_dirichlet(theta_ins)
Bounded parameter correction
Description
Computes Monte Carlo estimate of the bounded parameter correction to THAMES
Usage
bound_par_cor(theta_hat, sigma_svd, bound, radius, n_simuls = 1e+05)
Arguments
theta_hat |
center of the ellipsoid A. |
sigma_svd |
Singular value decomposition (SVD) of the posterior covariance matrix used to define A. |
bound |
Function calculating membership of a point in the posterior support. |
radius |
positive number, radius determining the ellipsoid A |
n_simuls |
Integer, number of Monte Carlo simulations to use in the calculation. |
Value
A number in [0,1] estimating of the proportion of the volume of A contained in the posterior support.
Examples
theta_ext <- runif(100)
theta_ins <- runif(100) / 100
Uniform sampling on/in ellipsoid
Description
Uniform sampling on an ellipsoid or in an ellipsoid. The sampling in an ellipsoid is available in arbitrary dimension. The sampling on an ellipsoid is available only in dimension 2 or 3. This code is borrowed directly from the uniformly package (https://CRAN.R-project.org/package=uniformly)
Usage
runif_on_ellipse(n, A, r)
runif_on_ellipsoid(n, A, r)
runif_in_ellipsoid(n, A, r)
Arguments
n |
number of simulations |
A |
symmetric positive-definite matrix defining the ellipsoid (see
Details), of size 2 for |
r |
"radius" (see Details) |
Details
The ellipsoid is the set of vectors x
satisfying
t(x) %*% A %*% x == r^2
. For example, for an axis-aligned
ellipse with horizontal radius a
and vertical radius b
, take
A=1/diag(c(a^2,b^2))
and r=1
.
Value
The simulations in a matrix with n
rows.
Uniform sampling on/in sphere
Description
Uniform sampling on a sphere or in a sphere, in arbitrary dimension. This code is borrowed directly from the uniformly package (https://CRAN.R-project.org/package=uniformly)
Usage
runif_on_sphere(n, d, r = 1)
runif_in_sphere(n, d, r = 1)
Arguments
n |
number of simulations |
d |
dimension of the space |
r |
radius of the sphere |
Value
The simulations in a n
times d
matrix.
THAMES estimator of the (reciprocal) log marginal likelihood
Description
This function computes the THAMES estimate of the reciprocal log marginal likelihood using posterior samples and unnormalized log posterior values.
Usage
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
)
Arguments
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. |
Value
Returns a named list with the following elements:
References
Metodiev M, Perrot-Dockès M, Ouadah S, Irons N. J., Latouche P., Raftery A. E. (2024) Easily Computed Marginal Likelihoods from Posterior Simulation Using the THAMES Estimator. Bayesian Analysis.
Examples
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)
Truncated normal quantiles
Description
This function computes quantiles of the truncated normal distribution for calculating THAMES confidence intervals.
Usage
trunc_quantile(p, ratio)
Arguments
p |
Percentile |
ratio |
Ratio of standard error to point estimate (midpoint of confidence interval) |
Value
Truncated normal quantile