| Title: | Bayesian Sparse Polynomial Chaos Expansion |
|---|---|
| Description: | Implements Bayesian polynomial chaos expansion methods for surrogate modeling, uncertainty quantification, and sensitivity analysis. Includes sparse regression-based approaches and adaptive Bayesian models based on reversible-jump Markov chain Monte Carlo. Optional screening and basis-enrichment strategies are provided to improve scalability in moderate to high dimensions. |
| Authors: | Kellin Rumsey [aut, cre] (ORCID: <https://orcid.org/0000-0002-2989-965X>), J. Derek Tucker [ctb] (ORCID: <https://orcid.org/0000-0001-8844-2169>) |
| Maintainer: | Kellin Rumsey <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 2.1.1 |
| Built: | 2026-05-24 07:18:47 UTC |
| Source: | https://github.com/cran/khaos |
A wrapper for adaptive Bayesian polynomial chaos expansion models with different coefficient prior formulations.
adaptive_khaos( X, y, prior_type = "ridge", nmcmc = 10000, nburn = 9000, thin = 1, legacy = TRUE, verbose = TRUE, ... )adaptive_khaos( X, y, prior_type = "ridge", nmcmc = 10000, nburn = 9000, thin = 1, legacy = TRUE, verbose = TRUE, ... )
X |
A data frame or matrix of predictors scaled to lie between 0 and 1. |
y |
A numeric response vector of length |
prior_type |
Character string specifying the coefficient-prior formulation.
Currently one of |
nmcmc |
Number of MCMC iterations. |
nburn |
Number of initial MCMC iterations to discard. |
thin |
Keep every |
legacy |
Logical. If |
verbose |
Logical; if |
... |
Additional arguments passed to the prior-specific fitting routine. |
Depending on prior_type, this function calls either
adaptive_khaos_ridge() or adaptive_khaos_gprior().
This function dispatches to one of the prior-specific adaptive KHAOS fitting routines:
prior_type = "ridge"Calls adaptive_khaos_ridge.
prior_type = "gprior"Calls adaptive_khaos_gprior.
The wrapper exposes only the most commonly used arguments. Additional
prior-specific tuning parameters can be supplied through ...; see
adaptive_khaos_ridge and adaptive_khaos_gprior
for full documentation.
An object of class "adaptive_khaos" containing the fitted model.
The object is a list including sampled basis functions, coefficient samples,
variance parameters, and additional MCMC output. The specific structure depends
on the chosen prior_type.
Francom, Devin, and Bruno Sanso. "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94.LA-UR-20-23587 (2020).
Rumsey, K.N., Francom, D., Gibson, G., Tucker, J. D., and Huerta, G. (2026). Bayesian Adaptive Polynomial Chaos Expansions. Stat, 15(1), e70151.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391 * ((x[1] - 0.4) * (x[2] - 0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit1 <- adaptive_khaos(X, y) fit2 <- adaptive_khaos(X, y, prior_type = "gprior")X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391 * ((x[1] - 0.4) * (x[2] - 0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit1 <- adaptive_khaos(X, y) fit2 <- adaptive_khaos(X, y, prior_type = "gprior")
Adaptive Bayesian polynomial chaos expansion using a modified g-prior. This implementation corresponds to the adaptive Bayesian PCE methodology described in Rumsey et al. (2026)
adaptive_khaos_gprior( X, y, degree = 15, order = 5, nmcmc = 10000, nburn = 9000, thin = 1, max_basis = 1000, a_g = 0.001, b_g = 1000, zeta = 1, g2_sample = "mh", g2_init = NULL, s2_lower = 0, a_sigma = 0, b_sigma = 0, a_M = 4, b_M = 4/length(y), move_probs = rep(1/3, 3), coin_pars = list(function(j) 1/j, 1, 2, 3), degree_penalty = 0, legacy = TRUE, verbose = TRUE ) adaptive_khaos2(...)adaptive_khaos_gprior( X, y, degree = 15, order = 5, nmcmc = 10000, nburn = 9000, thin = 1, max_basis = 1000, a_g = 0.001, b_g = 1000, zeta = 1, g2_sample = "mh", g2_init = NULL, s2_lower = 0, a_sigma = 0, b_sigma = 0, a_M = 4, b_M = 4/length(y), move_probs = rep(1/3, 3), coin_pars = list(function(j) 1/j, 1, 2, 3), degree_penalty = 0, legacy = TRUE, verbose = TRUE ) adaptive_khaos2(...)
X |
A data frame or matrix of predictors scaled to be between 0 and 1 |
y |
a response vector |
degree |
Maximum polynomial degree for each basis function. |
order |
Maximum order of interaction for each basis function. |
nmcmc |
Number of MCMC iterations. |
nburn |
Number of initial MCMC iterations to discard. |
thin |
Keep every |
max_basis |
Maximum number of basis functions. |
a_g, b_g
|
Prior parameters for global g-prior term (on precision scale) |
zeta |
Hyperparameter for modified g-prior. Setting zeta = 0 reduces to the usual g-prior. |
g2_sample |
Character string specifying the method used to sample or update the prior scaling parameter |
g2_init |
Initial calue of g2 (global precision for g-prior). Becomes the only value when |
s2_lower |
Lower bound on process variance (numerically useful for deterministic functions). |
a_sigma, b_sigma
|
Shape/rate parameters for the IG prior on process variance (default is Jefffrey's prior) |
a_M, b_M
|
Shape/rate parameters for the Gamma prior on expected number of basis functions. |
move_probs |
A 3-vector with probabilities for (i) birth, (ii) death, and (iii) mutation. |
coin_pars |
A list of control parameters for coinflip proposal |
degree_penalty |
Increasing this value encourages lower order polynomial terms (0 is no penalization). |
legacy |
Logical. If TRUE, mimics original implementation behavior (from the emulator comparison paper), which may retain invalid basis function structures across iterations. Defaults to FALSE. |
verbose |
Logical. Should progress information be printed? |
... |
additional arguments passed to adaptive_khaos |
Implements the RJMCMC algorithm described by Francom & Sanso (2020) for BMARS, modifying it for polynomial chaos basis functions. As an alternative the NKD procedure of Nott et al. (2005), we use a coinflipping procedure to identify useful variables. See writeup (coming soon) for details. The coin_pars argument is an ordered list with elements:
a function giving proposal probability for q_0, the expected order of interaction,
epsilon, the base weight for each variable (epsilon=Inf corresponds to uniform sampling),
alpha, the exponent-learning rate,
num_passes a numerical parameter only.
Sampling method for g0^2 depends on g2_sample
"f"Fixed: Do not update g0^2; carry forward the previous value (g2[i] <- g2[i-1]).
"lf"Laplace-Full: Use a Laplace approximation to sample g0^2 under the full marginal likelihood (no orthogonality assumption).
"lo"Laplace-Orthogonal: Use a Laplace approximation to sample g0^2 assuming the orthogonality approximation applies.
"mh"Metropolis-Hastings with full Laplace approximation as proposal. Target is the full posterior density of g0^2.
"mho"Metropolis-Hastings with orthogonal Laplace approximation as proposal. Target is the full posterior density of g0^2. under the orthogonality assumption.
"mhoo"Metropolis-Hastings with orthogonal Laplace approximation as proposal. Target is the posterior density of g0^2 under the orthogonality assumption.
Other proposal notes:
Expected order q0 is chosen from 1:order with weights coin_pars[[1]](1:order)
Degree is chosen from q0:degree with weights (1:(degree-q0+1))^(-degree_penalty) and a random partition is created (see helper function).
Two types of change steps are possible (and equally likely)
A re-ordering of the degrees
A single variable is swapped out with another one (only used when ncol(X) > 3)
An object of class "adaptive_khaos".
The object is a list containing:
Matrix of basis functions evaluated at the training inputs.
Arrays encoding the variables and polynomial degrees for each basis function across MCMC iterations.
Interaction order and total degree for each basis function.
Number of basis functions per MCMC iteration.
Posterior samples of regression coefficients.
Posterior samples of the noise variance.
Posterior samples of the Poisson rate parameter controlling model size.
Posterior samples of the global g-prior scaling parameter.
Residual sum of squares at each iteration.
Variable inclusion counts used in the proposal distribution.
Acceptance and proposal counts for RJMCMC moves.
Character string indicating the g-prior formulation.
Training data.
Francom, Devin, and Bruno Sanso. "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94.LA-UR-20-23587 (2020).
Nott, David J., Anthony YC Kuk, and Hiep Duc. "Efficient sampling schemes for Bayesian MARS models with many predictors." Statistics and Computing 15 (2005): 93-101.
Rumsey, K.N., Francom, D., Gibson, G., Derek Tucker, J. and Huerta, G., 2026. Bayesian Adaptive Polynomial Chaos Expansions. Stat, 15(1), p.e70151.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y)
Adaptive Bayesian polynomial chaos expansion using a fixed Gaussian (ridge) prior on coefficients. This implementation corresponds to a simplified version of the adaptive Bayesian PCE methodology described in Rumsey et al. (2026)
adaptive_khaos_ridge( X, y, degree = 15, order = 5, nmcmc = 10000, nburn = 9000, thin = 1, max_basis = 1000, tau2 = 10^5, s2_lower = 0, g1 = 0, g2 = 0, h1 = 4, h2 = 40/length(y), move_probs = rep(1/3, 3), coin_pars = list(function(j) 1/j, 1, 2, 3), degree_penalty = 0, legacy = TRUE, verbose = TRUE )adaptive_khaos_ridge( X, y, degree = 15, order = 5, nmcmc = 10000, nburn = 9000, thin = 1, max_basis = 1000, tau2 = 10^5, s2_lower = 0, g1 = 0, g2 = 0, h1 = 4, h2 = 40/length(y), move_probs = rep(1/3, 3), coin_pars = list(function(j) 1/j, 1, 2, 3), degree_penalty = 0, legacy = TRUE, verbose = TRUE )
X |
A data frame or matrix of predictors scaled to be between 0 and 1 |
y |
a response vector |
degree |
Maximum polynomial degree for each basis function. |
order |
Maximum order of interaction for each basis function. |
nmcmc |
Number of MCMC iterations. |
nburn |
Number of initial MCMC iterations to discard. |
thin |
Keep every |
max_basis |
Maximum number of basis functions. |
tau2 |
Prior variance for coefficients |
s2_lower |
Lower bound on process variance (numerically useful for deterministic functions). |
g1, g2
|
Shape/rate parameters for the IG prior on process variance (default is Jefffrey's prior) |
h1, h2
|
Shape/rate parameters for the Gamma prior on expected number of basis functions. |
move_probs |
A 3-vector with probabilities for (i) birth, (ii) death, and (iii) mutation. |
coin_pars |
A list of control parameters for coinflip proposal |
degree_penalty |
Increasing this value encourages lower order polynomial terms (0 is no penalization). |
legacy |
Logical. If TRUE, mimics original implementation behavior (from the emulator comparison paper), which may retain invalid basis function structures across iterations. Defaults to FALSE. |
verbose |
Logical. Should progress information be printed? |
Implements the RJMCMC algorithm described by Francom & Sanso (2020) for BMARS, modifying it for polynomial chaos basis functions. As an alternative the NKD procedure of Nott et al. (2005), we use a coinflipping procedure to identify useful variables. See writeup (coming soon) for details. The coin_pars argument is an ordered list with elements:
a function giving proposal probability for q_0, the expected order of interaction,
epsilon, the base weight for each variable (epsilon=Inf corresponds to uniform sampling),
alpha, the exponent-learning rate,
num_passes a numerical parameter only.
Other proposal notes:
Expected order q0 is chosen from 1:order with weights coin_pars[[1]](1:order)
Degree is chosen from q0:degree with weights (1:(degree-q0+1))^(-degree_penalty) and a random partition is created (see helper function).
Two types of change steps are possible (and equally likely) A re-ordering of the degrees A single variable is swapped out with another one
An object of class "adaptive_khaos".
The object is a list containing:
Matrix of basis functions evaluated at the training inputs.
Arrays encoding the variables and polynomial degrees for each basis function across MCMC iterations.
Interaction order and total degree for each basis function.
Number of basis functions per MCMC iteration.
Posterior samples of regression coefficients.
Posterior samples of the noise variance.
Posterior samples of the Poisson rate parameter controlling model size.
Residual sum of squares at each iteration.
Variable inclusion counts used in the proposal distribution.
Acceptance and proposal counts for RJMCMC moves.
Character string indicating the ridge prior.
Training data.
Francom, Devin, and Bruno Sanso. "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94.LA-UR-20-23587 (2020).
Nott, David J., Anthony YC Kuk, and Hiep Duc. "Efficient sampling schemes for Bayesian MARS models with many predictors." Statistics and Computing 15 (2005): 93-101.
Rumsey, K.N., Francom, D., Gibson, G., Derek Tucker, J. and Huerta, G., 2026. Bayesian Adaptive Polynomial Chaos Expansions. Stat, 15(1), p.e70151.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y)
The emulation approach of Francom et al. (2020) for BMARS, modified for polynomial chaos.
ordinal_khaos( X, y, degree = 15, order = 5, nmcmc = 10000, nburn = 9000, thin = 1, max_basis = 1000, tau2 = 10^5, sigma_thresh = 10, h1 = 4, h2 = 40/length(y), move_probs = rep(1/3, 3), coin_pars = list(function(j) 1/j, 1, 2, 3), degree_penalty = 0, verbose = TRUE )ordinal_khaos( X, y, degree = 15, order = 5, nmcmc = 10000, nburn = 9000, thin = 1, max_basis = 1000, tau2 = 10^5, sigma_thresh = 10, h1 = 4, h2 = 40/length(y), move_probs = rep(1/3, 3), coin_pars = list(function(j) 1/j, 1, 2, 3), degree_penalty = 0, verbose = TRUE )
X |
A data frame or matrix of predictors scaled to be between 0 and 1 |
y |
a response vector |
degree |
Maximum polynomial degree for each basis function. |
order |
Maximum order of interaction for each basis function. |
nmcmc |
Number of MCMC iterations. |
nburn |
Number of initial MCMC iterations to discard. |
thin |
Keep every |
max_basis |
Maximum number of basis functions. |
tau2 |
Prior variance for coefficients |
sigma_thresh |
Prior variance for the threshold parameters. |
h1, h2
|
Shape/rate parameters for the Gamma prior on expected number of basis functions. |
move_probs |
A 3-vector with probabilities for (i) birth, (ii) death, and (iii) mutation. |
coin_pars |
A list of control parameters for coinflip proposal |
degree_penalty |
Increasing this value encourages lower order polynomial terms (0 is no penalization). |
verbose |
Logical. Should progress information be printed? |
Implements the RJMCMC algorithm described by Francom & Sanso (2020) for BMARS, modifying it for polynomial chaos basis functions. As an alternative the NKD procedure of Nott et al. (2005), we use a coinflipping procedure to identify useful variables. See writeup (coming soon) for details. The coin_pars argument is an ordered list with elements:
a function giving proposal probability for q_0, the expected order of interaction,
epsilon, the base weight for each variable (epsilon=Inf corresponds to uniform sampling),
alpha, the exponent-learning rate,
num_passes a numerical parameter only.
Other proposal notes:
Expected order q0 is chosen from 1:order with weights coin_pars[[1]](1:order)
Degree is chosen from q0:degree with weights (1:(degree-q0+1))^(-degree_penalty) and a random partition is created (see helper function).
Two types of change steps are possible (and equally likely) A re-ordering of the degrees A single variable is swapped out with another one
An object of class "ordinal_khaos".
The object is a list containing:
Matrix of basis functions evaluated at the training inputs.
Arrays encoding the variables and polynomial degrees for each basis function across MCMC iterations.
Interaction order and total degree for each basis function.
Number of basis functions per MCMC iteration.
Posterior samples of regression coefficients.
Posterior samples of the ordinal threshold parameters.
Estimated latent variance across iterations.
Posterior samples of the Poisson rate parameter controlling model size.
Variable inclusion counts used in the proposal distribution.
Acceptance and proposal counts for RJMCMC moves.
Training data.
Francom, Devin, and Bruno Sanso. "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94.LA-UR-20-23587 (2020).
Nott, David J., Anthony YC Kuk, and Hiep Duc. "Efficient sampling schemes for Bayesian MARS models with many predictors." Statistics and Computing 15 (2005): 93-101.
set.seed(1) X <- matrix(runif(200), ncol = 1) y <- sample(1:4, 200, replace = TRUE) fit <- ordinal_khaos(X, y, nmcmc = 2000, nburn = 1000, thin = 2, verbose = FALSE) plot(fit)set.seed(1) X <- matrix(runif(200), ncol = 1) y <- sample(1:4, 200, replace = TRUE) fit <- ordinal_khaos(X, y, nmcmc = 2000, nburn = 1000, thin = 2, verbose = FALSE) plot(fit)
See adaptive_khaos() for details.
## S3 method for class 'adaptive_khaos' plot(x, ...)## S3 method for class 'adaptive_khaos' plot(x, ...)
x |
An object returned by the |
... |
Additional arguments for plotting |
Plot function for adaptive_khaos object.
No return value; called for its side effects (plotting).
Francom, Devin, and Bruno Sanso. "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94.LA-UR-20-23587 (2020).
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y) plot(fit)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y) plot(fit)
ordinal_khaos
Produces a 2x2 diagnostic plot: (1) trace of the number of basis functions;
(2) jittered predicted vs. actual classes with point size indicating posterior
support; (3) posterior mean class probabilities on x$X (lines if 1D,
otherwise barplot of averages); (4) histogram of latent means with
posterior-average thresholds overlaid.
## S3 method for class 'ordinal_khaos' plot(x, ...)## S3 method for class 'ordinal_khaos' plot(x, ...)
x |
An object of class |
... |
additional arguments passed to |
Panel (2) uses predict(x, type="class", aggregate=FALSE) to compute
per-draw MAP classes, plotting the modal class vs. observed class; point size
reflects the fraction of draws supporting the modal class. Panel (3) uses
predict(x, type="prob") to plot posterior mean class probabilities.
Panel (4) uses predict(x, type="latent", aggregate=FALSE) to pool
latent means across draws and overlays posterior-average cutpoints (handles
either stored or
with ).
Invisibly returns NULL.
set.seed(1) X <- matrix(runif(200), ncol = 1) y <- sample(1:4, 200, replace = TRUE) fit <- ordinal_khaos(X, y, nmcmc = 2000, nburn = 1000, thin = 2, verbose = FALSE) plot(fit)set.seed(1) X <- matrix(runif(200), ncol = 1) y <- sample(1:4, 200, replace = TRUE) fit <- ordinal_khaos(X, y, nmcmc = 2000, nburn = 1000, thin = 2, verbose = FALSE) plot(fit)
See sparse_khaos() for details.
## S3 method for class 'sparse_khaos' plot(x, ...)## S3 method for class 'sparse_khaos' plot(x, ...)
x |
An object returned by the |
... |
additional arguments passed to |
Plot function for sparse_khaos object.
returns invisible(x)
Shao, Q., Younes, A., Fahs, M., & Mara, T. A. (2017). Bayesian sparse polynomial chaos expansion for global sensitivity analysis. Computer Methods in Applied Mechanics and Engineering, 318, 474-496.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y) plot(fit)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y) plot(fit)
See adaptive_khaos() for details.
## S3 method for class 'adaptive_khaos' predict( object, newdata = NULL, mcmc.use = NULL, nugget = FALSE, nreps = 1, ... )## S3 method for class 'adaptive_khaos' predict( object, newdata = NULL, mcmc.use = NULL, nugget = FALSE, nreps = 1, ... )
object |
An object returned by the |
newdata |
A dataframe of the same dimension as the training data. |
mcmc.use |
Which posterior samples should be used for prediction? |
nugget |
Logical. Should predictions include error? |
nreps |
How many predictions should be taken for each mcmc sample (ignored when |
... |
Additional arguments to predict |
Predict function for adaptive_khaos object.
A numeric matrix of posterior predictive samples, with rows corresponding to samples and columns corresponding to observations.
Francom, Devin, and Bruno Sanso. "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94.LA-UR-20-23587 (2020).
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y) predict(fit)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y) predict(fit)
ordinal_khaos
Compute posterior predictive quantities for an ordinal probit BA-PCE model.
For each selected MCMC draw, the method builds the polynomial chaos basis,
forms the linear predictor , reconstructs the ordered
cutpoints, and returns either category probabilities, MAP classes, or latent
means. Results can be averaged across draws or returned per-draw.
## S3 method for class 'ordinal_khaos' predict( object, newdata = NULL, mcmc.use = NULL, type = c("class", "prob", "latent"), aggregate = FALSE, ... )## S3 method for class 'ordinal_khaos' predict( object, newdata = NULL, mcmc.use = NULL, type = c("class", "prob", "latent"), aggregate = FALSE, ... )
object |
An object of class |
newdata |
A data frame or matrix of predictors on the same scale and with
the same columns as used for fitting. If |
mcmc.use |
Integer vector of posterior draw indices to use. If |
type |
Character; one of |
aggregate |
Logical (default |
... |
Unused; included for method compatibility. |
Let with and
ordered cutpoints .
For a new input , the category probabilities are
The function reconstructs the full cutpoint vector internally. If the fitted
object stored then these are used directly;
if it stored only (with )
the missing fixed cutpoint is inserted automatically.
If type = "prob" and aggregate = TRUE, an nrow(newdata) x K
numeric matrix of posterior mean category probabilities. If aggregate = FALSE,
a 3-D array of dimension (#draws) x nrow(newdata) x K.
If type = "class" and aggregate = TRUE, an integer vector of length
nrow(newdata) with MAP classes aggregated by voting across draws. If
aggregate = FALSE, a (#draws) x nrow(newdata) integer matrix of
per-draw MAP classes.
If type = "latent", returns the latent mean(s) : a numeric vector
of length nrow(newdata) if aggregate = TRUE, or a
(#draws) x nrow(newdata) numeric matrix otherwise.
A numeric matrix of posterior predictive samples, with rows corresponding to samples and columns corresponding to observations.
Hoff, Peter D. (2009). A First Course in Bayesian Statistical Methods. Springer. (See ordinal probit data augmentation.)
Francom, Devin, and Bruno Sanso (2020). "BASS: An R package for fitting and performing sensitivity analysis of Bayesian adaptive spline surfaces." Journal of Statistical Software 94. LA-UR-20-23587.
ordinal_khaos for model fitting.
# Toy example (X scaled to [0,1]) set.seed(1) X <- lhs::maximinLHS(200, 3) # Suppose y has K=4 ordered categories: fit <- ordinal_khaos(X, sample(1:4, 200, replace=TRUE), nmcmc = 2000, nburn = 1000, thin = 2, verbose = FALSE) # Posterior mean probabilities for each class p_hat <- predict(fit, newdata = X, type = "prob", aggregate = TRUE) # MAP classes (aggregated across draws) y_hat <- predict(fit, newdata = X, type = "class") # Latent mean f(x) f_hat <- predict(fit, newdata = X, type = "latent")# Toy example (X scaled to [0,1]) set.seed(1) X <- lhs::maximinLHS(200, 3) # Suppose y has K=4 ordered categories: fit <- ordinal_khaos(X, sample(1:4, 200, replace=TRUE), nmcmc = 2000, nburn = 1000, thin = 2, verbose = FALSE) # Posterior mean probabilities for each class p_hat <- predict(fit, newdata = X, type = "prob", aggregate = TRUE) # MAP classes (aggregated across draws) y_hat <- predict(fit, newdata = X, type = "class") # Latent mean f(x) f_hat <- predict(fit, newdata = X, type = "latent")
See sparse_khaos() for details.
## S3 method for class 'sparse_khaos' predict(object, newdata = NULL, samples = 1000, nugget = FALSE, ...)## S3 method for class 'sparse_khaos' predict(object, newdata = NULL, samples = 1000, nugget = FALSE, ...)
object |
An object returned by the |
newdata |
A dataframe of the same dimension as the training data. |
samples |
How many posterior samples should be taken at each test point? If 0 or FALSE, then the MAP estimate is returned. |
nugget |
logical; should predictions include error? If FALSE, predictions will be for mean. |
... |
Additional arguments to predict |
Predict function for sparse_khaos object.
A numeric matrix of predictive samples (or a vector if samples = FALSE),
with rows corresponding to samples and columns corresponding to observations.
Shao, Q., Younes, A., Fahs, M., & Mara, T. A. (2017). Bayesian sparse polynomial chaos expansion for global sensitivity analysis. Computer Methods in Applied Mechanics and Engineering, 318, 474-496.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y) predict(fit)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y) predict(fit)
See sparse_khaos() for details.
## S3 method for class 'sparse_khaos' print(x, ...)## S3 method for class 'sparse_khaos' print(x, ...)
x |
An object returned by the |
... |
additional arguments passed to or from other methods. |
Print function for sparse_khaos object.
The input object x, invisibly.
Shao, Q., Younes, A., Fahs, M., & Mara, T. A. (2017). Bayesian sparse polynomial chaos expansion for global sensitivity analysis. Computer Methods in Applied Mechanics and Engineering, 318, 474-496.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y) print(fit)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y) print(fit)
Computes first-order, total-effect, and full interaction Sobol indices from an adaptive KHAOS model fit. Returns MCMC samples of sensitivity indices, including all active interaction terms used in the model.
sobol_khaos(obj, plot_it = TRUE, samples = 1000)sobol_khaos(obj, plot_it = TRUE, samples = 1000)
obj |
An object of class |
plot_it |
Logical; if |
samples |
How many samples from the posterior (only used for sparse class). |
A list with the following components:
A data frame of Sobol indices for all main effects and interactions (MCMC samples).
A data frame of total-effect Sobol indices (MCMC samples).
A numeric vector of unexplained variance proportions (residuals).
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y) sob <- sobol_khaos(fit) head(sob$S)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- adaptive_khaos(X, y) sob <- sobol_khaos(fit) head(sob$S)
A Bayesian sparse polynomial chaos expansion (PCE) method based on the forward-selection framework of Shao et al. (2017), with optional enrichment strategies that adapt the candidate basis set across degree and interaction-order expansions.
sparse_khaos( X, y, degree = c(2, 2, 16), order = c(1, 1, 5), prior = c(1, 1, 1), lambda = 1, rho = 0, regularize = TRUE, max_basis = 1e+06, enrichment = "adaptive", adaptive_ladder = c(10000, 1e+05), verbose = TRUE )sparse_khaos( X, y, degree = c(2, 2, 16), order = c(1, 1, 5), prior = c(1, 1, 1), lambda = 1, rho = 0, regularize = TRUE, max_basis = 1e+06, enrichment = "adaptive", adaptive_ladder = c(10000, 1e+05), verbose = TRUE )
X |
A data frame or matrix of predictors scaled to lie between 0 and 1. |
y |
A numeric response vector of length |
degree |
Integer vector of length 3 giving the polynomial-degree schedule:
|
order |
Integer vector of length 3 giving the interaction-order schedule:
|
prior |
Numeric vector of prior hyperparameters
|
lambda |
Nonnegative penalty parameter used in the KIC calculation. Larger values favor sparser models. |
rho |
Basis functions are discarded after partial-correlation screening if
their squared partial correlation is smaller than |
regularize |
Logical; if |
max_basis |
Maximum number of candidate basis functions allowed in any fitting round. This acts as a hard cap on computational cost. |
enrichment |
Either an integer in |
adaptive_ladder |
Numeric vector of candidate-size thresholds used only when
|
verbose |
Logical; if |
For fixed maximum degree and interaction order, the method constructs a candidate library of polynomial basis functions, ranks them using marginal correlations and sequential partial correlations, and evaluates nested models using the Kashyap information criterion (KIC). The best-ranked model is retained at that stage.
If the selected model contains a basis function at the current maximum degree or interaction order, the algorithm attempts another fitting round with increased degree and/or interaction order. In later rounds, the candidate basis set can be rebuilt using one of several enrichment strategies rather than constructing the full basis library from scratch.
The enrichment argument controls how the candidate set is generated after
the first fitting round:
0 (local enrichment)Starts from the previously selected basis functions and applies local modifications to each term. These include deletion, simplification, complication, and promotion moves. This is typically the fastest strategy, but it is also the most local.
1 (active-variable rebuild)Rebuilds the full candidate library using only variables that were active in the previously selected model. This is computationally efficient, but inactive variables cannot re-enter once dropped.
2 (full active rebuild plus sparse inactive enrichment)Rebuilds the candidate library on the currently active variables, then enriches around the previously selected basis functions by allowing inactive variables to re-enter through complication and promotion moves. This is a compromise between speed and flexibility.
3 (full active rebuild plus inactive enrichment)Rebuilds the candidate library on the active variables, then enriches that
larger active-variable library by allowing inactive variables to re-enter
through complication and promotion moves. This is more expansive than
enrichment = 2, but can be substantially more expensive.
4 (full rebuild)Rebuilds the full candidate library over all variables at each enrichment step. This is the most exhaustive strategy.
"adaptive"Begins with a relatively expansive enrichment strategy and, before the next recursion step, uses an upper bound on the candidate-set size to decide whether a more restrictive strategy should be used instead. This recovers the computational benefit of avoiding construction of candidate sets that are known in advance to be too large.
When enrichment = "adaptive", the function uses adaptive_ladder
together with an upper bound on the next candidate-set size. If the current
enrichment choice appears too expensive, the algorithm steps down to a more
restrictive enrichment rule before proceeding. If even the most restrictive
admissible next step is predicted to exceed the allowed budget, the current
fitted model is returned.
Strategies 2, 3, and "adaptive" are designed to address a
limitation of active-variable-only rebuilds: variables that are inactive in one
round are allowed to re-enter the model in later rounds.
An object of class "sparse_khaos".
The object is a list containing:
Matrix of selected basis functions evaluated at the training inputs.
Number of selected basis functions (including intercept).
Matrix encoding the polynomial multi-indices for each basis function.
MAP estimates of the regression coefficients.
Estimated noise variance.
Training data (with y on the original scale).
Centering and scaling constants used for y.
Cross-product matrix and its inverse.
Prior scaling factors for coefficients.
Prior hyperparameters.
Kashyap information criterion values for candidate models.
Shao, Q., Younes, A., Fahs, M., and Mara, T. A. (2017). Bayesian sparse polynomial chaos expansion for global sensitivity analysis. Computer Methods in Applied Mechanics and Engineering, 318, 474–496.
Rumsey, K. N., Francom, D., Gibson, G., Tucker, J. D., and Huerta, G. (2026). Bayesian adaptive polynomial chaos expansions. Stat, 15(1), e70151.
X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391 * ((x[1] - 0.4) * (x[2] - 0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y)X <- lhs::maximinLHS(100, 2) f <- function(x) 10.391 * ((x[1] - 0.4) * (x[2] - 0.6) + 0.36) y <- apply(X, 1, f) + stats::rnorm(100, 0, 0.1) fit <- sparse_khaos(X, y)