Description Usage Arguments Value References Examples
This function implements K-fold cross-validation for group-regularized regression in the exponential dispersion family with the spike-and-slab group lasso (SSGL) penalty. The identity link function is used for Gaussian regression, the logit link is used for binomial regression, and the log link is used for Poisson, negative binomial, and gamma regression.
1 2 3 4 |
y |
n \times 1 vector of responses. |
X |
n \times p design matrix, where the jth column of |
groups |
p-dimensional vector of group labels. The jth entry in |
family |
exponential dispersion family. Allows for |
nb.size |
known size parameter α in NB(α,μ_i) distribution for negative binomial responses. Default is |
gamma.shape |
known shape parameter ν in Gamma(μ_i,ν) distribution for gamma responses. Default is |
weights |
group-specific, nonnegative weights for the penalty. Default is to use the square roots of the group sizes. |
nfolds |
number of folds K to use in K-fold cross-validation. Default is |
nlambda0 |
number of spike hyperparameters L. Default is |
lambda0 |
grid of L spike hyperparameters λ_0. The user may specify either a scalar or a vector. If the user does not provide this, the program chooses the grid automatically. |
lambda1 |
slab hyperparameter λ_1 in the SSGL prior. Default is |
a |
shape hyperparameter for the Beta(a,b) prior on the mixing proportion in the SSGL prior. Default is |
b |
shape hyperparameter for the Beta(a,b) prior on the mixing proportion in the SSGL prior. Default is |
max.iter |
maximum number of iterations in the algorithm. Default is |
tol |
convergence threshold for algorithm. Default is |
print.fold |
Boolean variable for whether or not to print the current fold in the algorithm. Default is |
The function returns a list containing the following components:
lambda0 |
L \times 1 vector of spike hyperparameters |
cve |
L \times 1 vector of mean cross-validation error across all K folds. The kth entry in |
cvse |
L \times 1 vector of standard errors for cross-validation error across all K folds. The kth entry in |
lambda0.min |
value of |
Bai R. (2021). "Spike-and-slab group lasso for consistent Bayesian estimation and variable selection in non-Gaussian generalized additive models." arXiv pre-print arXiv:2007.07021.
Bai, R., Moran, G. E., Antonelli, J. L., Chen, Y., and Boland, M.R. (2021). "Spike-and-slab group lassos for grouped regression and sparse generalized additive models." Journal of the American Statistical Association, in press.
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 | ## Generate data
set.seed(12345)
X = matrix(runif(30*6), nrow=30)
n = dim(X)[1]
groups = c(1,1,1,2,2,3)
true.beta = c(-1.5,0.5,-1.5,0,0,0)
## Generate responses from Gaussian distribution
y = crossprod(t(X), true.beta) + rnorm(n)
## K-fold cross-validation for 3 choices of lambda0
## Note that if user does not specify lambda0, cv.SSGL chooses a grid automatically.
ssgl.mods = cv.SSGL(y, X, groups, family="gaussian", lambda0=seq(from=10,to=2,by=-4))
## Plot cross-validation curve
plot(ssgl.mods$lambda0, ssgl.mods$cve, type="l", xlab="lambda0", ylab="CVE")
## lambda which minimizes mean CVE
ssgl.mods$lambda0.min
## Example with Poisson regression
## Generate count responses
eta = crossprod(t(X), true.beta)
y = rpois(n,exp(eta))
## K-fold cross-validation with 4 choices of lambda0
## Note that if user does not specify lambda0, cv.SSGL chooses a grid automatically.
ssgl.poisson.mods = cv.SSGL(y, X, groups, family="poisson", lambda0=seq(from=8,to=2,by=-2))
## Plot cross-validation curve
plot(ssgl.poisson.mods$lambda0, ssgl.poisson.mods$cve, type="l", xlab="lambda0", ylab="CVE")
## lambda which minimizes mean CVE
ssgl.poisson.mods$lambda0.min
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.