Learn R Programming

⚠️There's a newer version (1.7.3) of this package.Take me there.

BAS: Bayesian Variable Selection and Model Averaging using Bayesian Adaptive Sampling

The BAS R package is designed to provide an easy to use package and fast code for implementing Bayesian Model Averaging and Model Selection in R using state of the art prior distributions for linear and generalized linear models. The prior distributions in BAS are based on Zellner’s g-prior or mixtures of g-priors for linear and generalized linear models. These have been shown to be consistent asymptotically for model selection and inference and have a number of computational advantages. BAS implements three main algorithms for sampling from the space of potential models: a deterministic algorithm for efficient enumeration, adaptive sampling without replacement algorithm for modest problems, and a MCMC algorithm that utilizes swapping to escape from local modes with standard Metropolis-Hastings proposals.

Installation

The stable version can be installed easily in the R console like any other package:

install.packages('BAS')

On the other hand, I welcome everyone to use the most recent version of the package with quick-fixes, new features and probably new bugs. It’s currently hosted on GitHub. To get the latest development version from GitHub, use the devtools package from CRAN and enter in R:

devtools::install_github('merliseclyde/BAS')

You can check out the current build status before installing.

Installing the package from source does require compilation of C and FORTRAN code as the library makes use of BLAS and LAPACK for efficient model fitting. See CRAN manuals for installing packages from source under different operating systems.

Usage

To begin load the package:

library(BAS)

The two main function in BAS are bas.lm and bas.glm for implementing Bayesian Model Averaging and Variable Selection using Zellner’s g-prior and mixtures of g priors. Both functions have a syntax similar to the lm and glm functions respectively. We illustrate using BAS on a simple example with the famous Hald data set using the Zellner-Siow Cauchy prior via

data(Hald)
hald.ZS = bas.lm(Y ~ ., data=Hald, prior="ZS-null", modelprior=uniform(), method="BAS")

BAS has summary, plot coef, predict and fitted functions like the lm/glm functions. Images of the model space highlighting which variable are important may be obtained via

image(hald.ZS)

Run demo("BAS.hald") or demo("BAS.USCrime") or see the package vignette for more examples and options such as using MCMC for model spaces that cannot be enumerated.

Generalized Linear Models

BAS now includes for support for binomial and binary regression, Poisson regression, and Gamma regression using Laplace approximations to obtain Bayes Factors used in calculating posterior probabilities of models or sampling of models. Here is an example using the Pima diabetes data set with the hyper-g/n prior:

library(MASS)
data(Pima.tr)
Pima.hgn = bas.glm(type ~ ., data=Pima.tr, method="BAS", family=binomial(),
                  betaprior=hyper.g.n(), modelprior=uniform())

Note, the syntax for specifying priors on the coefficients in bas.glm uses a function with arguments to specify the hyper-parameters, rather than a text string to specify the prior name and a separate argument for the hyper-parameters. bas.lm will be moving to this format sometime in the future.

Feature Requests and Issues

Feel free to report any issues or request features to be added via the github issues page.

For current documentation and vignettes see the BAS website

Support

This material is based upon work supported by the National Science Foundation under Grant DMS-1106891. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.

Copy Link

Version

Install

install.packages('BAS')

Monthly Downloads

1,535

Version

1.7.1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

December 6th, 2023

Functions in BAS (1.7.1)

force.heredity.bas

Post processing function to force constraints on interaction inclusion bas BMA objects
eplogprob.marg

eplogprob.marg - Compute approximate marginal inclusion probabilities from pvalues
cv.summary.bas

Summaries for Out of Sample Prediction
confint.pred.bas

Compute Credible (Bayesian Confidence) Intervals for a BAS predict object
g.prior

Families of G-Prior Distribution for Coefficients in BMA Models
bayesglm.fit

Fitting Generalized Linear Models and Bayesian marginal likelihood evaluation
intrinsic

Intrinsic Prior Distribution for Coefficients in BMA Models
image.bas

Images of models used in Bayesian model averaging
diagnostics

BAS MCMC diagnostic plot
eplogprob

eplogprob - Compute approximate marginal inclusion probabilities from pvalues
phi1

Compound Confluent hypergeometric function of two variables
plot.bas

Plot Diagnostics for an BAS Object
robust

Robust-Prior Distribution for Coefficients in BMA Model
list2matrix.bas

Coerce a BAS list object into a matrix.
fitted.bas

Fitted values for a BAS BMA objects
tCCH

Generalized tCCH g-Prior Distribution for Coefficients in BMA Models
tr.beta.binomial

Truncated Beta-Binomial Prior Distribution for Models
list2matrix.which

Coerce a BAS list object into a matrix.
protein

Protein Activity Data
hypergeometric1F1

Confluent hypergeometric1F1 function
predict.bas

Prediction Method for an object of class BAS
hypergeometric2F1

Gaussian hypergeometric2F1 function
predict.basglm

Prediction Method for an Object of Class basglm
testBF.prior

Test based Bayes Factors for BMA Models
variable.names.pred.bas

Extract the variable names for a model from a BAS prediction object
print.bas

Print a Summary of Bayesian Model Averaging objects from BAS
hyper.g

Hyper-g-Prior Distribution for Coefficients in BMA Models
tr.poisson

Truncated Poisson Prior Distribution for Models
uniform

Uniform Prior Distribution for Models
tr.power.prior

Truncated Power Prior Distribution for Models
hyper.g.n

Generalized hyper-g/n Prior Distribution for g for mixtures of g-priors on Coefficients in BMA Models
trCCH

Truncated Compound Confluent Hypergeometric function
which.matrix

Coerce a BAS list object of models into a matrix.
update.bas

Update BAS object using a new prior
plot.coef.bas

Plots the posterior distributions of coefficients derived from Bayesian model averaging
summary.bas

Summaries of Bayesian Model Averaging objects from BAS
plot.confint.bas

Plot Bayesian Confidence Intervals
bas.glm

Bayesian Adaptive Sampling Without Replacement for Variable Selection in Generalized Linear Models
EB.local

Empirical Bayes Prior Distribution for Coefficients in BMA Model
CCH

Generalized g-Prior Distribution for Coefficients in BMA Models
IC.prior

Information Criterion Families of Prior Distribution for Coefficients in BMA Models
Bernoulli

Independent Bernoulli Prior Distribution for Models
Hald

Hald Data
Bernoulli.heredity

Independent Bernoulli prior on models that with constraints for model hierarchy induced by interactions
Bayes.outlier

Bayesian Outlier Detection
Jeffreys

Jeffreys Prior Distribution for $g$ for Mixtures of g-Priors for Coefficients in BMA Models
climate

Climate Data
beta.binomial

Beta-Binomial Prior Distribution for Models
TG

Generalized g-Prior Distribution for Coefficients in BMA Models
beta.prime

Beta-Prime Prior Distribution for Coefficients in BMA Model
EB.global

Find the global Empirical Bayes estimates for BMA
bodyfat

Bodyfat Data
bas.lm

Bayesian Adaptive Sampling for Bayesian Model Averaging and Variable Selection in Linear Models
confint.coef.bas

Compute Credible Intervals for BAS regression coefficients from BAS objects
coef.bas

Coefficients of a Bayesian Model Average object
BAS

BAS: Bayesian Model Averaging using Bayesian Adaptive Sampling