Description Usage Arguments Details Value See Also Examples
Inference for Bayesian lasso regression models by Gibbs sampling from the Bayesian posterior distribution.
1 2 3 |
X |
|
y |
vector of output responses |
T |
total number of MCMC samples to be collected |
beta |
initial setting of the regression coefficients. |
lambda2 |
square of the initial lasso penalty parameter. |
s2 |
initial variance parameter. |
rd |
|
ab |
|
icept |
if |
normalize |
if |
device |
If no external pointer is provided to function, we can provide the ID of the device to use. |
parameters |
a 9 dimensional vector of parameters to tune the GPU implementation. |
The Bayesian lasso model, hyperprior for the lasso parameter, and Gibbs Sampling algorithm implemented by this function are identical to that is described in detail in Park & Casella (2008). The GPU implementation is derived from the CPU implementation blasso from package monomvn.
lasso
returns an object of class "lasso"
, which is a
list
containing a copy of all of the input arguments as well as
of the components listed below.
mu |
a vector of |
beta |
a |
s2 |
a vector of |
lambda2 |
a vector of |
tau2i |
a |
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 | set.seed(0)
n_samples <- 500
n_features <- 40
X <- matrix(rnorm(n_features * n_samples), nrow = n_samples)
y <- 2 * X[,1] - 3 * X[,2] + rnorm(n_samples) # only features 1 & 2 are relevant
X_train <- X[1:400,]
y_train <- y[1:400]
X_test <- X[401:500,]
y_test <- y[401:500]
# START ------------------------------------------------------------------------
# first, standardize data !!!
X_train <- scale(X_train)
tmp00 <- bayesCL::lasso(X = X_train,
y = y_train,
T = 500, # number of Gibbs sampling iterations
icept = T,
device=0 ) # use constant term (intercept), we do
#scale test data based on train data means and scales!!
X_test <- scale(X_test,
center = attr(X_train, "scaled:center"),
scale = attr(X_train, "scaled:scale"))
p_train1 <- colMeans(tmp00$beta %*% t(X_train))
p_test1 <- colMeans(tmp00$beta %*% t(X_test))
plot(y_train, p_train1, col = "red", xlab = "actual", ylab = "predicted")
points(y_test, p_test1, col = "green")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.