lambda_sequence: Calculate Sequence of Tuning Parameters

Description Usage Arguments Details Value Author(s) References Examples

View source: R/utility_functions.R

Description

Function to calculate the sequence of tuning parameters based on the design matrix x and the response variable y. This is used in the shim_once function to calculate the tuning parameters applied to the main effects

Usage

1
2
lambda_sequence(x, y, weights = NULL, lambda.factor = ifelse(nobs < nvars,
  0.01, 1e-06), nlambda = 100, scale_x = F, center_y = F)

Arguments

x

Design matrix of dimension n x q, where n is the number of subjects and q is the total number of variables; each row is an observation vector. This must include all main effects and interactions as well, with column names corresponding to the names of the main effects (e.g. x1, x2, E) and their interactions (e.g. x1:E, x2:E). All columns should be scaled to have mean 0 and variance 1; this is done internally by the shim function.

y

response variable (matrix form) of dimension n x 1

weights

Separate penalty factors can be applied to each coefficient. This is a number that multiplies lambda to allow differential shrinkage, and can be used to apply adaptive LASSO. Can be 0 for some variables, which implies no shrinkage, and that variable is always included in the model. Default is 1 for all variables (and implicitly infinity for variables listed in exclude). Note: the penalty factors are internally rescaled to sum to nvars, and the lambda sequence will reflect this change.

lambda.factor

The factor for getting the minimal lambda in lambda sequence, where min(lambda) = lambda.factor * max(lambda). max(lambda) is the smallest value of lambda for which all coefficients are zero. The default depends on the relationship between N (the number of rows in the matrix of predictors) and p (the number of predictors). If N > p, the default is 1e-6, close to zero. If N < p, the default is 0.01. A very small value of lambda.factor will lead to a saturated fit.

nlambda

the number of lambda values - default is 100.

scale_x

should the columns of x be scaled - default is FALSE

center_y

should y be mean centered - default is FALSE

Details

The maximum lambda is calculated using the following inequality:

(N*w_j)^-1 | ∑ x_ij y_i | ≤ λ_max

The minimum lambda is given by lambda.factor*lambda_max. The sequence of nlambda values are decreasing from lambda_max to lambda_min on the log scale.

The penalty factors are internally rescaled to sum to the number of predictor variables in glmnet. Therefore, to get the correct sequence of lambdas when there are weights, this function first rescales the weights and then calclated the sequence of lambdas.

This formula is taken from section 2.5 of the glmnet paper in the Journal of Statistical Software (see references for details)

Value

numeric vector of length q

Author(s)

Sahir Bhatnagar

Maintainer: Sahir Bhatnagar sahir.bhatnagar@mail.mcgill.ca

References

Friedman, J., Hastie, T. and Tibshirani, R. (2008) Regularization Paths for Generalized Linear Models via Coordinate Descent, http://www.stanford.edu/~hastie/Papers/glmnet.pdf Journal of Statistical Software, Vol. 33(1), 1-22 Feb 2010 http://www.jstatsoft.org/v33/i01/

Yang, Y., & Zou, H. (2015). A fast unified algorithm for solving group-lasso penalize learning problems. Statistics and Computing, 25(6), 1129-1141. http://www.math.mcgill.ca/yyang/resources/papers/gglasso.pdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# number of observations
n <- 100

# number of predictors
p <- 5

# environment variable
e <- sample(c(0,1), n, replace = T)

# main effects
x <- cbind(matrix(rnorm(n*p), ncol = p), e)

# need to label columns
dimnames(x)[[2]] <- c(paste0("x",1:p), "e")

# design matrix without intercept
X <- model.matrix(~(x1+x2+x3+x4+x5)*e-1, data = as.data.frame(x))

# response
Y <- X %*% rbinom(ncol(X), 1, 0.2) + 3*rnorm(n)

lambda_sequence(X,Y)

sahirbhatnagar/shim documentation built on May 29, 2019, 12:59 p.m.