glmnet_filter {nestedcv}R Documentation

glmnet filter

Description

Filter using sparsity of elastic net regression using glmnet to calculate variable importance.

Usage

glmnet_filter(
  y,
  x,
  family = NULL,
  force_vars = NULL,
  nfilter = NULL,
  method = c("mean", "nonzero"),
  type = c("index", "names", "full"),
  ...
)

Arguments

y

Response vector

x

Matrix of predictors

family

Either a character string representing one of the built-in families, or else a glm() family object. See glmnet::glmnet(). If not specified, the function tries to set this automatically to one of either "gaussian", "binomial" or "multinomial".

force_vars

Vector of column names x which have no shrinkage and are always included in the model.

nfilter

Number of predictors to return

method

String indicating method of determining variable importance. "mean" (the default) uses the mean absolute coefficients across the range of lambdas; "nonzero" counts the number of times variables are retained in the model across all values of lambda.

type

Type of vector returned. Default "index" returns indices, "names" returns predictor names, "full" returns full output.

...

Other arguments passed to glmnet::glmnet

Details

The glmnet elastic net mixing parameter alpha can be varied to include a larger number of predictors. Default alpha = 1 is pure LASSO, resulting in greatest sparsity, while alpha = 0 is pure ridge regression, retaining all predictors in the regression model. Note, the family argument is commonly needed, see glmnet::glmnet.

Value

Integer vector of indices of filtered parameters (type = "index") or character vector of names (type = "names") of filtered parameters. If type is "full" a named vector of variable importance is returned.

See Also

glmnet::glmnet


[Package nestedcv version 0.7.9 Index]