bess {BeSS} | R Documentation |
Best subset selection for generalized linear model and Cox's proportional model.
bess(x, y, family = c("gaussian", "binomial", "cox"), method = "gsection", s.min = 1, s.max, s.list, K.max = 20, max.steps = 20, glm.max = 20, cox.max = 20, eta = 0.2, factor = NULL, epsilon = 1e-4, weights = rep(1,nrow(x)), ic.type = c("GIC", "AIC", "BIC"), warm.start = TRUE, normalize = TRUE)
x |
Input matrix,of dimension n x p; each row is an observation vector. |
y |
Response variable,of length n. For family="binomial" should be a factor with two levels. For family="cox", y should be a two-column matrix with columns named 'time' and 'status'. |
family |
One of the GLM or Cox models. Either "gaussian", "binomial", or "cox", depending on the response. |
method |
Methods tobe used to select the optimal model size. For method = " |
s.min |
The minimum value of model sizes. Only used for method = " |
s.max |
The maximum value of model sizes. Only used for method = " |
s.list |
A list of sequential value representing the model sizes. Only used for method = " |
K.max |
The maximum iterations used for method = " |
max.steps |
The maximum number of iterations in |
glm.max |
The maximum number of iterations for solving the maximum likelihood problem on the active set at each step in the primal dual active set algorithm.Only used in the logistic regression for family="binomial". Default is 20. |
cox.max |
The maximum number of iterations for solving the maximum partial likelihood problem on the active set at each step in the primal dual active set algorithm. Only used in Cox's model for family="cox". Default is 20. |
eta |
The step size of Newton Raphson-algorithm in Cox model. Default is 0.2. |
factor |
Which variable to be factored. Should be NULL or a numeric vector. |
epsilon |
The tolerance for an early stoping rule in the method "sequential". The early stopping rule is defined as \|Y-Xβ\|/n ≤q ε. |
weights |
Observation weights. Default is 1 for each observation |
ic.type |
Types of best model returned. |
warm.start |
Logical flag for using warm-start. It will sometimes be more efficient. Default is warm.start=TRUE. |
normalize |
Logical flag for x variable normalization, prior to fitting the model sequence.The coefficients are always returned on the original scale. Default is normalize=TRUE. |
The best subset selection problem with model size s is
\min_β -2 logL(β) \;\;{\rm s.t.}\;\; \|β\|_0 ≤q s.
In the GLM case, logL(β) is the log-likelihood function; In the Cox model, logL(β) is the log parital likelihood function.
For each candiate model size, the best subset selection problem is solved by the primal dual active set(PDAS) algorithm, see Wen et al(2017) for details. This algorithm utilizes an active set updating strategy via primal and dual vairables and fits the sub-model by exploiting the fact that their support set are non-overlap and complementary. For the case of method = "sequential", we run the PDAS algorithm for a list of sequential model sizes and use the estimate from last iteration as a warm start. For the case of method = "gsection
", a golden section search technique is adopted to efficiently determine the optimal model size.
A list with class attribute 'bess' and named components:
family |
Types of the model: " |
beta |
The best fitting coefficients of size s=0,1,…,p with the smallest loss function. |
bestmodel |
The best fitted model, the class of which is "lm", "glm" or "coxph" |
deviance |
The value of -2\times logL. |
nulldeviance |
The value of -2\times logL for null model. |
AIC |
The value of -2\times logL + 2 \|β\|_0. |
BIC |
The value of -2\times logL+ log(n) \|β\|_0. |
GIC |
The value of -2\times logL+ log(p)log(log(n)) \|β\|_0. |
factor |
Which variable to be factored. Should be NULL or a numeric vector. |
Canhong Wen, Aijun Zhang, Shijie Quan, and Xueqin Wang.
Wen, C., Zhang, A., Quan, S. and Wang, X. (2017). BeSS: an R package for best subset selection in linear, logistic and CoxPH models. arXiv: 1709.06254.
bess.one
, plot.bess
,
predict.bess
.
#--------------linear model--------------# # Generate simulated data n <- 500 p <- 20 K <-10 sigma <- 1 rho <- 0.2 data <- gen.data(n, p, family = "gaussian", K, rho, sigma) # Best subset selection fit1 <- bess(data$x, data$y, family = "gaussian") print(fit1) #coef(fit1, sparse=TRUE) # The estimated coefficients bestmodel <- fit1$bestmodel #summary(bestmodel) # Plot solution path and the loss function plot(fit1, type = "both", breaks = TRUE) ## Not run: #--------------logistic model--------------# # Generate simulated data data <- gen.data(n, p, family="binomial", 5, rho, sigma) # Best subset selection fit2 <- bess(data$x, data$y, s.list = 1:10, method = "sequential", family = "binomial", epsilon = 0) print(fit2) #coef(fit2, sparse = TRUE) bestmodel <- fit2$bestmodel #summary(bestmodel) # Plot solution path and the loss function plot(fit2, type = "both", breaks = TRUE, K = 5) #--------------cox model--------------# # Generate simulated data data <- gen.data(n, p, 5, rho, sigma, c = 10, family = "cox", scal = 10) # Best subset selection fit3 <- bess(data$x, data$y, s.list = 1:10, method = "sequential", family = "cox") print(fit3) #coef(fit3, sparse = TRUE) bestmodel <- fit3$bestmodel #summary(bestmodel) # Plot solution path and the loss function plot(fit3, type = "both", breaks = TRUE, K = 5) #----------------------High dimensional linear models--------------------# p <- 1000 data <- gen.data(n, p, family = "gaussian", K, rho, sigma) # Best subset selection fit <- bess(data$x, data$y, method="sequential", family = "gaussian", epsilon = 1e-12) # Plot solution path plot(fit, type = "both", breaks = TRUE, K = 10) data("prostate") x = prostate[,-9] y = prostate[,9] fit.group = bess(x, y, s.list = 1:ncol(x), factor = c("gleason")) #---------------SAheart---------------# data("SAheart") y = SAheart[,5] x = SAheart[,-5] x$ldl[x$ldl<5] = 1 x$ldl[x$ldl>=5&x$ldl<10] = 2 x$ldl[x$ldl>=10] = 3 fit.group = bess(x, y, s.list = 1:ncol(x), factor = c("ldl"), family = "binomial") ## End(Not run)