| Title: | Bayesian Projection Pursuit Regression |
|---|---|
| Description: | Bayesian fitting of projection pursuit regression model. Built to handle continuous and categorical inputs and scalar output (Collins et al., 2023 <DOI:10.1007/s11222-023-10334-z>). |
| Authors: | Gavin Collins [aut, ctb], J. Derek Tucker [ctb, cre] (ORCID: <https://orcid.org/0000-0001-8844-2169>) |
| Maintainer: | J. Derek Tucker <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-18 19:37:28 UTC |
| Source: | https://github.com/cran/BayesPPR |
Fits a BayesPPR model using RJMCMC. Can handle categorical features.
bppr( X, y, n_ridge_mean = 10, n_ridge_max = NULL, n_act_max = NULL, df_spline = 4, prob_relu = 2/3, prior_coefs = "zs", shape_var_coefs = NULL, scale_var_coefs = NULL, n_dat_min = NULL, scale_proj_dir_prop = NULL, adapt_act_feat = TRUE, w_n_act = NULL, w_feat = NULL, n_post = 1000, n_burn = 9000, n_adapt = 0, n_thin = 1, print_every = 1000, bppr_init = NULL )bppr( X, y, n_ridge_mean = 10, n_ridge_max = NULL, n_act_max = NULL, df_spline = 4, prob_relu = 2/3, prior_coefs = "zs", shape_var_coefs = NULL, scale_var_coefs = NULL, n_dat_min = NULL, scale_proj_dir_prop = NULL, adapt_act_feat = TRUE, w_n_act = NULL, w_feat = NULL, n_post = 1000, n_burn = 9000, n_adapt = 0, n_thin = 1, print_every = 1000, bppr_init = NULL )
X |
a data frame or matrix of predictors. Categorical features should be coded as numeric. |
y |
a numeric response vector. |
n_ridge_mean |
mean for Poisson prior on the number of ridge functions. |
n_ridge_max |
maximum number of ridge functions allowed in the model. Used to avoid memory overload. Defaults to 150 unless the number of observed responses is small. |
n_act_max |
maximum number of active variables in any given ridge function. Defaults to 3 unless categorical features are detected, in which case the default is larger. |
df_spline |
degrees of freedom for spline basis. Stability should be examined for anything other than 4. |
prob_relu |
prior probability that any given ridge function uses a relu transformation. |
prior_coefs |
form of the prior distribution for the basis coefficients. Default is |
shape_var_coefs |
shape for IG prior on the variance of the basis function coefficients. Default is for the Zellner-Siow prior. For the flat, improper prior, |
scale_var_coefs |
scale for IG prior on the variance of the basis function coefficients. Default is for the Zellner-Siow prior. For the flat, improper prior, |
n_dat_min |
minimum number of observed non-zero datapoints in a ridge function. Defaults to 20 or 0.1 times the number of observations, whichever is smaller. |
scale_proj_dir_prop |
scale parameter for generating proposed projection directions. Should be in (0, 1); default is about 0.002. |
adapt_act_feat |
logical; if |
w_n_act |
vector of weights for number of active variables in a ridge function, used in generating proposed basis functions. If |
w_feat |
vector of weights for feature indices used in a ridge function, used in generating proposed basis functions. If |
n_post |
number of posterior draws to obtain from the Markov chain after burn-in. |
n_burn |
number of draws to burn before obtaining |
n_adapt |
number of adaptive MCMC iterations to perform before burn-in. Skips sampling basis coefficients and residual variance to save time. |
n_thin |
keep every n_thin posterior draws after burn-in. |
print_every |
print the iteration number every print_every iterations. Use |
bppr_init |
list of initial values for the Markov chain. Used by bppr_resume. |
Explores BayesPPR model space using RJMCMC. The BayesPPR model has
and is a natural spline basis expansion. We use priors
as well as the hyper-prior on the variance of the coefficients mentioned in the arguments above.
An object of class "bppr". Predictions can be obtained by passing the entire object to the predict.bppr function.
predict.bppr for prediction.
################################ ### univariate example ################################ ## simulate data (Friedman function) f <- function(X){ 10*sin(pi*X[,1]*X[,2]) + 20*(X[,3] - .5)^2 + 10*X[,4] + 5*X[,5] } n <- 500 # number of observations p <- 10 #10 variables, only first 5 matter X <- matrix(runif(n*p), n, p) y <- f(X) + rnorm(n) ## fit BPPR fit <- bppr(X, y) ## plot diagnostics plot(fit) ## get out-of-sample predictions X_test <- matrix(runif(n*p), n, p) preds <- predict(fit, X_test) # posterior predictive samples ## minimal example for CRAN testing fit <- bppr(matrix(1:50), 1:50, n_post = 2, n_burn = 0, n_adapt = 0)################################ ### univariate example ################################ ## simulate data (Friedman function) f <- function(X){ 10*sin(pi*X[,1]*X[,2]) + 20*(X[,3] - .5)^2 + 10*X[,4] + 5*X[,5] } n <- 500 # number of observations p <- 10 #10 variables, only first 5 matter X <- matrix(runif(n*p), n, p) y <- f(X) + rnorm(n) ## fit BPPR fit <- bppr(X, y) ## plot diagnostics plot(fit) ## get out-of-sample predictions X_test <- matrix(runif(n*p), n, p) preds <- predict(fit, X_test) # posterior predictive samples ## minimal example for CRAN testing fit <- bppr(matrix(1:50), 1:50, n_post = 2, n_burn = 0, n_adapt = 0)
Fits a BayesPPR model to multivariate response using RJMCMC. Can handle categorical features.
bppr_pca( X, Y, n_pc = NULL, prop_var = 0.99, n_cores = 1, par_type = "fork", n_ridge_mean = 10, n_ridge_max = NULL, n_act_max = NULL, df_spline = 4, prob_relu = 2/3, prior_coefs = "zs", shape_var_coefs = NULL, scale_var_coefs = NULL, n_dat_min = NULL, scale_proj_dir_prop = NULL, adapt_act_feat = TRUE, w_n_act = NULL, w_feat = NULL, n_post = 1000, n_burn = 9000, n_adapt = 0, n_thin = 1, print_every = NULL, bppr_init_list = NULL )bppr_pca( X, Y, n_pc = NULL, prop_var = 0.99, n_cores = 1, par_type = "fork", n_ridge_mean = 10, n_ridge_max = NULL, n_act_max = NULL, df_spline = 4, prob_relu = 2/3, prior_coefs = "zs", shape_var_coefs = NULL, scale_var_coefs = NULL, n_dat_min = NULL, scale_proj_dir_prop = NULL, adapt_act_feat = TRUE, w_n_act = NULL, w_feat = NULL, n_post = 1000, n_burn = 9000, n_adapt = 0, n_thin = 1, print_every = NULL, bppr_init_list = NULL )
X |
a data frame or matrix of predictors. Categorical features should be coded as numeric. |
Y |
a data frame or matrix of responses, with columns representing different dimensions of the response. |
n_pc |
number of principle components to be used in pca approximation of Y. |
prop_var |
proportion of variance to be explained by the first |
n_cores |
number of cores the user desired to utilize for parallel computation. |
par_type |
a character variable dicatating the type of parallel computation to be performed. Supported values include |
n_ridge_mean |
mean for Poisson prior on the number of ridge functions. |
n_ridge_max |
maximum number of ridge functions allowed in the model. Used to avoid memory overload. Defaults to 150 unless the number of observed responses is small. |
n_act_max |
maximum number of active variables in any given ridge function. Defaults to 3 unless categorical features are detected, in which case the default is larger. |
df_spline |
degrees of freedom for spline basis. Stability should be examined for anything other than 4. |
prob_relu |
prior probability that any given ridge function uses a relu transformation. |
prior_coefs |
form of the prior distribution for the basis coefficients. Default is |
shape_var_coefs |
shape for IG prior on the variance of the basis function coefficients. Default is for the Zellner-Siow prior. For the flat, improper prior, |
scale_var_coefs |
scale for IG prior on the variance of the basis function coefficients. Default is for the Zellner-Siow prior. For the flat, improper prior, |
n_dat_min |
minimum number of observed non-zero datapoints in a ridge function. Defaults to 20 or 0.1 times the number of observations, whichever is smaller. |
scale_proj_dir_prop |
scale parameter for generating proposed projection directions. Should be in (0, 1); default is about 0.002. |
adapt_act_feat |
logical; if |
w_n_act |
vector of weights for number of active variables in a ridge function, used in generating proposed basis functions. If |
w_feat |
vector of weights for feature indices used in a ridge function, used in generating proposed basis functions. If |
n_post |
number of posterior draws to obtain from the Markov chain after burn-in. |
n_burn |
number of draws to burn before obtaining |
n_adapt |
number of adaptive MCMC iterations to perform before burn-in. Skips sampling basis coefficients and residual variance to save time. |
n_thin |
keep every n_thin posterior draws after burn-in. |
print_every |
print the iteration number every print_every iterations. Use |
bppr_init_list |
list of length |
Explores BayesPPR model space using RJMCMC. The BayesPPR model has
and is a natural spline basis expansion. We use priors
as well as the hyper-prior on the variance of the coefficients mentioned in the arguments above.
An object of class "bppr_pca". Predictions can be obtained by passing the entire object to the predict.bppr_pca function.
predict.bppr_pca for prediction.
# See examples in bppr documentation.# See examples in bppr documentation.
Resumes fitting a BayesPPR model where the last Markov chain left off, using the same model parameters.
bppr_resume( object, append = FALSE, n_post = 1000, n_burn = 9000, n_adapt = 0, n_thin = 1, print_every = 1000 )bppr_resume( object, append = FALSE, n_post = 1000, n_burn = 9000, n_adapt = 0, n_thin = 1, print_every = 1000 )
object |
an object of class |
append |
logical; if |
n_post |
number of posterior draws to obtain from the Markov chain after burn-in. |
n_burn |
number of draws to burn before obtaining |
n_adapt |
number of adaptive MCMC iterations to perform before burn-in. Skips sampling basis coefficients and residual variance to save time. |
n_thin |
keep every n_thin posterior draws after burn-in. |
print_every |
print the iteration number every print_every iterations. Use |
Continues exploring BayesPPR model space using RJMCMC, beginning at the values contained in the last iteration of object.
An object of class "bppr". Predictions can be obtained by passing the entire object to the predict.bppr function.
predict.bppr for prediction.
Generate diagnostic plots for BPPR model fit.
## S3 method for class 'bppr' plot(x, quants = c(0.025, 0.975), pred = TRUE, ...)## S3 method for class 'bppr' plot(x, quants = c(0.025, 0.975), pred = TRUE, ...)
x |
a |
quants |
quantiles for intervals, if desired. NULL if not desired. |
pred |
logical, whether posterior predictions should be plotted (defaults to TRUE). |
... |
graphical parameters. |
The first two plots are trace plots for diagnosing convergence. The third plot is posterior predicted vs observed, with intervals for predictions. The fourth plot is a histogram of the residuals (of the posterior mean model), with a red curve showing the assumed Normal density (using posterior mean variance). If pred=FALSE the third and fourth plots are omitted.
no return value
# See examples in bppr documentation.# See examples in bppr documentation.
Predict function for BayesPPR. Outputs posterior predictive samples for the desired MCMC iterations.
## S3 method for class 'bppr' predict(object, newdata, idx_use = NULL, ...)## S3 method for class 'bppr' predict(object, newdata, idx_use = NULL, ...)
object |
a fitted model, output from the |
newdata |
a matrix of new input values at which to predict. The columns should correspond to the same variables used in the |
idx_use |
index of Markov samples to use when generating predictions. |
... |
further arguments passed to or from other methods. |
Bare-bones methods. Could be improved for efficiency.
A matrix with the same number of rows as newdata and columns corresponding to all MCMC iterations indexed by idx_use. These are samples from the posterior predictive distribution.
bppr for model fitting.
# See examples in bppr documentation.# See examples in bppr documentation.
Predict function for BayesPPR. Outputs the posterior predictive samples for the desired MCMC iterations.
## S3 method for class 'bppr_pca' predict(object, newdata, idx_use = NULL, n_cores = 1, par_type = "fork", ...)## S3 method for class 'bppr_pca' predict(object, newdata, idx_use = NULL, n_cores = 1, par_type = "fork", ...)
object |
a fitted model, output from the |
newdata |
a matrix of new input values at which to predict. The columns should correspond to the same variables used in the |
idx_use |
index of Markov samples to use when generating predictions. |
n_cores |
number of cores the user desired to utilize for parallel computation. |
par_type |
a character variable dicatating the type of parallel computation to be performed. Supported values include |
... |
further arguments passed to or from other methods. |
Bare-bones methods. Could be improved for efficiency.
An matrix where the first dimension corresponds to MCMC iterations indexed by idx_use, the second dimensions is the same number of rows as newdata, and the third corresponds to the dimension of the response.
bppr for model fitting.
# See examples in bppr documentation.# See examples in bppr documentation.
Print some of the details of a BPPR model.
## S3 method for class 'bppr' print(x, ...)## S3 method for class 'bppr' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
no return value
Summarize some of the details of a BPPR model.
## S3 method for class 'bppr' summary(object, ...)## S3 method for class 'bppr' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
no return value