Title: | Learning Interactions via Hierarchical Group-Lasso Regularization |
---|---|
Description: | Group-Lasso INTERaction-NET. Fits linear pairwise-interaction models that satisfy strong hierarchy: if an interaction coefficient is estimated to be nonzero, then its two associated main effects also have nonzero estimated coefficients. Accommodates categorical variables (factors) with arbitrary numbers of levels, continuous variables, and combinations thereof. Implements the machinery described in the paper "Learning interactions via hierarchical group-lasso regularization" (JCGS 2015, Volume 24, Issue 3). Michael Lim & Trevor Hastie (2015) <DOI:10.1080/10618600.2014.938812>. |
Authors: | Michael Lim, Trevor Hastie |
Maintainer: | Michael Lim <[email protected]> |
License: | GPL-2 |
Version: | 1.0.12 |
Built: | 2024-11-01 11:30:48 UTC |
Source: | https://github.com/cran/glinternet |
Returns the actual main effect and interaction coefficients that satisfy the sum constraints in a linear interaction model. See the paper below for details.
## S3 method for class 'glinternet' coef(object, lambdaIndex = NULL, ...)
## S3 method for class 'glinternet' coef(object, lambdaIndex = NULL, ...)
object |
Fitted |
lambdaIndex |
Index of |
... |
Not used. |
Returns the actual main effect and interaction coefficients. These satisfy the sum constraints in the original linear interaction model.
A list of length lambda
if lambdaIndex
is not
provided. Otherwise, of length lambdaIndex
. Each component (for
each lambda) is
itself a list, with components
mainEffects |
A list with components |
mainEffectsCoef |
List of coefficients for the main effects in
|
interactions |
List of interactions, with components
|
interactionsCoef |
List of interaction coefficients for
|
Michael Lim and Trevor Hastie
Maintainer: Michael Lim [email protected]
"Learning interactions via hierarchical group-lasso regularization"
glinternet.cv
, predict.glinternet
,
predict.glinternet.cv
, plot.glinternet.cv
, glinternet
Y = rnorm(100) X = matrix(rnorm(100*10), nrow=100) numLevels = rep(1, 10) fit = glinternet(X, Y, numLevels) coeffs = coef(fit)
Y = rnorm(100) X = matrix(rnorm(100*10), nrow=100) numLevels = rep(1, 10) fit = glinternet(X, Y, numLevels) coeffs = coef(fit)
The regularization path is computed along a grid of values for the regularization parameter lambda. Can deal with categorical variables with arbitrary numbers of levels, continuous variables, and combinations of the two. Accommodates squared error loss and logistic loss.
The multicore option requires that the package be compiled with OpenMP support. Examples of compilers that qualify include gcc (>= 4.2) and icc. We also recommend a higher level of optimization, such as -O3 in gcc.
glinternet(X, Y, numLevels, lambda = NULL, nLambda = 50, lambdaMinRatio = 0.01, interactionCandidates=NULL, interactionPairs=NULL, screenLimit = NULL, numToFind = NULL, family = c("gaussian","binomial"), tol = 1e-05, maxIter=5000, verbose=FALSE, numCores = 1)
glinternet(X, Y, numLevels, lambda = NULL, nLambda = 50, lambdaMinRatio = 0.01, interactionCandidates=NULL, interactionPairs=NULL, screenLimit = NULL, numToFind = NULL, family = c("gaussian","binomial"), tol = 1e-05, maxIter=5000, verbose=FALSE, numCores = 1)
X |
Matrix of features or predictors with dimension nobs x nvars; each row is an observation vector. Categorical variables must be coded as 0, 1, 2, ... |
Y |
Target variable of length nobs. Continuous for squared error loss, 0-1 for logistic loss. |
numLevels |
Number of levels for each variable, of length nvars. Set to 1 for continuous variables. |
lambda |
A user supplied |
nLambda |
The number of |
lambdaMinRatio |
Smallest value for |
interactionCandidates |
An optional vector of variable
indices. This will force the algorithm to only consider interactions
between |
interactionPairs |
An optional nx2 matrix of variable indices. This will force the algorithm to only consider the interaction pairs defined by this matrix. For example, matrix(c(1,2,1,5), ncol=2, byrow=TRUE) restricts the model to two interaction pairs: one between variables 1 and 2, and another between 1 and 5. |
screenLimit |
If not null (the default), limits the size of the interaction
search space to |
numToFind |
Stops the program after |
family |
A character string describing the target variable: "gaussian" for continuous (the default), "binomial" for logistic. |
tol |
Convergence tolerance in the adaptive FISTA algorithm. |
maxIter |
Maximum number of iterations in adaptive FISTA. Default 5000. |
verbose |
Prints progress. False by default. |
numCores |
Number of threads to run. For this to work, the package must be installed with OpenMP enabled. Default is 1 thread. |
The sequence of models implied by lambda
is fit by FISTA (fast
iterative soft thresholding) with adaptive step size and adaptive
momentum restart. The continuous features are standardized to have
unit norm and mean zero before computing the lambda
sequence
and fitting. The returned coefficients are unstandardized. Categorical
variables are not standardized.
An object of class glinternet
with the components
call |
The user function call. |
fitted |
The fitted values, with dimension nobs x
|
lambda |
The actual |
objValue |
Objective values for each lambda. |
activeSet |
A list (of length |
betahat |
List (of length |
numLevels |
The number of levels for each variable. |
family |
The target variable type. |
Michael Lim and Trevor Hastie
Maintainer: Michael Lim [email protected]
Michael Lim and Trevor Hastie (2013)Learning interactions via hierarchical group-lasso regularization, https://arxiv.org/abs/1308.2719
glinternet.cv
, predict.glinternet
,
predict.glinternet.cv
, plot.glinternet.cv
, coef.glinternet
# gaussian response, continuous features Y = rnorm(100) X = matrix(rnorm(100*10), nrow=100) numLevels = rep(1, 10) fit = glinternet(X, Y, numLevels) #binary response, continuous features Y = rbinom(100, 1, 0.5) fit = glinternet(X, Y, numLevels, family="binomial") #binary response, categorical variables X = matrix(sample(0:2, 100*10, replace=TRUE), nrow=100) numLevels = rep(3, 10) fit = glinternet(X, Y, numLevels, family="binomial")
# gaussian response, continuous features Y = rnorm(100) X = matrix(rnorm(100*10), nrow=100) numLevels = rep(1, 10) fit = glinternet(X, Y, numLevels) #binary response, continuous features Y = rbinom(100, 1, 0.5) fit = glinternet(X, Y, numLevels, family="binomial") #binary response, categorical variables X = matrix(sample(0:2, 100*10, replace=TRUE), nrow=100) numLevels = rep(3, 10) fit = glinternet(X, Y, numLevels, family="binomial")
Does k-fold cross validation for glinternet and returns a
value of lambda
.
glinternet.cv(X, Y, numLevels, nFolds = 10, lambda=NULL, nLambda=50, lambdaMinRatio=0.01, interactionCandidates=NULL, interactionPairs=NULL, screenLimit=NULL, family=c("gaussian", "binomial"), tol=1e-5, maxIter=5000, verbose=FALSE, numCores=1)
glinternet.cv(X, Y, numLevels, nFolds = 10, lambda=NULL, nLambda=50, lambdaMinRatio=0.01, interactionCandidates=NULL, interactionPairs=NULL, screenLimit=NULL, family=c("gaussian", "binomial"), tol=1e-5, maxIter=5000, verbose=FALSE, numCores=1)
X |
|
Y |
Target |
numLevels |
Number of levels |
nFolds |
Number of folds - default is 10. |
lambda |
|
nLambda |
|
lambdaMinRatio |
|
interactionCandidates |
|
interactionPairs |
|
screenLimit |
|
family |
|
tol |
|
maxIter |
|
verbose |
|
numCores |
|
The lambda
sequence is computed using all the
data. nFolds
models are fit, each time with one of the folds
omitted. The error is accumulated, and the average error and standard deviation over the
folds is computed. The lambda
value that minimizes the average
error is returned, and a model with this lambda
is fit to the
full data set.
An object of class glinternet.cv
with the components
call |
The user function call. |
glinternetFit |
Glinternet object fitted on the full data using a
lambda sequence that terminates at |
fitted |
Vector for fitted values (same length as |
activeSet |
|
betahat |
Unstandardized coefficients for the variables in
|
lambda |
The actual sequence of |
lambdaHat |
The value of |
lambdaHat1Std |
The largest value of |
cvErr |
The vector of cross validation errors. Same length as
|
cvErrStd |
Standard deviation for cv errors across the
|
family |
The response type. |
numLevels |
Input number of levels for each variable. |
nFolds |
The number of folds used. |
Michael Lim and Trevor Hastie
Maintainer: Michael Lim [email protected]
glinternet
, predict.glinternet
,
predict.glinternet.cv
, plot.glinternet.cv
Y = rnorm(100) numLevels = sample(1:5, 10, replace=TRUE) X = sapply(numLevels, function(x) if (x==1) rnorm(100) else sample(0:(x-1), 100, replace=TRUE)) fit = glinternet.cv(X, Y, numLevels, nFolds=3)
Y = rnorm(100) numLevels = sample(1:5, 10, replace=TRUE) X = sapply(numLevels, function(x) if (x==1) rnorm(100) else sample(0:(x-1), 100, replace=TRUE)) fit = glinternet.cv(X, Y, numLevels, nFolds=3)
glinternetCV
object.Plots the cross validation error against the lambda index. Uses ggplot2
if found on the user's system.
## S3 method for class 'glinternet.cv' plot(x, ...)
## S3 method for class 'glinternet.cv' plot(x, ...)
x |
|
... |
Not used. |
A plot of CV error.
Michael Lim and Trevor Hastie
Maintainer: Michael Lim [email protected]
glinternet
, glinternet.cv
, predict.glinternet.cv
, predict.glinternet
Similar to other predict methods, this function returns fitted values on the response scale. Also gives the option to return the link function.
## S3 method for class 'glinternet' predict(object, X, type = c("response", "link"), lambda=NULL, ...)
## S3 method for class 'glinternet' predict(object, X, type = c("response", "link"), lambda=NULL, ...)
object |
Fitted |
X |
Matrix of new values for which to make predictions. Must have the same number of variables as during training the model, and all the variables must have the same number of levels. |
type |
Return fitted |
lambda |
User input lambda sequence. Must be subset of the lambdas used in fitting. If NULL (the default), predict at all the lambdas used during fitting. |
... |
Not used. Other arguments to predict. |
If lambda is not specified, makes predictions at all the fitted lambda values. Users may provide their own lambda sequence, but this must be a subset of the values used to fit the models.
A matrix of predicted values, with columns corresponding to each fitted model.
Michael Lim and Trevor Hastie
Maintainer: Michael Lim [email protected]
glinternet
, glinternet.cv
, predict.glinternet.cv
, plot.glinternet.cv
Y = rnorm(100) numLevels = sample(1:5, 10, replace=TRUE) X = sapply(numLevels, function(x) if (x==1) rnorm(100) else sample(0:(x-1), 100, replace=TRUE)) fit = glinternet(X, Y, numLevels) max(abs(fit$fitted - predict(fit, X)))
Y = rnorm(100) numLevels = sample(1:5, 10, replace=TRUE) X = sapply(numLevels, function(x) if (x==1) rnorm(100) else sample(0:(x-1), 100, replace=TRUE)) fit = glinternet(X, Y, numLevels) max(abs(fit$fitted - predict(fit, X)))
Similar to other predict methods, this function returns fitted values on the response scale. Also gives the option to return the link function.
## S3 method for class 'glinternet.cv' predict(object, X, type = c("response", "link"), lambdaType=c("lambdaHat", "lambdaHat1Std"), ...)
## S3 method for class 'glinternet.cv' predict(object, X, type = c("response", "link"), lambdaType=c("lambdaHat", "lambdaHat1Std"), ...)
object |
|
X |
Matrix of new values for which to make predictions. Must have the same number of variables as during training the model, and all the variables must have the same number of levels. |
type |
Return fitted |
lambdaType |
|
... |
Not used. |
Makes predictions using the model fitted at the appropriate lambda value.
A vector of predicted values.
Michael Lim and Trevor Hastie
Maintainer: Michael Lim [email protected]
glinternet
, glinternet.cv
, predict.glinternet
Y = rnorm(100) numLevels = sample(1:5, 10, replace=TRUE) X = sapply(numLevels, function(x) if (x==1) rnorm(100) else sample(0:(x-1), 100, replace=TRUE)) fit = glinternet.cv(X, Y, numLevels, nFolds=3) max(abs(fit$fitted - predict(fit, X)))
Y = rnorm(100) numLevels = sample(1:5, 10, replace=TRUE) X = sapply(numLevels, function(x) if (x==1) rnorm(100) else sample(0:(x-1), 100, replace=TRUE)) fit = glinternet.cv(X, Y, numLevels, nFolds=3) max(abs(fit$fitted - predict(fit, X)))