| Title: | Generalized Bayesian Adaptive Smoothing Splines |
|---|---|
| Description: | Bayesian nonlinear regression under a range of likelihood models using generalized Bayesian adaptive smoothing splines. Robust regression with Student's t likelihoods, quantile regression, and related latent-scale models are included as special cases. |
| Authors: | Kellin Rumsey [aut, cre] |
| Maintainer: | Kellin Rumsey <[email protected]> |
| License: | BSD_3_clause + file LICENSE |
| Version: | 2.0.1 |
| Built: | 2026-05-25 09:25:40 UTC |
| Source: | https://github.com/cran/GBASS |
Bayesian nonlinear regression under a range of likelihood models using generalized Bayesian adaptive smoothing splines. Robust regression with Student's t likelihoods, quantile regression, and related latent-scale models are included as special cases.
Maintainer: Kellin Rumsey [email protected]
Construct a prior specification for GBASS
build_prior( type = c("GIG", "GBP"), p, a, b, lower_bound = NULL, prop_sigma = NULL, adapt = NULL, adapt_delay = NULL, adapt_thin = NULL ) build_GIG( p, a, b, lower_bound = NULL, prop_sigma = NULL, adapt = NULL, adapt_delay = NULL, adapt_thin = NULL ) build_GBP( p, a, b, lower_bound = NULL, prop_sigma = NULL, adapt = NULL, adapt_delay = NULL, adapt_thin = NULL )build_prior( type = c("GIG", "GBP"), p, a, b, lower_bound = NULL, prop_sigma = NULL, adapt = NULL, adapt_delay = NULL, adapt_thin = NULL ) build_GIG( p, a, b, lower_bound = NULL, prop_sigma = NULL, adapt = NULL, adapt_delay = NULL, adapt_thin = NULL ) build_GBP( p, a, b, lower_bound = NULL, prop_sigma = NULL, adapt = NULL, adapt_delay = NULL, adapt_thin = NULL )
type |
"GIG" or "GBP" |
p, a, b
|
prior hyperparameters |
lower_bound |
optional lower bound |
prop_sigma |
optional proposal sd (log scale) |
adapt |
logical; use adaptive MH? |
adapt_delay |
delay before adapting |
adapt_thin |
thinning for adaptation updates |
A named list containing the prior specification.
Fits a generalized Bayesian MARS (GBASS) model for nonlinear regression under flexible latent-scale likelihoods.
gbass( X, y, w_prior = list(type = "GIG", p = 0, a = 0, b = 0), v_prior = list(type = "GIG", p = -15, a = 0, b = 30), maxInt = 3, maxBasis = 1000, npart = NULL, nmcmc = 10000, nburn = 9000, thin = 1, moveProbs = rep(1/3, 3), a_tau = 1/2, b_tau = NULL, a_lambda = 1, b_lambda = 1, m_beta = 0, s_beta = 0, scale = 1, Iw0 = rep(1, maxInt), Zw0 = rep(1, ncol(X)), verbose = TRUE )gbass( X, y, w_prior = list(type = "GIG", p = 0, a = 0, b = 0), v_prior = list(type = "GIG", p = -15, a = 0, b = 30), maxInt = 3, maxBasis = 1000, npart = NULL, nmcmc = 10000, nburn = 9000, thin = 1, moveProbs = rep(1/3, 3), a_tau = 1/2, b_tau = NULL, a_lambda = 1, b_lambda = 1, m_beta = 0, s_beta = 0, scale = 1, Iw0 = rep(1, maxInt), Zw0 = rep(1, ncol(X)), verbose = TRUE )
X |
An |
y |
A numeric response vector of length |
w_prior |
A named list specifying the prior for the global variance component. See Details. |
v_prior |
A named list specifying the shared prior for the local variance components. See Details. |
maxInt |
Integer giving the maximum interaction degree in proposed basis functions. |
maxBasis |
Maximum number of basis functions. |
npart |
Minimum number of nonzero points required for a proposed basis
function. Defaults to |
nmcmc |
Total number of MCMC iterations. |
nburn |
Number of initial iterations discarded as burn-in. |
thin |
Thinning interval for retained draws. |
moveProbs |
A length-3 vector giving probabilities for birth, death, and mutation moves. |
a_tau |
Prior hyperparameter for |
b_tau |
Prior hyperparameter for |
a_lambda |
Prior hyperparameter for |
b_lambda |
Prior hyperparameter for |
m_beta |
Prior mean for |
s_beta |
Prior standard deviation for |
scale |
Fixed variance-scale parameter. Defaults to |
Iw0 |
Vector of positive nominal weights for interaction order in proposed
basis functions. Must have length |
Zw0 |
Vector of positive nominal weights for variable selection in
proposed basis functions. Must have length |
verbose |
Logical; should progress be printed? |
The priors for w and v_i must belong to the generalized inverse
Gaussian ("GIG") or generalized beta prime ("GBP") families.
Each prior list may contain:
type: either "GIG" or "GBP".
p, a, b: prior hyperparameters.
lower_bound: optional lower bound for the parameter support.
For backward compatibility, lb is also accepted.
prop_sigma: proposal standard deviation on the log scale for
Metropolis updates, when applicable.
adapt, adapt_delay, adapt_thin: optional controls
for adaptive Metropolis updates when applicable.
For w, prop_sigma and the adaptive Metropolis fields are mainly
relevant when w_prior$type = "GBP". In the "GIG" case with
nonzero beta, w is sampled using the modified half-normal
formulation rather than a random-walk Metropolis step.
Retained draws are taken at iterations
nburn + 1, nburn + 1 + thin, .... Thus nburn is interpreted as
the number of initial iterations discarded as burn-in.
An object of class "gbass" containing posterior draws and fitted model
information.
Current implementation notes:
Basis function parameters are stored as lists.
Knot locations use continuous uniform proposals.
Basis coefficients use a ridge-type prior.
ff1 <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) n <- 100 p <- 4 X <- matrix(runif(n * p), nrow = n) y <- apply(X, 1, ff1) mod <- gbass(X, y, nmcmc = 1000, nburn = 900, thin = 2)ff1 <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) n <- 100 p <- 4 X <- matrix(runif(n * p), nrow = n) y <- apply(X, 1, ff1) mod <- gbass(X, y, nmcmc = 1000, nburn = 900, thin = 2)
Converts an object of class gbass to an object with class bass,
so that downstream BASS utilities such as Sobol decomposition can be used.
gbass2bass(gm) gm2bm(gm)gbass2bass(gm) gm2bm(gm)
gm |
An object of class |
An object with class c("bass", "gbass").
Computes Sobol sensitivity indices for a fitted gbass model by first
converting it to a compatible BASS object with gbass2bass(),
and then calling BASS::sobol().
gsobol(object, ...)gsobol(object, ...)
object |
A fitted object of class |
... |
Additional arguments passed to |
This is a thin wrapper around BASS::sobol() for GBASS models.
Users who want direct access to the converted BASS object can call
gbass2bass() explicitly and then use BASS::sobol() themselves.
An object of class "bassSob" returned by BASS::sobol().
ff1 <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) n <- 100 p <- 4 X <- matrix(runif(n * p), nrow = n) y <- apply(X, 1, ff1) mod <- gbass(X, y, nmcmc = 1000, nburn = 900) # Direct wrapper sob <- gsobol(mod) # Equivalent manual conversion bm <- gbass2bass(mod) sob2 <- BASS::sobol(bm)ff1 <- function(x) 10.391*((x[1]-0.4)*(x[2]-0.6) + 0.36) n <- 100 p <- 4 X <- matrix(runif(n * p), nrow = n) y <- apply(X, 1, ff1) mod <- gbass(X, y, nmcmc = 1000, nburn = 900) # Direct wrapper sob <- gsobol(mod) # Equivalent manual conversion bm <- gbass2bass(mod) sob2 <- BASS::sobol(bm)
Wrapper around gbass() using generalized beta prime latent-scale priors.
hbass( X, y, w_prior = list(type = "GBP", p = 1, a = 1/2, b = 1/2), likelihood = "h", ... )hbass( X, y, w_prior = list(type = "GBP", p = 1, a = 1/2, b = 1/2), likelihood = "h", ... )
X |
An |
y |
A numeric response vector of length |
w_prior |
A named list specifying the prior for the global variance component. See Details. |
likelihood |
Character string specifying the likelihood family.
Use |
... |
Additional arguments passed to |
The Horseshoe and Strawderman-Berger likelihoods can be expressed using
generalized beta prime latent-scale distributions. This function provides a
convenient wrapper for these likelihoods. For additional flexibility, use
gbass() directly.
An object of class c("hbass", "gbass") containing posterior draws
and fitted model information.
Estimates Normal-Wald parameters from sample moments or from a supplied vector of moments.
nw_est_mom( data = NULL, stats = NULL, mu = NA, delta = NA, beta = NA, alpha = NA, triangle = FALSE, ... )nw_est_mom( data = NULL, stats = NULL, mu = NA, delta = NA, beta = NA, alpha = NA, triangle = FALSE, ... )
data |
Optional data vector. If supplied, empirical moments are computed
from |
stats |
Optional numeric vector of length 4 containing mean, variance,
skewness, and kurtosis. Entries may be |
mu |
Location parameter, if fixed. |
delta |
Scale parameter, if fixed. |
beta |
Skewness parameter, if fixed. |
alpha |
Tail parameter, if fixed. |
triangle |
Logical; if |
... |
Additional arguments passed to |
This function computes method-of-moments estimates for the Normal-Wald
distribution. If data is supplied, sample mean, variance, skewness,
and kurtosis are computed automatically. Otherwise, the user may provide
these moments directly through stats.
If some parameters are fixed, only the remaining parameters are estimated.
When triangle = TRUE, the returned values are the transformed summary
quantities
and a corresponding
asymmetry measure.
If triangle = FALSE, a named numeric vector with entries
mu, delta, beta, and alpha.
If triangle = TRUE, a named numeric vector with entries
asymmetry and steepness.
n <- 500 y <- rgamma(n, 3, 1.5) + rlnorm(n, 1, 0.5) z <- (y - mean(y)) / sd(y) skew <- mean(z^3) kurt <- mean(z^4) nw_est_mom(stats = c(NA, NA, skew, kurt), mu = 0, delta = 1, triangle = TRUE) nw_est_mom(stats = c(NA, var(y), skew, kurt), mu = 0, triangle = TRUE)n <- 500 y <- rgamma(n, 3, 1.5) + rlnorm(n, 1, 0.5) z <- (y - mean(y)) / sd(y) skew <- mean(z^3) kurt <- mean(z^4) nw_est_mom(stats = c(NA, NA, skew, kurt), mu = 0, delta = 1, triangle = TRUE) nw_est_mom(stats = c(NA, var(y), skew, kurt), mu = 0, triangle = TRUE)
Selects prior hyperparameters for gamma in the Normal-Wald model using
probability statements about the steepness parameter
.
nw_gamma_prior( q1 = 0.1, q2 = 0.9, p1 = 0.5, p2 = 0.05, par0 = NULL, lambda = 0 )nw_gamma_prior( q1 = 0.1, q2 = 0.9, p1 = 0.5, p2 = 0.05, par0 = NULL, lambda = 0 )
q1 |
Lower reference value for the steepness parameter. Default is
|
q2 |
Upper reference value for the steepness parameter. Default is
|
p1 |
Target probability associated with |
p2 |
Target probability associated with |
par0 |
Optional starting values for the numerical optimization. |
lambda |
Optional ridge penalty used in the optimization. Default is
|
This function chooses hyperparameters for a prior on gamma by solving
a simple calibration problem based on the steepness parameter
. The optimization is carried out with
optim using the Nelder-Mead method.
A named numeric vector with entries m_gamma and
s_gamma.
nw_gamma_prior() nw_gamma_prior(q1 = 0.2, q2 = 0.8, p1 = 0.4, p2 = 0.1)nw_gamma_prior() nw_gamma_prior(q1 = 0.2, q2 = 0.8, p1 = 0.4, p2 = 0.1)
Visualizes posterior draws of the Normal-Wald shape parameters in terms of
asymmetry and steepness. The plotted coordinates are
and
.
nw_triangle(obj, add = FALSE, details = FALSE, ...)nw_triangle(obj, add = FALSE, details = FALSE, ...)
obj |
A fitted object containing components |
add |
Logical; if |
details |
Logical; if |
... |
Additional graphical arguments passed to |
This plot provides a simple geometric summary of the shape of the Normal-Wald likelihood. The upper boundary corresponds to symmetric models, while points away from zero on the horizontal axis indicate asymmetry.
Invisibly returns a data frame with columns asymmetry and
steepness.
# mod is a fitted nwbass model # Simple example n <- 200 X <- lhs::maximinLHS(n, 2) f <- 20 * apply(X, 1, function(x) sin(pi * x[1]) + x[2]^2) eps <- rgamma(n, 3, 1.5) - 2 y <- f + eps mod <- nwbass(X, y, m_beta=0, s_beta=10, m_gamma = nw_gamma_prior()[1], s_gamma = nw_gamma_prior()[2]) nw_triangle(mod)# mod is a fitted nwbass model # Simple example n <- 200 X <- lhs::maximinLHS(n, 2) f <- 20 * apply(X, 1, function(x) sin(pi * x[1]) + x[2]^2) eps <- rgamma(n, 3, 1.5) - 2 y <- f + eps mod <- nwbass(X, y, m_beta=0, s_beta=10, m_gamma = nw_gamma_prior()[1], s_gamma = nw_gamma_prior()[2]) nw_triangle(mod)
Fits a generalized BMARS model under a Normal-Wald likelihood. This provides flexible nonlinear regression with a unimodal, potentially skewed error model.
nwbass( X, y, w_prior = list(type = "GIG", p = -0.1, a = 0, b = 0.1), maxInt = 3, maxBasis = 1000, npart = NULL, nmcmc = 10000, nburn = 9000, thin = 1, moveProbs = rep(1/3, 3), a_tau = 1/2, b_tau = NULL, a_lambda = 1, b_lambda = 1, m_beta = 0, s_beta = 0, lag_beta = 1001, m_gamma = 1, s_gamma = 0, scale = 1, Iw0 = rep(1, maxInt), Zw0 = rep(1, ncol(X)), verbose = TRUE ) nwbass2(...)nwbass( X, y, w_prior = list(type = "GIG", p = -0.1, a = 0, b = 0.1), maxInt = 3, maxBasis = 1000, npart = NULL, nmcmc = 10000, nburn = 9000, thin = 1, moveProbs = rep(1/3, 3), a_tau = 1/2, b_tau = NULL, a_lambda = 1, b_lambda = 1, m_beta = 0, s_beta = 0, lag_beta = 1001, m_gamma = 1, s_gamma = 0, scale = 1, Iw0 = rep(1, maxInt), Zw0 = rep(1, ncol(X)), verbose = TRUE ) nwbass2(...)
X |
An |
y |
A numeric response vector of length |
w_prior |
A named list specifying the prior for the global variance component. See Details. |
maxInt |
Integer giving the maximum degree of interaction in spline basis
functions. Defaults to |
maxBasis |
Maximum number of basis functions. |
npart |
Minimum number of nonzero points required for a proposed basis
function. Defaults to |
nmcmc |
Total number of MCMC iterations. |
nburn |
Number of initial MCMC iterations discarded as burn-in. |
thin |
Thinning interval for retained draws. |
moveProbs |
A length-3 vector giving probabilities for birth, death, and mutation moves. |
a_tau |
Prior hyperparameter for |
b_tau |
Prior hyperparameter for |
a_lambda |
Prior hyperparameter for |
b_lambda |
Prior hyperparameter for |
m_beta |
Prior mean for |
s_beta |
Prior standard deviation for |
lag_beta |
Number of initial iterations for which |
m_gamma |
Prior mean for |
s_gamma |
Prior standard deviation for |
scale |
Fixed variance-scale parameter. Defaults to |
Iw0 |
Vector of positive nominal weights for interaction order in proposed
basis functions. Must have length |
Zw0 |
Vector of positive nominal weights for variable selection in proposed
basis functions. Must have length |
verbose |
Logical; should progress be printed? |
... |
(for backwards compatability) |
The latent local-scale prior is fixed internally to the Normal-Wald form
. Unlike gbass(),
nwbass() does not expose a user-specified v_prior.
The w_prior list should contain:
type: either "GIG" or "GBP".
p, a, b: hyperparameters for the prior.
lower_bound: optional lower bound for w. For backward
compatibility, lb is also accepted.
prop_sigma: proposal standard deviation on the log scale for
Metropolis updates of w. This is only used when w is updated
by Metropolis-Hastings, such as the "GBP" case.
adapt, adapt_delay, adapt_thin: optional controls
for adaptive Metropolis updates of w when applicable.
Retained draws are taken at iterations
nburn + 1, nburn + 1 + thin, .... Thus nburn is interpreted as
the number of initial iterations discarded as burn-in.
An object of class c("nwbass", "gbass") containing posterior draws and
fitted model information.
n <- 200 X <- lhs::maximinLHS(n, 2) f <- 20 * apply(X, 1, function(x) sin(pi * x[1]) + x[2]^2) eps <- rgamma(n, 3, 1.5) - 2 y <- f + eps mod <- nwbass(X, y, m_beta=0, s_beta=10, m_gamma = nw_gamma_prior()[1], s_gamma = nw_gamma_prior()[2])n <- 200 X <- lhs::maximinLHS(n, 2) f <- 20 * apply(X, 1, function(x) sin(pi * x[1]) + x[2]^2) eps <- rgamma(n, 3, 1.5) - 2 y <- f + eps mod <- nwbass(X, y, m_beta=0, s_beta=10, m_gamma = nw_gamma_prior()[1], s_gamma = nw_gamma_prior()[2])
Plot method for gbass objects
## S3 method for class 'gbass' plot(x, ...)## S3 method for class 'gbass' plot(x, ...)
x |
A fitted object of class |
... |
Additional graphical arguments. |
No return value, called for its side effects.
Returns posterior draws of either: (i) the linear predictor / mean surface, or (ii) the full posterior predictive distribution.
## S3 method for class 'gbass' predict( object, newdata = NULL, mcmc.use = NULL, predictive = TRUE, bias_correct = FALSE, samples = 1, ... )## S3 method for class 'gbass' predict( object, newdata = NULL, mcmc.use = NULL, predictive = TRUE, bias_correct = FALSE, samples = 1, ... )
object |
an object of class "gbass" (including subclasses like "tbass", "qbass", "nwbass") |
newdata |
a matrix of predictor variables. Defaults to training inputs. |
mcmc.use |
optional vector indicating which posterior draws to use. |
predictive |
logical. If TRUE, return posterior predictive draws. If FALSE, return draws of the linear predictor. |
bias_correct |
logical. Ignored unless predictive = FALSE. If TRUE, return the posterior mean response rather than just the linear predictor. |
samples |
Integer giving the number of predictive samples to generate
per retained MCMC draw when |
... |
Additional graphical arguments (not used) |
If predictive = FALSE and bias_correct = FALSE, this returns draws of B(x)a.
If predictive = FALSE and bias_correct = TRUE, this returns draws of B(x)a + E(error | posterior draw), i.e. the mean response under the fitted GBASS error model.
If predictive = TRUE, this returns posterior predictive draws by simulating a fresh latent local variance v_new and Gaussian draw for each posterior sample.
For qbass objects, bias_correct = TRUE is usually not what you want, because qbass is typically being used for quantile regression rather than mean regression.
Currently, posterior predictive draws are implemented for GIG-based models. If the fitted object uses a GBP prior for v, predictive = TRUE will stop.
a matrix with rows corresponding to posterior draws and columns corresponding to rows of newdata.
Print a gbass object
## S3 method for class 'gbass' print(x, ...)## S3 method for class 'gbass' print(x, ...)
x |
An object of class |
... |
Unused. |
The input object, invisibly.
Wrapper around gbass() for quantile regression.
qbass( X, y, q = 0.5, w_prior = list(type = "GIG", p = -0.1, a = 0, b = 0.1), ... )qbass( X, y, q = 0.5, w_prior = list(type = "GIG", p = -0.1, a = 0, b = 0.1), ... )
X |
An |
y |
A numeric response vector of length |
q |
Quantile of interest. Default is |
w_prior |
Prior for the global variance factor. |
... |
Additional arguments passed to |
Performs quantile regression for quantile q using the asymmetric
Laplace representation. For many quantiles, fitting separate models in
parallel may be convenient.
An object of class c("qbass", "gbass") containing posterior draws
and fitted model information.
This function generates samples from the GIG(p, a, b) distribution with density function f(x) = cx^(p-1)exp(-1/2*(a*x + b/x))
rgig2(p, a, b)rgig2(p, a, b)
p |
a real valued parameter |
a |
a non-negative parameter. If a=0, then p must be negative. |
b |
a non-negative parameter. If b=0, then p must be positive. |
A uniformly bounded rejection sample based on Hörmann et. al. (2014). Special cases include Gamma (b=0, p>0), Inverse Gamma (a=0, p<0) and Inverse Gaussian (p=-1/2).
A numeric vector of random draws from the generalized inverse Gaussian distribution.
Hörmann, Wolfgang, and Josef Leydold. "Generating generalized inverse Gaussian random variates." Statistics and Computing 24.4 (2014): 547-557.
x <- rep(NA, 1000) for(i in 1:1000) x[i] <- rgig2(2, 3, 0.5) hist(x)x <- rep(NA, 1000) for(i in 1:1000) x[i] <- rgig2(2, 3, 0.5) hist(x)
Generates random samples from the modified half-normal distribution with
density proportional to
for .
rmhn(n = 1, alpha, beta, gamma)rmhn(n = 1, alpha, beta, gamma)
n |
Number of random draws. |
alpha |
Positive shape parameter. |
beta |
Positive rate parameter multiplying x^2. |
gamma |
Real-valued linear parameter multiplying x. |
This distribution arises in latent-scale updates for the generalized Bayesian adaptive smoothing spline model. The function is intended mainly for internal model fitting, but it may also be useful on its own.
A numeric vector of length n containing random draws from the
modified half-normal distribution.
x <- rmhn(1000, alpha = 3, beta = 1, gamma = 0.5) hist(x, breaks = 30, freq = FALSE)x <- rmhn(1000, alpha = 3, beta = 1, gamma = 0.5) hist(x, breaks = 30, freq = FALSE)
Wrapper around gbass() for a Student's t error model.
tbass(X, y, df = 5, ...)tbass(X, y, df = 5, ...)
X |
An |
y |
A numeric response vector of length |
df |
Degrees of freedom. Default is |
... |
Additional arguments passed to |
Uses an inverse-gamma latent-scale representation through a GIG prior on the
local variance components. If df > 2, the scale is set to
(df - 2) / df so that the marginal variance matches w.
An object of class c("tbass", "gbass") containing posterior draws
and fitted model information.