Overview

The BayesPen package implements variable and confounder selection via penalized credible regrions. The methods are detailed in the following papers

Bondell HD, Reich BJ. 2012. Consistent high-dimensional Bayesian variable selection via penalized credible regions. J. Am. Stat. Assoc. 107: 1610–1624.

Wilson A, Reich BJ. 2014. Confounder selection via penalized credible regions. Biometrics 70: 852–861.

The citation for this package is

Ander Wilson, Howard D. Bondell and Brian J. Reich (2015). BayesPen: Bayesian Penalized Credible Regions. R package version 1.2.

Installation

The BayesPen package can be installed using devtools.

library(devtools)
install_github(repo="BayesPen", username="AnderWilson")
library(BayesPen)

An Example

First load the R package.

library(BayesPen)
## Loading required package: lars
## Loaded lars 1.2
## 
## Loading required package: MCMCpack
## Loading required package: coda
## Loading required package: lattice
## Loading required package: MASS
## ##
## ## Markov Chain Monte Carlo Package (MCMCpack)
## ## Copyright (C) 2003-2015 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
## ##
## ## Support provided by the U.S. National Science Foundation
## ## (Grants SES-0350646 and SES-0350613)
## ##
## Loading required package: SuppDists

Variable Selection via Penalized Credible Regions

Simulate data.

set.seed(1234)
dat <- SimExample(500,model="BR1")
X <- dat$X
y <- dat$y

Fit the full model assuming flat priors on beta

fit1 <- lm(y~X-1)
betahat <- coef(fit1)
cov <- vcov(fit1)

Find solution path

fit.BayesPen <- BayesPen(beta=betahat, beta_cov=cov)
## [1] "============================================================"
## [1] "Joint not specified."
## [1] "Joint credible sets will be used for variable selection."
## [1] "============================================================"

Refit the model.

refit <- BayesPen.refit(y,X,fit.BayesPen)
## [1] "============================================================"
## [1] "max.refit missing."
## [1] "max.refit will be set to 50."
## [1] "============================================================"

Plot the solution path.

BayesPen.plot(refit)

Confounder Selection via Penalized Credible Regions

set.seed(1234)
dat <- SimExample(500,model="WPD2")
X <- dat$X
U <- dat$U
W <- cbind(X,U)
y <- dat$y

Fit the full outcome model assuming flat priors on beta.

fit1 <- lm(y~W-1)
betahat <- coef(fit1)
cov <- vcov(fit1)

Fit the full exposure model assuming flat priors on beta.

fit2 <- lm(X~U-1)
gammahat <- coef(fit2)

Find solution path.

fit.BayesPen <- BayesPen(beta=betahat, beta_cov=cov, confounder.weights=c(0,gammahat), force=1)

Refit the outcome model.

refit <- BayesPen.refit(y,W,fit.BayesPen)
## [1] "============================================================"
## [1] "max.refit missing."
## [1] "max.refit will be set to 58."
## [1] "============================================================"

Plot the solution path.

BayesPen.plot(refit)