asgl: Fit a GLM with Adaptive Sparse Group Lasso Penalty

Description Usage Arguments Value Examples

View source: R/asgl.R

Description

Fit a generalized linear model via penalized maximum likelihood. The regularization path is computed for the adaptive sparse group lasso penalty along a sequence of tuning parameter values. Supports linear and logistic regression.

Usage

1
2
3
4
asgl(x, y, index, family = c("gaussian", "binomial"), offset = NULL,
  alpha = 0.95, lambda = NULL, lambda_min = 0.1, nlambda = 20,
  maxit = 1000, thresh = 0.001, gamma = 0.8, step = 1,
  standardize = FALSE, grp_weights = NULL, ind_weights = NULL)

Arguments

x

Input matrix of dimensions n by p.

y

Response vector of length n. For linear models (family = "gaussian"), a numeric vector; for logistic models (family = "binomial"), a categorical factor with two levels.

index

A vector of length p defining group membership for each covariate.

family

Response type. One of "gaussian" or "binomial".

offset

Optional. A vector of length n to be included in the linear predictor

alpha

Penalty mixing parameter. The penalty reduces to the adaptive group lasso if alpha = 0 and to the adaptive lasso if alpha = 0.

lambda

Optional. A vector of user-specified penalty tuning parameter values at which to fit model. If NULL, the sequence is chosen automatically (recommended).

lambda_min

Smallest tuning parameter value, as a fraction of the largest parameter value in the sequence (the smallest value for which all coefficients are zero).

nlambda

The number of tuning parameter values in the sequence.

maxit

Maximum number of iterations until convergence

thresh

Convergence threshold for change in model coefficient values.

gamma

Backtracking parameter for use in gradient descent step

step

Initial gradient descent step size.

standardize

If TRUE, variables are standardized prior to model fitting.

grp_weights

A vector of weights for each group of coefficients, the same length as index.

ind_weights

A vector of weights for each indiviual coefficient, of length p.

Value

An object of class "asgl"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# linear regression
n <- 500; p <- 20; groupsize <- 5
index <- ceiling(1:p / groupsize)
beta <- (-2:2)
x <- matrix(rnorm(n * p), ncol = p, nrow = n)
y <- as.vector(x[,1:5] %*% beta + 0.1 * rnorm(n))
asgl(x, y, index, family = "gaussian")

# logistic regression
eta <- x[, 1:5] %*% beta
prob <- exp(eta) / (1 + exp(eta))
y <- rbinom(n, 1, prob)
asgl(x, y, index, family = "binomial")

# adaptive weights
coefs <- glm.fit(x, y, family = binomial())$coefficients
ind_weights <- 1 / abs(coefs)
grp_weights <- numeric(length(unique(index)))
for (i in unique(index)) {
  grp_weights[i] <-  1 / sqrt(sum(coefs[which(index == i)]^2))
}
asgl(x, y, index, family = "binomial",
     grp_weights = grp_weights, ind_weights = ind_weights)

jeffdaniel/asgl documentation built on Nov. 4, 2019, 2:37 p.m.