cv.SBGAM {sparseGAM} | R Documentation |
Cross-Validation for Sparse Bayesian Generalized Additive Model
Description
This function implements K
-fold cross-validation for sparse Bayesian generalized additive models (GAMs) with the spike-and-slab group lasso (SSGL) penalty. The identity link function is used for Gaussian GAMs, the logit link is used for binomial GAMs, and the log link is used for Poisson, negative binomial, and gamma GAMs.
Usage
cv.SBGAM(y, X, df=6,
family=c("gaussian","binomial","poisson","negativebinomial","gamma"),
nb.size=1, gamma.shape=1, nfolds=5, nlambda0=20, lambda0, lambda1,
a, b, max.iter=100, tol = 1e-6, print.fold=TRUE)
Arguments
y |
|
X |
|
df |
number of B-spline basis functions to use in each basis expansion. Default is |
family |
exponential dispersion family. Allows for |
nb.size |
known size parameter |
gamma.shape |
known shape parameter |
nfolds |
number of folds |
nlambda0 |
number of spike hyperparameter |
lambda0 |
grid of |
lambda1 |
slab hyperparameter |
a |
shape hyperparameter for the |
b |
shape hyperparameter for the |
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 |
Value
The function returns a list containing the following components:
lambda0 |
|
cve |
|
cvse |
|
lambda0.min |
value of |
References
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.
Examples
## Generate data
set.seed(12345)
X = matrix(runif(30*3), nrow=30)
n = dim(X)[1]
y = 2.5*sin(pi*X[,1]) + rnorm(n)
## K-fold cross-validation for 4 degrees of freedom and 4 values of lambda0
## Note that if user does not specify lambda0, cv.SBGAM chooses a grid automatically.
cv.mod = cv.SBGAM(y, X, df=4, family="gaussian", lambda0=seq(from=25,to=5,by=-10))
## Plot CVE curve
plot(cv.mod$lambda0, cv.mod$cve, type="l", xlab="lambda0", ylab="CVE")
## lambda which minimizes cross-validation error
cv.mod$lambda0.min