| Title: | 'Moreau-Yosida' Importance Sampling for Statistical Inference |
|---|---|
| Description: | Implements 'Moreau-Yosida' Markov chain Monte Carlo ('MCMC') importance sampling for parameter estimation and Bayesian inference under smooth, non-differentiable, or light-tailed target posterior distributions and arbitrary probability models with complete or censored data. Users supply user-defined probability density functions, optional distribution functions, parameter ranges, and observations subject to complete, right, left, interval, Type-I, Type-II, progressive Type-II, first-failure, or truncation schemes. Constructs 'Moreau-Yosida' envelopes, gradient-based proposals ('MALA', 'HMC', or 'RWM'), self-normalized importance weights, batch-means asymptotic variance estimates, and Bayesian marginal quantiles. Methodologies are based on 'Shukla', 'Vats', and 'Chi' (2025) <doi:10.48550/arXiv.2501.02228>, 'Pereyra' (2016) <doi:10.1111/sjos.12208>, 'Durmus' and others (2022) <doi:10.1214/22-EJS2027>, 'Chen' and 'Shao' (1999) <doi:10.1214/ss/1009211804>, 'Roberts' and 'Rosenthal' (1998) <doi:10.1214/aoap/1028903378>, 'Geweke' (1989) <doi:10.2307/2290062>, 'Hesterberg' (1995) <doi:10.1080/00031305.1995.10476138>, and 'Balakrishnan' and 'Aggarwala' (2000, ISBN:978-0-8176-4001-9). |
| Authors: | Shikhar Tyagi [aut, cre] (ORCID: <https://orcid.org/0000-0003-1606-0844>), Arvind Pandey [aut], Bhupendra Singh [aut], Vrijesh Tripathi [aut] |
| Maintainer: | Shikhar Tyagi <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-10-05 10:56:09 UTC |
| Source: | https://github.com/cran/MYIS |
Estimates the asymptotic covariance matrix of a Markov chain output using consistent batch-means methodology (Vats et al., 2019).
batch_means_cov(S_matrix, batch_size = NULL)batch_means_cov(S_matrix, batch_size = NULL)
S_matrix |
Numeric matrix of size |
batch_size |
Integer batch size. If |
A p x p numeric matrix representing the batch-means estimated asymptotic covariance.
set.seed(123) data_mat <- matrix(rnorm(1000), ncol = 2) cov_bm <- batch_means_cov(data_mat)set.seed(123) data_mat <- matrix(rnorm(1000), ncol = 2) cov_bm <- batch_means_cov(data_mat)
Constructs the negative log-posterior potential function
for a user-supplied PDF (and optional CDF / Survival function), data, censoring scheme, and prior.
build_negative_log_posterior( pdf, cdf = NULL, surv = NULL, data, censoring = "complete", censoring_params = list(), par_lower = -Inf, par_upper = Inf, log_prior = NULL )build_negative_log_posterior( pdf, cdf = NULL, surv = NULL, data, censoring = "complete", censoring_params = list(), par_lower = -Inf, par_upper = Inf, log_prior = NULL )
pdf |
Function taking variable |
cdf |
Optional function taking variable |
surv |
Optional function taking variable |
data |
Numeric vector, matrix, or list containing the observed dataset. |
censoring |
Character string specifying the censoring scheme. Options include:
|
censoring_params |
Named list of additional parameters for censoring schemes (e.g. |
par_lower |
Numeric vector of lower parameter bounds. |
par_upper |
Numeric vector of upper parameter bounds. |
log_prior |
Optional function taking parameter vector |
A function of theta returning scalar negative log-posterior .
my_pdf <- function(x, th) dexp(x, rate = th) psi_fn <- build_negative_log_posterior(my_pdf, data = c(0.5, 1.2, 2.1), par_lower = 0.001) psi_fn(1.0)my_pdf <- function(x, th) dexp(x, rate = th) psi_fn <- build_negative_log_posterior(my_pdf, data = c(0.5, 1.2, 2.1), par_lower = 0.001) psi_fn(1.0)
Calculates the effective sample size (ne) for importance sampling based on Kong (1992).
effective_sample_size_is(weights)effective_sample_size_is(weights)
weights |
Numeric vector of non-negative importance weights. |
A named list containing ne (effective sample size) and ratio (ne/n).
set.seed(123) w <- runif(100) ess_info <- effective_sample_size_is(w)set.seed(123) w <- runif(100) ess_info <- effective_sample_size_is(w)
Computes the Moreau-Yosida envelope value, proximal mapping point, gradient,
and unnormalized importance weights for a given convex or log-concave function
following Shukla, Vats, and Chi (2025).
my_envelope( psi_fn, theta, lambda, par_lower = -Inf, par_upper = Inf, method = NULL )my_envelope( psi_fn, theta, lambda, par_lower = -Inf, par_upper = Inf, method = NULL )
psi_fn |
Function taking a numeric parameter vector |
theta |
Numeric vector of parameter values at which to evaluate the envelope. |
lambda |
Positive numeric smoothing parameter |
par_lower |
Numeric vector of lower bounds for parameters. Defaults to |
par_upper |
Numeric vector of upper bounds for parameters. Defaults to |
method |
Character string specifying the optimization algorithm for |
A list with the following components:
prox |
Numeric vector containing the proximal mapping point |
psi_lambda |
Scalar numeric value of the Moreau-Yosida envelope |
psi_orig |
Scalar numeric value of the original function |
grad_psi_lambda |
Numeric vector representing the gradient of the envelope |
grad_log_pi_lambda |
Numeric vector representing |
weight |
Scalar numeric value of the unnormalized importance weight |
Shukla, A., Vats, D., & Chi, E. C. (2025). MCMC Importance Sampling via Moreau-Yosida Envelopes. arXiv:2501.02228v2.
psi <- function(th) sum(abs(th)) # Laplace potential res <- my_envelope(psi, theta = c(1.5, -0.8), lambda = 0.5) res$prox res$weightpsi <- function(th) sum(abs(th)) # Laplace potential res <- my_envelope(psi, theta = c(1.5, -0.8), lambda = 0.5) res$prox res$weight
Computes Moreau-Yosida MCMC Importance Sampling (MY-IS) estimates, standard errors, asymptotic covariance, Bayesian marginal quantiles, and effective sample size for user-defined probability density functions under complete or censored observations (Shukla, Vats, and Chi, 2025).
my_is_estimate( pdf, cdf = NULL, surv = NULL, data, initial_theta, censoring = "complete", censoring_params = list(), par_lower = -Inf, par_upper = Inf, log_prior = NULL, sampler = c("mala", "hmc", "rwm"), n_samples = 3000, burnin = 500, lambda = NULL, tune_lambda = TRUE, target_ne_ratio = 0.6, conf_level = 0.95 )my_is_estimate( pdf, cdf = NULL, surv = NULL, data, initial_theta, censoring = "complete", censoring_params = list(), par_lower = -Inf, par_upper = Inf, log_prior = NULL, sampler = c("mala", "hmc", "rwm"), n_samples = 3000, burnin = 500, lambda = NULL, tune_lambda = TRUE, target_ne_ratio = 0.6, conf_level = 0.95 )
pdf |
User-defined function taking variable |
cdf |
Optional function taking variable |
surv |
Optional function taking variable |
data |
Numeric vector, matrix, or data frame of observations. |
initial_theta |
Numeric vector of initial parameter values. |
censoring |
Character string specifying censoring scheme. Supported schemes:
|
censoring_params |
Named list of scheme options (e.g. |
par_lower |
Numeric vector of lower parameter bounds. Defaults to |
par_upper |
Numeric vector of upper parameter bounds. Defaults to |
log_prior |
Optional function taking parameter vector |
sampler |
Character string specifying MCMC algorithm for |
n_samples |
Integer number of retained MCMC samples. Defaults to |
burnin |
Integer number of burn-in samples. Defaults to |
lambda |
Optional positive numeric smoothing parameter |
tune_lambda |
Logical flag indicating whether to perform automatic |
target_ne_ratio |
Numeric target ratio for importance sampling effective sample size |
conf_level |
Numeric confidence level for Bayesian credible intervals in |
An S3 object of class "myis" containing:
estimates |
Named vector of MY-IS parameter point estimates |
se |
Named vector of batch-means standard errors. |
cov_mat |
Asymptotic covariance matrix estimate |
cred_intervals |
Matrix containing lower and upper bounds of Bayesian credible intervals. |
quantiles |
Matrix of weighted quantiles calculated via Chen & Shao (1999). |
ne_info |
List containing effective sample size |
accept_rate |
Numeric MCMC acceptance rate. |
lambda |
Smoothing parameter |
samples |
Numeric matrix of generated MCMC states. |
weights |
Numeric vector of unnormalized importance weights. |
sampler |
Character string of sampler used. |
censoring |
Character string of censoring scheme used. |
call |
Matched function call. |
Shukla, A., Vats, D., & Chi, E. C. (2025). MCMC Importance Sampling via Moreau-Yosida Envelopes. arXiv:2501.02228v2. Chen, M. H., & Shao, Q. M. (1999). Monte Carlo estimation of Bayesian credible quantities. Journal of Computational and Graphical Statistics, 8(1), 69-92.
set.seed(42) sample_data <- rexp(30, rate = 1.5) my_pdf <- function(x, th) dexp(x, rate = th[1]) fit <- my_is_estimate( pdf = my_pdf, data = sample_data, initial_theta = 1.0, par_lower = 0.001, n_samples = 100, burnin = 20 ) print(fit)set.seed(42) sample_data <- rexp(30, rate = 1.5) my_pdf <- function(x, th) dexp(x, rate = th[1]) fit <- my_is_estimate( pdf = my_pdf, data = sample_data, initial_theta = 1.0, par_lower = 0.001, n_samples = 100, burnin = 20 ) print(fit)
Generates trace plots, autocorrelation functions (ACF), posterior density/histograms, and weight distribution plots for MCMC importance sampling outputs.
## S3 method for class 'myis' plot( x, type = c("all", "trace", "acf", "density", "weights"), par_idx = 1, ... )## S3 method for class 'myis' plot( x, type = c("all", "trace", "acf", "density", "weights"), par_idx = 1, ... )
x |
An S3 object of class |
type |
Character string specifying plot type: |
par_idx |
Integer parameter index to plot. Defaults to 1. |
... |
Additional graphical parameters. |
No return value, called for side effects.
set.seed(123) dat <- rexp(20, rate = 2) fit <- my_is_estimate( dexp, data = dat, initial_theta = 1, n_samples = 100, burnin = 20 ) plot(fit, type = "all")set.seed(123) dat <- rexp(20, rate = 2) fit <- my_is_estimate( dexp, data = dat, initial_theta = 1, n_samples = 100, burnin = 20 ) plot(fit, type = "all")
Print method for S3 objects of class "myis".
## S3 method for class 'myis' print(x, ...)## S3 method for class 'myis' print(x, ...)
x |
An S3 object of class |
... |
Additional arguments passed to print. |
Returns x invisibly.
set.seed(123) dat <- rexp(20, rate = 2) fit <- my_is_estimate( dexp, data = dat, initial_theta = 1, n_samples = 100, burnin = 20 ) print(fit)set.seed(123) dat <- rexp(20, rate = 2) fit <- my_is_estimate( dexp, data = dat, initial_theta = 1, n_samples = 100, burnin = 20 ) print(fit)
Print method for summary objects of class "summary.myis".
## S3 method for class 'summary.myis' print(x, ...)## S3 method for class 'summary.myis' print(x, ...)
x |
An S3 object of class |
... |
Additional arguments. |
Returns x invisibly.
Computes exponential with an upper cap to prevent numerical overflow to Inf.
safe_exp(x, max_val = 700)safe_exp(x, max_val = 700)
x |
Numeric scalar, vector, or matrix. |
max_val |
Numeric maximum allowed exponent. Defaults to |
Numeric output after applying safe exponential.
safe_exp(c(-5, 10, 1000))safe_exp(c(-5, 10, 1000))
Computes the logarithm with a lower bound threshold to avoid -Inf or NaN errors.
safe_log(x, min_val = 1e-300)safe_log(x, min_val = 1e-300)
x |
Numeric scalar, vector, or matrix. |
min_val |
Numeric threshold value. Defaults to |
Numeric output after applying safe logarithm.
safe_log(c(0, 0.5, 2))safe_log(c(0, 0.5, 2))
Simulates a Markov chain targeting the Moreau-Yosida importance density
using Hamiltonian Monte Carlo (Livingstone et al., 2019; Chaari et al., 2016).
sample_pi_lambda_hmc( psi_fn, initial_theta, lambda, n_samples = 2000, burnin = 500, step_size = NULL, n_leapfrog = 10, par_lower = -Inf, par_upper = Inf )sample_pi_lambda_hmc( psi_fn, initial_theta, lambda, n_samples = 2000, burnin = 500, step_size = NULL, n_leapfrog = 10, par_lower = -Inf, par_upper = Inf )
psi_fn |
Function taking parameter vector |
initial_theta |
Numeric vector of initial parameter values. |
lambda |
Positive numeric smoothing parameter |
n_samples |
Integer number of MCMC samples to retain. |
burnin |
Integer number of initial burn-in iterations. |
step_size |
Optional positive leapfrog step size |
n_leapfrog |
Integer number of leapfrog steps |
par_lower |
Numeric vector of lower parameter bounds. |
par_upper |
Numeric vector of upper parameter bounds. |
A list containing samples, weights, accept_rate, and step_size.
psi <- function(th) sum(th^2) res <- sample_pi_lambda_hmc( psi, initial_theta = c(1, 1), lambda = 0.1, n_samples = 100, burnin = 20 )psi <- function(th) sum(th^2) res <- sample_pi_lambda_hmc( psi, initial_theta = c(1, 1), lambda = 0.1, n_samples = 100, burnin = 20 )
Simulates a Markov chain targeting the Moreau-Yosida importance density
using the MALA proposal (Shukla, Vats, and Chi, 2025; Pereyra, 2016).
sample_pi_lambda_mala( psi_fn, initial_theta, lambda, n_samples = 2000, burnin = 500, step_size = NULL, par_lower = -Inf, par_upper = Inf )sample_pi_lambda_mala( psi_fn, initial_theta, lambda, n_samples = 2000, burnin = 500, step_size = NULL, par_lower = -Inf, par_upper = Inf )
psi_fn |
Function taking parameter vector |
initial_theta |
Numeric vector of initial parameter values. |
lambda |
Positive numeric smoothing parameter |
n_samples |
Integer number of MCMC samples to retain. |
burnin |
Integer number of initial burn-in iterations. |
step_size |
Optional positive step size |
par_lower |
Numeric vector of lower parameter bounds. |
par_upper |
Numeric vector of upper parameter bounds. |
A list containing samples (matrix of MCMC states), weights (vector of importance weights),
accept_rate (acceptance rate), and step_size (used step size).
psi <- function(th) sum(th^2) res <- sample_pi_lambda_mala( psi, initial_theta = c(1, 1), lambda = 0.1, n_samples = 100, burnin = 20 )psi <- function(th) sum(th^2) res <- sample_pi_lambda_mala( psi, initial_theta = c(1, 1), lambda = 0.1, n_samples = 100, burnin = 20 )
Simulates a Markov chain targeting the Moreau-Yosida importance density
using Random Walk Metropolis proposal.
sample_pi_lambda_rwm( psi_fn, initial_theta, lambda, n_samples = 2000, burnin = 500, proposal_sd = NULL, par_lower = -Inf, par_upper = Inf )sample_pi_lambda_rwm( psi_fn, initial_theta, lambda, n_samples = 2000, burnin = 500, proposal_sd = NULL, par_lower = -Inf, par_upper = Inf )
psi_fn |
Function taking parameter vector |
initial_theta |
Numeric vector of initial parameter values. |
lambda |
Positive numeric smoothing parameter |
n_samples |
Integer number of MCMC samples to retain. |
burnin |
Integer number of initial burn-in iterations. |
proposal_sd |
Optional positive proposal standard deviation. If |
par_lower |
Numeric vector of lower parameter bounds. |
par_upper |
Numeric vector of upper parameter bounds. |
A list containing samples, weights, accept_rate, and proposal_sd.
psi <- function(th) sum(th^2) res <- sample_pi_lambda_rwm( psi, initial_theta = c(1, 1), lambda = 0.1, n_samples = 100, burnin = 20 )psi <- function(th) sum(th^2) res <- sample_pi_lambda_rwm( psi, initial_theta = c(1, 1), lambda = 0.1, n_samples = 100, burnin = 20 )
Summary method for S3 objects of class "myis".
## S3 method for class 'myis' summary(object, ...)## S3 method for class 'myis' summary(object, ...)
object |
An S3 object of class |
... |
Additional arguments. |
An S3 object of class "summary.myis".
set.seed(123) dat <- rexp(20, rate = 2) fit <- my_is_estimate( dexp, data = dat, initial_theta = 1, n_samples = 100, burnin = 20 ) summary(fit)set.seed(123) dat <- rexp(20, rate = 2) fit <- my_is_estimate( dexp, data = dat, initial_theta = 1, n_samples = 100, burnin = 20 ) summary(fit)
Calculates weighted marginal quantiles from MCMC importance sampling outputs following the estimator proposed by Chen and Shao (1999).
weighted_quantiles(samples, weights, probs = c(0.025, 0.5, 0.975))weighted_quantiles(samples, weights, probs = c(0.025, 0.5, 0.975))
samples |
Numeric matrix of samples (iterations x components) or numeric vector. |
weights |
Numeric vector of non-negative importance weights corresponding to each row. |
probs |
Numeric vector of desired quantile probabilities in |
A matrix or vector of estimated weighted quantiles.
set.seed(123) x <- rnorm(100) w <- exp(-0.1 * x^2) q <- weighted_quantiles(x, w, probs = c(0.025, 0.5, 0.975))set.seed(123) x <- rnorm(100) w <- exp(-0.1 * x^2) q <- weighted_quantiles(x, w, probs = c(0.025, 0.5, 0.975))