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

n \times 1 vector of responses.

X

n \times p design matrix, where the jth column of X corresponds to the jth overall covariate.

df

number of B-spline basis functions to use in each basis expansion. Default is df=6, but the user may specify degrees of freedom as any integer greater than or equal to 3.

family

exponential dispersion family. Allows for "gaussian", "binomial", "poisson", "negativebinomial", and "gamma". Note that for "negativebinomial", the size parameter must be specified, while for "gamma", the shape parameter must be specified.

nb.size

known size parameter \alpha in NB(\alpha,\mu_i) distribution for negative binomial responses. Default is nb.size=1. Ignored if family is not "negativebinomial".

gamma.shape

known shape parameter \nu in Gamma(\mu_i,\nu) distribution for gamma responses. Default is gamma.shape=1. Ignored if family is not "gamma".

nfolds

number of folds K to use in K-fold cross-validation. Default is nfolds=5.

nlambda0

number of spike hyperparameter L. Default is nlambda0=20.

lambda0

grid of L spike hyperparameters \lambda_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 \lambda_1 in the SSGL prior. Default is lambda1=1.

a

shape hyperparameter for the Beta(a,b) prior on the mixing proportion in the SSGL prior. Default is a=1.

b

shape hyperparameter for the Beta(a,b) prior on the mixing proportion in the SSGL prior. Default is b=dim(X)[2].

max.iter

maximum number of iterations in the algorithm. Default is max.iter=100.

tol

convergence threshold for algorithm. Default is tol=1e-6.

print.fold

Boolean variable for whether or not to print the current fold in the algorithm. Default is print.fold=TRUE.

Value

The function returns a list containing the following components:

lambda0

L \times 1 vector of spike hyperparameters lambda0 used to fit the model. lambda0 is displayed in descending order.

cve

L \times 1 vector of mean cross-validation error across all K folds. The kth entry in cve corresponds to the kth regularization parameter in lambda0.

cvse

L \times 1 vector of standard errors for cross-validation error across all K folds. The kth entry in cvse corresponds to the kth regularization parameter in lambda0.

lambda0.min

value of lambda0 that minimizes mean cross-validation error cve.

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

[Package sparseGAM version 1.0 Index]