fwelnet: Fit feature-weighted elastic net

Description Usage Arguments Details Value Examples

View source: R/fwelnet.R

Description

Fit a model with feature-weighted elastic net for a path of lambda values. Fits linear and logistic regression models.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
fwelnet(
  x,
  y,
  z,
  lambda = NULL,
  family = c("gaussian", "binomial"),
  alpha = 1,
  standardize = TRUE,
  max_iter = 1,
  ave_mode = 1,
  thresh_mode = 1,
  t = 1,
  a = 0.5,
  thresh = 1e-04,
  verbose = FALSE
)

Arguments

x

Input matrix, of dimension nobs x nvars; each row is an observation vector.

y

Response variable. Quantitative for family = "gaussian". For family="binomial", should be a numeric vector consisting of 0s and 1s.

z

Feature of features matrix, with dimension nvars x nfeaturevars.

lambda

A user supplied lambda sequence. Typical usage is to have the program compute its own lambda sequence; supplying a value of lambda overrides this.

family

Response type. Either "gaussian" (default) for linear regression or "binomial" for logistic regression.

alpha

The elastic net mixing hyperparameter, a real value number between 0 and 1 (inclusive). Default value is 1.

standardize

If TRUE, the columns of the input matrix are standardized before the algorithm is run. Default is TRUE.

max_iter

The number of iterations for the optimization. Default is 1.

ave_mode

If equal to 1 (default), the gradient descent direction for theta is the mean gradient across the lambda values. If equal to 2, it is the component-wise median gradient across the lambda values.

thresh_mode

If equal to 1 (default), backtracking line search for theta is done so that the mean objective function (across lambda values) decreases. If equal to 2, it is done so that the median objective function decreases.

t

The initial step size for theta backtracking line search (default value is 1).

a

The factor by which step size is decreased in theta backtracking line search (default value is 0.5).

thresh

If the mean/median objective function does not decrease by at least this factor, we terminate the optimization early. Default is 1e-4.

verbose

If TRUE, prints information to console as model is being fit. Default is FALSE.

Details

fwelnet always mean centers the columns of the x matrix. If standardize=TRUE, fwelnet will also scale the columns to have standard deviation 1. In all cases, the beta coefficients returned are for the original x values (i.e. uncentered and unscaled).

Value

An object of class "fwelnet".

beta

A p x length(lambda) matrix of coefficients.

theta

Theta value, a nfeaturevars x 1 matrix.

a0

Intercept sequence of length length(lambda).

lambda

The actual sequence of lambda values used.

nzero

The number of non-zero coefficients for each value of lambda.

family

Response type.

call

The call that produced this object.

obj

A max_iter + 1 by length(lambda) matrix of objective function values. (Number of rows could be fewer if the optimization stopped early.)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(1)
n <- 100; p <- 20
x <- matrix(rnorm(n * p), n, p)
beta <- matrix(c(rep(2, 5), rep(0, 15)), ncol = 1)
y <- x %*% beta + rnorm(n)
z <- cbind(1, abs(beta) + rnorm(p))

fwelnet(x, y, z)
fwelnet(x, y, z, ave_mode = 2)
fwelnet(x, y, z, ave_mode = 2, thresh_mode = 2)

kjytay/fwelnet documentation built on June 9, 2020, 1:39 p.m.