Description Usage Arguments Value References Examples
This function implements Kfold crossvalidation for sparse Bayesian generalized additive models (GAMs) with the spikeandslab 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.
1 2 3 4 
y 
n \times 1 vector of responses. 
X 
n \times p design matrix, where the jth column of 
df 
number of Bspline basis functions to use in each basis expansion. Default is 
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 
nfolds 
number of folds K to use in Kfold crossvalidation. Default is 
nlambda0 
number of spike hyperparameter 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 crossvalidation error across all K folds. The kth entry in 
cvse 
L \times 1 vector of standard errors for crossvalidation error across all K folds. The kth entry in 
lambda0.min 
value of 
Bai R. (2021). "Spikeandslab group lasso for consistent Bayesian estimation and variable selection in nonGaussian generalized additive models." arXiv preprint arXiv:2007.07021.
Bai, R., Moran, G. E., Antonelli, J. L., Chen, Y., and Boland, M.R. (2021). "Spikeandslab 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  ## 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)
## Kfold crossvalidation 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 crossvalidation error
cv.mod$lambda0.min

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.