Title: | A Lasso for Hierarchical Interactions |
---|---|
Description: | Fits sparse interaction models for continuous and binary responses subject to the strong (or weak) hierarchy restriction that an interaction between two variables only be included if both (or at least one of) the variables is included as a main effect. For more details, see Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141. |
Authors: | Jacob Bien and Rob Tibshirani |
Maintainer: | Jacob Bien <[email protected]> |
License: | GPL-2 |
Version: | 1.10 |
Built: | 2024-11-07 06:12:54 UTC |
Source: | https://github.com/jacobbien/hiernet |
One of the main functions in the hierNet package. Builds a regression model with hierarchically constrained pairwise interactions. Required inputs are an x matrix of features (the columns are the features) and a y vector of values. Reasonably fast for moderate sized problems (100-200 variables). We are currently working on an alternate algorithm for large scale problems.
hierNet(x, y, lam, delta=1e-8, strong=FALSE, diagonal=TRUE, aa=NULL, zz=NULL, center=TRUE, stand.main=TRUE, stand.int=FALSE, rho=nrow(x), niter=100, sym.eps=1e-3, step=1, maxiter=2000, backtrack=0.2, tol=1e-5, trace=0)
hierNet(x, y, lam, delta=1e-8, strong=FALSE, diagonal=TRUE, aa=NULL, zz=NULL, center=TRUE, stand.main=TRUE, stand.int=FALSE, rho=nrow(x), niter=100, sym.eps=1e-3, step=1, maxiter=2000, backtrack=0.2, tol=1e-5, trace=0)
x |
A matrix of predictors, where the rows are the samples and the columns are the predictors |
y |
A vector of observations, where length(y) equals nrow(x) |
lam |
Regularization parameter (>0). L1 penalty param is |
delta |
Elastic Net parameter. Squared L2 penalty param is |
strong |
Flag specifying strong hierarchy (TRUE) or weak hierarchy (FALSE). Default FALSE. |
diagonal |
Flag specifying whether to include "pure" quadratic terms, th_jjX_j^2, in the model. Default TRUE. |
aa |
An *optional* argument, a list with results from a previous call |
zz |
An *optional* argument, a matrix whose columns are products of features, computed by the function compute.interactions.c |
center |
Should features be centered? Default TRUE; FALSE should rarely be used. This option is available for special uses only |
stand.main |
Should main effects be standardized? Default TRUE. |
stand.int |
Should interactions be standardized? Default FALSE. |
rho |
ADMM parameter: tuning parameter (>0) for ADMM. If there are convergence
problems, try decreasing |
niter |
ADMM parameter: number of iterations |
sym.eps |
ADMM parameter: threshold for symmetrizing with strong=TRUE |
step |
Stepsize for generalized gradient descent |
maxiter |
Maximum number of iterations for generalized gradient descent |
backtrack |
Backtrack parameter for generalized gradient descent |
tol |
Error tolerance parameter for generalized gradient descent |
trace |
Output option; trace=1 gives verbose output |
bp |
p-vector of estimated "positive part" main effect (p=# features) |
bn |
p-vector of estimated "negative part" main effect; overall main effect estimated coefficients are bp-bn |
th |
Matrix of estimated interaction coefficients, of dimension p by p. Note: when output from hierNet is printed, th is symmetrized (set to (th+t(th))/2) for simplicity. |
obj |
Value of objective function at minimum. |
lam |
Value of lambda used |
type |
Type of model fit- "gaussian" or "logistic" (binomial) |
mx |
p-vector of column means of x |
sx |
p-vector of column standard deviations of x |
my |
mean of y |
mzz |
column means of feature product matrix |
szz |
column standard deviations of feature product matrix |
call |
The call to hierNet |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
predict.hierNet, hierNet.cv, hierNet.path
set.seed(12) # fit a single hierNet model x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet(x,y,lam=50) print(fit) # try strong (rather than weak) hierarchy fit=hierNet(x,y,lam=50, strong=TRUE) print(fit) # a typical analysis including cross-validation set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet.path(x,y) fitcv=hierNet.cv(fit,x,y) print(fitcv) lamhat=fitcv$lamhat.1se fit2=hierNet(x,y,lam=lamhat) yhat=predict(fit2,x)
set.seed(12) # fit a single hierNet model x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet(x,y,lam=50) print(fit) # try strong (rather than weak) hierarchy fit=hierNet(x,y,lam=50, strong=TRUE) print(fit) # a typical analysis including cross-validation set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet.path(x,y) fitcv=hierNet.cv(fit,x,y) print(fitcv) lamhat=fitcv$lamhat.1se fit2=hierNet(x,y,lam=lamhat) yhat=predict(fit2,x)
Uses cross-validation to estimate the regularization parameter for hierNet
hierNet.cv(fit, x, y, nfolds=10,folds=NULL,trace=0)
hierNet.cv(fit, x, y, nfolds=10,folds=NULL,trace=0)
fit |
Object returned from call to hierNet.path or hierNet.logistic.path. All parameter settings will be taken from this object. |
x |
A matrix of predictors, where the rows are the samples and the columns are the predictors |
y |
A vector of observations, where length(y) equals nrow(x) |
nfolds |
Number of cross-validation folds |
folds |
(Optional) user-supplied cross-validation folds. If provided, nfolds is ignored. |
trace |
Verbose output? 0=no, 1=yes |
lamlist |
Vector of lambda values tried |
cv.err |
Estimate of cross-validation error |
cv.se |
Estimated standard error of cross-validation estimate |
lamhat |
lambda value minimizing cv.err |
lamhat.1se |
largest lambda value with cv.err less than or equal to min(cv.err)+ SE |
folds |
Indices of folds used in cross-validation |
yhat |
n by nlam matrix of predicted values. Here, ith prediction is based on training on all folds that do not include the ith data point. |
nonzero |
Vector giving number of non-zero coefficients for each lambda value |
call |
The call to hierNet.cv |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
hierNet,hierNet.path, hierNet.logistic,hierNet.logistic.path
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet.path(x,y) fitcv=hierNet.cv(fit,x,y) print(fitcv) plot(fitcv) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) fit=hierNet.logistic.path(x,y) fitcv=hierNet.cv(fit,x,y) print(fitcv) plot(fitcv)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet.path(x,y) fitcv=hierNet.cv(fit,x,y) print(fitcv) plot(fitcv) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) fit=hierNet.logistic.path(x,y) fitcv=hierNet.cv(fit,x,y) print(fitcv) plot(fitcv)
One of the main functions in the hierNet package. Builds a logistic regression model with hierarchically constrained pairwise interactions. Required inputs are an x matrix of features (the columns are the features) and a y vector of values. Reasonably fast for moderate sized problems (100-200 variables). We are currently working on a alternate algorithm for large scale problems.
hierNet.logistic(x, y, lam, delta=1e-8, diagonal=TRUE, strong=FALSE, aa=NULL, zz=NULL, center=TRUE, stand.main=TRUE, stand.int=FALSE, rho=nrow(x), niter=100, sym.eps=1e-3,# ADMM params step=1, maxiter=2000, backtrack=0.2, tol=1e-5, trace=1)
hierNet.logistic(x, y, lam, delta=1e-8, diagonal=TRUE, strong=FALSE, aa=NULL, zz=NULL, center=TRUE, stand.main=TRUE, stand.int=FALSE, rho=nrow(x), niter=100, sym.eps=1e-3,# ADMM params step=1, maxiter=2000, backtrack=0.2, tol=1e-5, trace=1)
x |
A matrix of predictors, where the rows are the samples and the columns are the predictors |
y |
A vector of observations, with values 0 or 1, where length(y) equals nrow(x) |
lam |
Regularization parameter (>0). L1 penalty param is |
delta |
Elastic Net parameter. Squared L2 penalty param is |
diagonal |
Flag specifying whether to include "pure" quadratic terms, th_jjX_j^2, in the model. Default TRUE. |
strong |
Flag specifying strong hierarchy (TRUE) or weak hierarchy (FALSE). Default FALSE |
aa |
An *optional* argument, a list with results from a previous call |
zz |
An *optional* argument, a matrix whose columns are products of features, computed by the function compute.interactions.c |
center |
Should features be centered? Default TRUE; FALSE should rarely be used. This option is available for special uses only |
stand.main |
Should main effects be standardized? Default TRUE |
stand.int |
Should interactions be standardized? Default FALSE |
rho |
ADMM parameter: tuning parameter (>0) for ADMM. If there are convergence
problems, try decreasing |
niter |
ADMM parameter: number of iterations |
sym.eps |
ADMM parameter Thresholding for symmetrizing with strong=TRUE |
step |
Stepsize for generalized gradient descent |
maxiter |
Maximum number of iterations for generalized gradient descent |
backtrack |
Backtrack parameter for generalized gradient descent |
tol |
Error tolerance parameter for generalized gradient descent |
trace |
Output option; trace=1 gives verbose output |
b0 |
Intercept |
bp |
p-vector of estimated "positive part" main effect (p=#features) |
bn |
p-vector of estimated "negative part" main effect; overall main effect estimated coefficients are bp-bn |
th |
Matrix of estimated interaction coefficients, of dimension p by p |
obj |
Value of objective function at minimum. |
lam |
Value of lambda used |
type |
Type of model fit- "gaussian" or "logistic" (binomial) |
mx |
p-vector of column means of x |
my |
Mean of y |
sx |
p-vector of column standard deviations of x |
mzz |
column means of feature product matrix |
call |
The call to hierNet |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
predict.hierNet.logistic,linkhierNet.logistic.path
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) fit=hierNet.logistic(x,y,lam=5) print(fit)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) fit=hierNet.logistic(x,y,lam=5) print(fit)
One of the main functions in the hierNet package. Fits a logistic path of hierNet models over different values of the regularization parameter. Calls hierNet.logistic, which builds a regression model with hierarchically constrained pairwise interactions. Required inputs are an x matrix of features (the columns are the features) and a y vector of values. Reasonably fast for moderate sized problems (100-200 variables). We are currently working on a alternate algorithm for large scale problems.
hierNet.logistic.path(x, y, lamlist = NULL, delta=1e-8, minlam = NULL, maxlam = NULL, flmin=.01, nlam = 20, diagonal = TRUE, strong = FALSE, aa = NULL, zz = NULL, stand.main = TRUE, stand.int = FALSE, rho = nrow(x), niter = 100, sym.eps = 0.001, step = 1, maxiter = 2000, backtrack = 0.2, tol = 1e-05, trace = 0)
hierNet.logistic.path(x, y, lamlist = NULL, delta=1e-8, minlam = NULL, maxlam = NULL, flmin=.01, nlam = 20, diagonal = TRUE, strong = FALSE, aa = NULL, zz = NULL, stand.main = TRUE, stand.int = FALSE, rho = nrow(x), niter = 100, sym.eps = 0.001, step = 1, maxiter = 2000, backtrack = 0.2, tol = 1e-05, trace = 0)
x |
A matrix of predictors, where the rows are the samples and the columns are the predictors |
y |
A vector of observations equal to 0 or 1, where length(y) equals nrow(x) |
lamlist |
Optional vector of values of lambda (the regularization parameter). L1 penalty param is |
delta |
Elastic Net parameter. Squared L2 penalty param is |
minlam |
Optional minimum value for lambda |
maxlam |
Optional maximum value for lambda |
flmin |
Fraction of maxlam; minlam= flmin*maxlam. If computation is slow, try increasing flmin to focus on the sparser part of the path |
nlam |
Number of values of lambda to be tried |
diagonal |
Flag specifying whether to include "pure" quadratic terms, th_jjX_j^2, in the model. Default TRUE. |
stand.main |
Should main effects be standardized? Default TRUE |
stand.int |
Should interactions be standardized? Default FALSE |
strong |
Flag specifying strong hierarchy (TRUE) or weak hierarchy (FALSE). Default FALSE |
aa |
An *optional* argument, a list with results from a previous call |
zz |
An *optional* argument, a matrix whose columns are products of features, computed by the function compute.interactions.c |
rho |
ADMM parameter: tuning parameter (>0) for ADMM. If there are convergence
problems, try decreasing |
niter |
ADMM parameter: number of iterations |
sym.eps |
ADMM parameter Thresholding for symmetrizing with strong=TRUE |
step |
Stepsize for generalized gradient descent |
maxiter |
Maximum number of iterations for generalized gradient descent |
backtrack |
Backtrack parameter for generalized gradient descent |
tol |
Error tolerance parameter for generalized gradient descent |
trace |
Output option; trace=1 gives verbose output |
bp |
p by nlam matrix of estimated "positive part" main effects (p=#features) |
bn |
p by nlam matrix of estimated "negative part" main effects |
th |
p by p by nlam array of estimated interaction coefficients |
obj |
nlam values of objective function, one per lambda value |
lamlist |
Vector of values of lambda used |
mx |
p-vector of column means of x |
sx |
p-vector of column standard deviations of x |
my |
mean of y |
mzz |
column means of feature product matrix |
szz |
column standard deviations of feature product matrix |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
hierNet,predict.hierNet, hierNet.cv
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) fit=hierNet.logistic.path(x,y) print(fit)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) fit=hierNet.logistic.path(x,y) print(fit)
One of the main functions in the hierNet package. Fits a path of hierNet models over different values of the regularization parameter. Calls hierNet, which builds a regression model with hierarchically constrained pairwise interactions. Required inputs are an x matrix of features (the columns are the features) and a y vector of values. Reasonably fast for moderate sized problems (100-200 variables). We are currently working on an alternate algorithm for large scale problems.
hierNet.path(x, y, lamlist = NULL, delta=1e-8, minlam = NULL, maxlam = NULL, nlam=20, flmin=.01, diagonal = TRUE, strong = FALSE, aa = NULL, zz = NULL, stand.main = TRUE, stand.int = FALSE, rho = nrow(x), niter = 100, sym.eps = 0.001, step = 1, maxiter = 2000, backtrack = 0.2, tol = 1e-05, trace = 0)
hierNet.path(x, y, lamlist = NULL, delta=1e-8, minlam = NULL, maxlam = NULL, nlam=20, flmin=.01, diagonal = TRUE, strong = FALSE, aa = NULL, zz = NULL, stand.main = TRUE, stand.int = FALSE, rho = nrow(x), niter = 100, sym.eps = 0.001, step = 1, maxiter = 2000, backtrack = 0.2, tol = 1e-05, trace = 0)
x |
A matrix of predictors, where the rows are the samples and the columns are the predictors |
y |
A vector of observations, where length(y) equals nrow(x) |
lamlist |
Optional vector of values of lambda (the regularization parameter). L1 penalty param is |
delta |
Elastic Net parameter. Squared L2 penalty param is |
minlam |
Optional minimum value for lambda |
maxlam |
Optional maximum value for lambda |
nlam |
Number of values of lambda to be tried |
flmin |
Fraction of maxlam; minlam= flmin*maxlam. If computation is slow, try increasing flmin to focus on the sparser part of the path |
diagonal |
Flag specifying whether to include "pure" quadratic terms, th_jjX_j^2, in the model. Default TRUE. |
strong |
Flag specifying strong hierarchy (true) or weak hierarchy (false). Default false |
aa |
An *optional* argument, a list with results from a previous call |
zz |
An *optional* argument, a matrix whose columns are products of features, computed by the function compute.interactions.c |
stand.main |
Should main effects be standardized? Default TRUE |
stand.int |
Should interactions be standardized? Default FALSE |
rho |
ADMM parameter: tuning parameter (>0) for ADMM. If there are convergence problems, try decreasing rho. Default n. |
niter |
ADMM parameter: number of iterations |
sym.eps |
ADMM parameter Thresholding for symmetrizing with strong=TRUE |
step |
Stepsize for generalized gradient descent |
maxiter |
Maximum number of iterations for generalized gradient descent |
backtrack |
Backtrack parameter for generalized gradient descent |
tol |
Error tolerance parameter for generalized gradient descent |
trace |
Output option; trace=1 gives verbose output |
bp |
p by nlam matrix of estimated "positive part" main effects (p=#variables) |
bn |
p by nlam matrix of estimated "negative part" main effects |
th |
p by p by nlam array of estimated interaction coefficients |
obj |
nlam values of objective function, one per lambda value |
lamlist |
Vector of values of lambda used |
mx |
p-vector of column means of x |
sx |
p-vector of column standard deviations of x |
my |
mean of y |
mzz |
column means of feature product matrix |
szz |
column standard deviations of feature product matrix |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
hierNet,predict.hierNet, hierNet.cv
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet.path(x,y) print(fit)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) fit=hierNet.path(x,y) print(fit)
(This is an experimental function.) Calculates a measure of the importance of each variable.
hierNet.varimp(fit, x, y, ...)
hierNet.varimp(fit, x, y, ...)
fit |
The results of a call to the "hierNet" |
x |
The training set feature matrix used in call produced "fit" |
y |
The training set response vector used in call produced "fit" |
... |
additional arguments (not currently used) |
Table of variable importance.
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet(x,y,lam=50) yhat=predict(fit,newx) fit=hierNet.path(x,y) yhat=predict(fit,newx)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet(x,y,lam=50) yhat=predict(fit,newx) fit=hierNet.path(x,y) yhat=predict(fit,newx)
A function to perform prediction, using an x matrix and the output of the "hierNet" or "hiernet.logistic" function.
## S3 method for class 'hierNet' predict(object, newx, newzz=NULL, ...)
## S3 method for class 'hierNet' predict(object, newx, newzz=NULL, ...)
object |
The results of a call to the "hierNet" or "hierNet.path" or function. The coefficients that are part of this object will be used for making predictions. |
newx |
The new x at which predictions should be made. Can be a vector or a matrix (one obseration per row). |
newzz |
Optional matrix of products of columns of newx, computed by compute.interactions.c |
... |
additional arguments (not currently used) |
yhat |
Vector of predictions for each observation. For logistic model, these are the estimated probabilities. |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet(x,y,lam=50) yhat=predict(fit,newx) fit=hierNet.path(x,y) yhat=predict(fit,newx)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet(x,y,lam=50) yhat=predict(fit,newx) fit=hierNet.path(x,y) yhat=predict(fit,newx)
A function to perform prediction, using an x matrix and the output of the "hierNet.logistic" function or "hierNet.logistic.path".
## S3 method for class 'hierNet.logistic' predict(object, newx, newzz=NULL,...)
## S3 method for class 'hierNet.logistic' predict(object, newx, newzz=NULL,...)
object |
The results of a call to the "hierNet.logistic" or "hierNet.logistic.path" or function. The coefficients that are part of this object will be used for making predictions. |
newx |
The new x at which predictions should be made. Can be a vector or a matrix (one observation per row). |
newzz |
Optional matrix of products of columns of newx, computed by compute.interactions.c |
... |
additional arguments (not currently used) |
yhat |
Matrix of predictions (probabilities), one row per observation |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
hierNet.logistic, hierNet.logistic.path
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet.logistic(x,y,lam=5) yhat=predict(fit,newx) fit=hierNet.logistic.path(x,y) yhat=predict(fit,newx)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) y=1*(y>0) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet.logistic(x,y,lam=5) yhat=predict(fit,newx) fit=hierNet.logistic.path(x,y) yhat=predict(fit,newx)
A function to perform prediction, using an x matrix and the output of the "hierNet.path" or "hiernet.logistic.path" functions.
## S3 method for class 'hierNet.path' predict(object, newx, newzz=NULL, ...)
## S3 method for class 'hierNet.path' predict(object, newx, newzz=NULL, ...)
object |
The results of a call to the "hierNet" or "hierNet.path" or function. The coefficients that are part of this object will be used for making predictions. |
newx |
The new x at which predictions should be made. Can be a vector or a matrix (one obseration per row). |
newzz |
Optional matrix of products of columns of newx, computed by compute.interactions.c |
... |
additional arguments (not currently used) |
yhat |
Matrix of predictions, one row per observation. For logistic model, these are the estimated probabilities. |
Jacob Bien and Robert Tibshirani
Bien, J., Taylor, J., Tibshirani, R., (2013) "A Lasso for Hierarchical Interactions." Annals of Statistics. 41(3). 1111-1141.
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet(x,y,lam=50) yhat=predict(fit,newx) fit=hierNet.path(x,y) yhat=predict(fit,newx)
set.seed(12) x=matrix(rnorm(100*10),ncol=10) x=scale(x,TRUE,TRUE) y=x[,1]+2*x[,2]+ x[,1]*x[,2]+3*rnorm(100) newx=matrix(rnorm(100*10),ncol=10) fit=hierNet(x,y,lam=50) yhat=predict(fit,newx) fit=hierNet.path(x,y) yhat=predict(fit,newx)