hier_lasso: Two-stage hierarchical lasso

Description Usage Arguments Value Examples

View source: R/hier_lasso.R

Description

An implementation of the two-stage lasso studied in Hao et, al (2018).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
hier_lasso(
  x,
  y,
  lambda = NULL,
  nlam = 100,
  lam_choice = "min",
  lam_min_ratio = ifelse(nrow(x) < ncol(x), 0.01, 1e-04),
  nfold = 5,
  foldid = NULL,
  ...
)

Arguments

x

An n by p design matrix of main effects. Each row is an observation of p main effects.

y

A response vector of size n.

...

other arguments to be passed to the glmnet calls, such as alpha or penalty.factor

Value

An object of S3 class "cv.hier".

n

The sample size.

p

The number of main effects.

fit

The whole cv.glmnet fit object.

compact

A compact representation of the selected variables. compact has three columns, with the first two columns representing the indices of a selected variable (main effects with first index = 0), and the last column representing the estimate of coefficients.

Examples

1
2
3
4
5
6
7
set.seed(123)
n <- 100
p <- 200
# dense input
x <- matrix(rnorm(n * p), n, p)
y <- x[, 1] - 2 * x[, 2] + 3 * x[, 1] * x[, 3] - 4 * x[, 4] * x[, 5] + rnorm(n)
mod <- hier_lasso(x = x, y = y)

hugogogo/sprintr documentation built on Dec. 14, 2021, 6:07 p.m.