Description Usage Arguments Value Examples
View source: R/BayesBridgeSMU.R
Bayesian Bridge Regression
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | BayesBridgeSMU(
x,
y,
alpha = 0.5,
max.steps = 20000,
n.burn = 10000,
n.thin = 1,
eps = 1e-06,
r = 1,
delta = 0.1,
posterior.summary.beta = "mean",
posterior.summary.lambda = "mean",
posterior.summary.alpha = "mean",
beta.ci.level = 0.95,
lambda.ci.level = 0.95,
alpha.ci.level = 0.95,
seed = 1234
)
|
x |
A numeric matrix with standardized predictors in columns and samples in rows. |
y |
A mean-centered continuous response variable with matched sample rows with x. |
alpha |
Concavity parameter of the bridge penalty (the exponent to which the L1 norm of the coefficients are raised). Default is 0.5, the square root. Must be in (0,1]. |
max.steps |
Number of MCMC iterations. Default is 20000. |
n.burn |
Number of burn-in iterations. Default is 10000. |
n.thin |
Lag at which thinning should be done. Default is 1 (no thinning). |
eps |
Small tolerance parameter to be used when inverting X, if it is less than full rank. Default is 1e-06. |
r |
Shape hyperparameter for the Gamma prior on lambda. Default is 1. |
delta |
Rate hyperparameter for the Gamma prior on lambda. Default is 0.1. |
posterior.summary.beta |
Posterior summary measure for beta (mean, median, or mode). Default is 'mean'. |
posterior.summary.lambda |
Posterior summary measure for lambda (mean or median). Default is 'mean'. |
beta.ci.level |
Credible interval level for beta. Default is 0.95 (95%). |
lambda.ci.level |
Credible interval level for lambda. Default is 0.95 (95%). |
seed |
Seed value for reproducibility. Default is 1234. |
A list containing the following components is returned:
time |
Computational time in minutes. |
beta |
Posterior mean or median estimates of beta. |
lowerbeta |
Lower limit credible interval of beta. |
upperbeta |
Upper limit credible interval of beta. |
lambda |
Posterior estimate of lambda. |
lambdaci |
Posterior credible interval of lambda. |
beta.post |
Post-burn-in posterior samples of beta. |
sigma2.post |
Post-burn-in posterior samples of sigma2. |
lambda.post |
Post-burn-in posterior samples of lambda |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ## Not run:
#########################
# Load Diabetes dataset #
#########################
library(ElemStatLearn)
prost<-prostate
###########################################
# Scale data and prepare train/test split #
###########################################
prost.std <- data.frame(cbind(scale(prost[,1:8]),prost$lpsa))
names(prost.std)[9] <- 'lpsa'
data.train <- prost.std[prost$train,]
data.test <- prost.std[!prost$train,]
##################################
# Extract standardized variables #
##################################
y.train = data.train$lpsa - mean(data.train$lpsa)
y.test <- data.test$lpsa - mean(data.test$lpsa)
x.train = scale(as.matrix(data.train[,1:8], ncol=8))
x.test = scale(as.matrix(data.test[,1:8], ncol=8))
##############################################
# Bayesian Bridge with alpha = 0.5 using SMU #
##############################################
library(UBR)
BayesBridge<- BayesBridgeSMU(as.data.frame(x.train), y.train, alpha = 0.5)
y.pred.BayesBridge<-x.test%*%BayesBridge$beta
mean((y.pred.BayesBridge - y.test)^2) # Performance on test data
#############################################################
# Bayesian Bridge with alpha = 1 using SMU (Bayesian LASSO) #
#############################################################
BayesLASSO<- BayesBridgeSMU(as.data.frame(x.train), y.train, alpha = 1)
y.pred.BayesLASSO<-x.test%*%BayesLASSO$beta
mean((y.pred.BayesLASSO - y.test)^2) # Performance on test data
########################################################
# Visualization of Posterior Samples (Bayesian Bridge) #
########################################################
##############
# Trace Plot #
##############
library(coda)
plot(mcmc(BayesBridge$beta.post),density=FALSE,smooth=TRUE)
#############
# Histogram #
#############
library(psych)
multi.hist(BayesBridge$beta.post,density=TRUE,main="")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.