Title: | The (Adaptive) Elastic Net and Lasso Penalized Sparse Asymmetric Least Squares (SALES) and Coupled Sparse Asymmetric Least Squares (COSALES) using Coordinate Descent and Proximal Gradient Algorithms |
---|---|
Description: | A coordinate descent algorithm for computing the solution paths of the sparse and coupled sparse asymmetric least squares, including the (adaptive) elastic net and Lasso penalized SALES and COSALES regressions. |
Authors: | Yuwen Gu <[email protected]>, Hui Zou <[email protected]> |
Maintainer: | Yuwen Gu <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.2 |
Built: | 2024-11-28 06:42:17 UTC |
Source: | CRAN |
coef
is a generic function which extracts model coefficients from
objects returned by modeling functions. coefficients
is an
alias for it.
coef(object, ...)
coef(object, ...)
object |
an object for which the extraction of model coefficients is meaningful. |
... |
other arguments. |
Coefficients extracted from the model object object
.
Computes the coefficients or returns a list of the indices of the nonzero
coefficients at the requested values for lambda
from a fitted cpernet
object.
## S3 method for class 'cpernet' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
## S3 method for class 'cpernet' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
object |
fitted |
s |
value(s) of the penalty parameter |
type |
type |
... |
not used. Other arguments to predict. |
s
is the new vector at which predictions are requested. If
s
is not in the lambda sequence used for fitting the model, the
coef
function will use linear interpolation to make predictions. The
new values are interpolated using a fraction of coefficients from both left
and right lambda
indices.
The object returned depends on type.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
cpernet
, predict.cpernet
,
print.cpernet
, plot.cpernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, intercept = TRUE, standardize = FALSE, lambda2 = lambda2) mean.coef <- as.vector(coef(m2, s = m2$lambda[50])[[1]]) scale.coef <- as.vector(coef(m2, s = m2$lambda[50])[[2]])
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, intercept = TRUE, standardize = FALSE, lambda2 = lambda2) mean.coef <- as.vector(coef(m2, s = m2$lambda[50])[[1]]) scale.coef <- as.vector(coef(m2, s = m2$lambda[50])[[2]])
This function gets coefficients from a cross-validated cpernet model, using
the fitted cv.cpernet
object, and the optimal value chosen for
lambda
.
## S3 method for class 'cv.cpernet' coef(object, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.cpernet' coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
fitted |
s |
value(s) of the penalty parameter |
... |
not used. Other arguments to predict. |
This function makes it easier to use the results of cross-validation to get coefficients or make coefficient predictions.
The object returned depends the ... argument which is passed on
to the predict
method for cpernet
objects.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
cv.cpernet
, predict.cv.cpernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) as.vector(coef(m2.cv, s = "lambda.min")$beta) as.vector(coef(m2.cv, s = "lambda.min")$theta)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) as.vector(coef(m2.cv, s = "lambda.min")$beta) as.vector(coef(m2.cv, s = "lambda.min")$theta)
This function gets coefficients from a cross-validated ernet model, using
the fitted cv.ernet
object, and the optimal value chosen for
lambda
.
## S3 method for class 'cv.ernet' coef(object, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.ernet' coef(object, s = c("lambda.1se", "lambda.min"), ...)
object |
fitted |
s |
value(s) of the penalty parameter |
... |
not used. Other arguments to predict. |
This function makes it easier to use the results of cross-validation to get coefficients or make coefficient predictions.
The object returned depends the ... argument which is passed on
to the predict
method for ernet
objects.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) as.vector(coef(m1.cv, s = "lambda.min"))
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) as.vector(coef(m1.cv, s = "lambda.min"))
Computes the coefficients or returns a list of the indices of the nonzero
coefficients at the requested values for lambda
from a fitted ernet
object.
## S3 method for class 'ernet' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
## S3 method for class 'ernet' coef(object, s = NULL, type = c("coefficients", "nonzero"), ...)
object |
fitted |
s |
value(s) of the penalty parameter |
type |
type |
... |
not used. Other arguments to predict. |
s
is the new vector at which predictions are requested. If
s
is not in the lambda sequence used for fitting the model, the
coef
function will use linear interpolation to make predictions. The
new values are interpolated using a fraction of coefficients from both left
and right lambda
indices.
The object returned depends on type.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
ernet
, predict.ernet
,
print.ernet
, plot.ernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) as.vector(coef(m1, s = m1$lambda[5]))
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) as.vector(coef(m1, s = m1$lambda[5]))
Fits regularization paths for coupled sparse asymmetric least squares regression at a sequence of regularization parameters.
cpernet( x, y, w = 1, nlambda = 100L, method = "cper", lambda.factor = ifelse(2 * nobs < nvars, 0.01, 1e-04), lambda = NULL, lambda2 = 0, pf.mean = rep(1, nvars), pf2.mean = rep(1, nvars), pf.scale = rep(1, nvars), pf2.scale = rep(1, nvars), exclude, dfmax = nvars + 1, pmax = min(dfmax * 1.2, nvars), standardize = TRUE, intercept = TRUE, eps = 1e-08, maxit = 1000000L, tau = 0.8 )
cpernet( x, y, w = 1, nlambda = 100L, method = "cper", lambda.factor = ifelse(2 * nobs < nvars, 0.01, 1e-04), lambda = NULL, lambda2 = 0, pf.mean = rep(1, nvars), pf2.mean = rep(1, nvars), pf.scale = rep(1, nvars), pf2.scale = rep(1, nvars), exclude, dfmax = nvars + 1, pmax = min(dfmax * 1.2, nvars), standardize = TRUE, intercept = TRUE, eps = 1e-08, maxit = 1000000L, tau = 0.8 )
x |
matrix of predictors, of dimension (nobs * nvars); each row is an observation. |
y |
response variable. |
w |
weight applied to the asymmetric squared error loss of the mean part. See details. Default is 1.0. |
nlambda |
the number of |
method |
a character string specifying the loss function to use. Only
|
lambda.factor |
The factor for getting the minimal lambda in the
|
lambda |
a user-supplied |
lambda2 |
regularization parameter |
pf.mean , pf.scale
|
L1 penalty factor of length |
pf2.mean , pf2.scale
|
L2 penalty factor of length |
exclude |
indices of variables to be excluded from the model. Default is none. Equivalent to an infinite penalty factor. |
dfmax |
limit the maximum number of variables in the model. Useful for
very large |
pmax |
limit the maximum number of variables ever to be nonzero. For
example once |
standardize |
logical flag for variable standardization, prior to
fitting the model sequence. The coefficients are always returned to the
original scale. Default is |
intercept |
Should intercept(s) be fitted (default=TRUE) or set to zero (FALSE). |
eps |
convergence threshold for coordinate descent. Each inner
coordinate descent loop continues until the maximum change in any
coefficient is less than |
maxit |
maximum number of outer-loop iterations allowed at fixed lambda
values. Default is 1e7. If the algorithm does not converge, consider
increasing |
tau |
the parameter |
Note that the objective function in cpernet
is
where
denotes the asymmetric squared error
loss and the penalty is a combination of L1 and L2 terms for both the mean
and scale coefficients.
For faster computation, if the algorithm is not converging or running slow,
consider increasing eps
, decreasing nlambda
, or increasing
lambda.factor
before increasing maxit
.
An object with S3 class cpernet
.
call |
the call that produced this object. |
b0 , t0
|
intercept sequences both of
length |
beta , theta
|
|
lambda |
the actual sequence of |
df.beta , df.theta
|
the number of nonzero mean and scale coefficients
respectively for each value of |
dim |
dimensions of coefficient matrices. |
npasses |
total number of iterations summed over all lambda values. |
jerr |
error flag, for warnings and errors, 0 if no error. |
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
plot.cpernet
, coef.cpernet
,
predict.cpernet
, print.cpernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2)
Does k-fold cross-validation for cpernet
, produces a plot, and returns
a value for lambda
. This function is based on the cv
function
from the glmnet
package.
cv.cpernet( x, y, w = 1, lambda = NULL, pred.loss = "loss", nfolds = 5, foldid, tau = 0.8, ... )
cv.cpernet( x, y, w = 1, lambda = NULL, pred.loss = "loss", nfolds = 5, foldid, tau = 0.8, ... )
x |
|
y |
response variable |
w |
weight applied to the asymmetric squared error loss of the mean part. Default is 1.0. |
lambda |
optional user-supplied lambda sequence; default is |
pred.loss |
loss function used to calculate cross-validation error. The
only option now is |
nfolds |
number of folds. Default value is 5. Although |
foldid |
an optional vector of values between 1 and |
tau |
the asymmetry coefficient |
... |
other arguments that can be passed to cpernet. |
The function runs cpernet
nfolds
+1 times. The
first gets the lambda
sequence, and the remainder fits the model
with each of the folds removed. The average error and standard deviation
over the folds are computed.
an object of class cv.cpernet
is returned, which is a
list with the ingredients of the cross-validation fit.
lambda |
the values of |
cvm |
the mean cross-validated error - a vector of length
|
cvsd |
estimate of standard error of |
cvupper |
upper curve = |
cvlower |
lower curve = |
nzero |
a list of two components, each representing the number of
non-zero coefficients at each |
name |
a text string indicating type of measure (for plotting purposes). |
cpernet.fit |
a fitted |
lambda.min |
The optimal value of |
lambda.1se |
The largest value of |
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2)
Does k-fold cross-validation for ernet, produces a plot, and returns a value
for lambda
. This function is based on the cv
function from the
glmnet
package.
cv.ernet( x, y, lambda = NULL, pred.loss = "loss", nfolds = 5, foldid, tau = 0.5, ... )
cv.ernet( x, y, lambda = NULL, pred.loss = "loss", nfolds = 5, foldid, tau = 0.5, ... )
x |
|
y |
response variable |
lambda |
optional user-supplied lambda sequence; default is |
pred.loss |
loss function used to calculate cross-validation error. The
only option now is |
nfolds |
number of folds. Default value is 5. Although |
foldid |
an optional vector of values between 1 and |
tau |
the asymmetry coefficient |
... |
other arguments that can be passed to ernet. |
The function runs ernet
nfolds
+1 times; the
first to get the lambda
sequence, and the remainder to compute the
fit with each of the folds removed. The average error and standard
deviation over the folds are computed.
an object of class cv.ernet
is returned, which is a
list with the ingredients of the cross-validation fit.
lambda |
the values of |
cvm |
the mean cross-validated error - a vector of length
|
cvsd |
estimate of standard error of |
cvupper |
upper curve = |
cvlower |
lower curve = |
nzero |
number of non-zero coefficients at each |
name |
a text string indicating type of measure (for plotting purposes). |
ernet.fit |
a fitted |
lambda.min |
The optimal value of |
lambda.1se |
The largest value of |
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2)
Fits regularization paths for the Lasso or elastic net penalized asymmetric least squares regression at a sequence of regularization parameters.
ernet( x, y, nlambda = 100L, method = "er", lambda.factor = ifelse(nobs < nvars, 0.01, 1e-04), lambda = NULL, lambda2 = 0, pf = rep(1, nvars), pf2 = rep(1, nvars), exclude, dfmax = nvars + 1, pmax = min(dfmax * 1.2, nvars), standardize = TRUE, intercept = TRUE, eps = 1e-08, maxit = 1000000L, tau = 0.5 )
ernet( x, y, nlambda = 100L, method = "er", lambda.factor = ifelse(nobs < nvars, 0.01, 1e-04), lambda = NULL, lambda2 = 0, pf = rep(1, nvars), pf2 = rep(1, nvars), exclude, dfmax = nvars + 1, pmax = min(dfmax * 1.2, nvars), standardize = TRUE, intercept = TRUE, eps = 1e-08, maxit = 1000000L, tau = 0.5 )
x |
matrix of predictors, of dimension (nobs * nvars); each row is an observation. |
y |
response variable. |
nlambda |
the number of |
method |
a character string specifying the loss function to use. only
|
lambda.factor |
The factor for getting the minimal lambda in the
|
lambda |
a user-supplied |
lambda2 |
regularization parameter |
pf |
L1 penalty factor of length |
pf2 |
L2 penalty factor of length |
exclude |
indices of variables to be excluded from the model. Default is none. Equivalent to an infinite penalty factor. |
dfmax |
the maximum number of variables allowed in the model. Useful for
very large |
pmax |
the maximum number of coefficients allowed ever to be nonzero.
For example once |
standardize |
logical flag for variable standardization, prior to
fitting the model sequence. The coefficients are always returned to the
original scale. Default is |
intercept |
Should intercept(s) be fitted (default is |
eps |
convergence threshold for coordinate descent. Each inner
coordinate descent loop continues until the maximum change in any
coefficient is less than |
maxit |
maximum number of outer-loop iterations allowed at fixed lambda
values. Default is 1e7. If the algorithm does not converge, consider
increasing |
tau |
the parameter |
Note that the objective function in ernet
is
where
denotes the asymmetric squared error loss and
the penalty is a combination of weighted L1 and L2 terms.
For faster computation, if the algorithm is not converging or running slow,
consider increasing eps
, decreasing nlambda
, or increasing
lambda.factor
before increasing maxit
.
An object with S3 class ernet
.
call |
the call that produced this object |
b0 |
intercept sequence of length |
beta |
a |
lambda |
the actual sequence of |
df |
the number of nonzero coefficients for each value of
|
dim |
dimension of coefficient matrix |
npasses |
total number of iterations summed over all lambda values |
jerr |
error flag, for warnings and errors, 0 if no error. |
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
Gu, Y., and Zou, H. (2016).
"High-dimensional generalizations of asymmetric least squares regression and their applications."
The Annals of Statistics, 44(6), 2661–2694.
plot.ernet
, coef.ernet
,
predict.ernet
, print.ernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2)
Produces a coefficient profile plot of the coefficient paths for a fitted
cpernet object. This function is modified based on the plot
method in
the glmnet
package.
## S3 method for class 'cpernet' plot(x, xvar = c("norm", "lambda"), color = FALSE, label = FALSE, ...)
## S3 method for class 'cpernet' plot(x, xvar = c("norm", "lambda"), color = FALSE, label = FALSE, ...)
x |
fitted |
xvar |
what is on the x-axis. |
color |
if |
label |
if |
... |
other graphical parameters to plot. |
Two coefficient profile plots are produced, one for the mean coefficients and the other for the scale coefficients.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, intercept = TRUE, standardize = FALSE, lambda2 = lambda2) plot(m2)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, intercept = TRUE, standardize = FALSE, lambda2 = lambda2) plot(m2)
Plots the cross-validated curve, and upper and lower standard deviation
curves, as a function of the lambda
values used. This function is
modified based on the plot.cv.glmnet
function from the glmnet
package.
## S3 method for class 'cv.cpernet' plot(x, sign.lambda = 1, ...)
## S3 method for class 'cv.cpernet' plot(x, sign.lambda = 1, ...)
x |
fitted |
sign.lambda |
either plot against |
... |
other graphical parameters to plot |
A plot is produced.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) plot(m2.cv)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) plot(m2.cv)
Plots the cross-validated curve, and upper and lower standard deviation
curves, as a function of the lambda
values used. This function is
modified based on the plot.cv.glmnet
function from the glmnet
package.
## S3 method for class 'cv.ernet' plot(x, sign.lambda = 1, ...)
## S3 method for class 'cv.ernet' plot(x, sign.lambda = 1, ...)
x |
fitted |
sign.lambda |
either plot against |
... |
other graphical parameters to plot |
A plot is produced.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) plot(m1.cv)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) plot(m1.cv)
Produces a coefficient profile plot of the coefficient paths for a fitted
ernet object. This function is modified based on the plot
method in
the glmnet
package.
## S3 method for class 'ernet' plot(x, xvar = c("norm", "lambda"), color = FALSE, label = FALSE, ...)
## S3 method for class 'ernet' plot(x, xvar = c("norm", "lambda"), color = FALSE, label = FALSE, ...)
x |
fitted |
xvar |
what is on the x-axis. |
color |
if |
label |
if |
... |
other graphical parameters to plot. |
A coefficient profile plot is produced.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) plot(m1)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) plot(m1)
predict
is a generic function for predictions from the results of
various model fitting functions. The function invokes particular
methods which depend on the class
of the first
argument.
predict(object, ...)
predict(object, ...)
object |
a model object for which prediction is desired. |
... |
additional arguments affecting the predictions produced. |
The form of the value returned by predict
depends on the
class of its argument. See the documentation of the particular methods for
details of what is produced by that method.
predict.ernet
, predict.cpernet
.
Similar to other predict methods, this function predicts fitted values from a cpernet object.
## S3 method for class 'cpernet' predict(object, newx, s = NULL, type = "response", ...)
## S3 method for class 'cpernet' predict(object, newx, s = NULL, type = "response", ...)
object |
fitted |
newx |
matrix of new values for |
s |
value(s) of the penalty parameter |
type |
type of prediction required. Only |
... |
Not used. Other arguments to predict. |
s
is the new vector at which predictions are to be made. If
s
is not in the lambda sequence used for fitting the model, the
predict
function will use linear interpolation to make predictions.
The new values are interpolated using a fraction of predicted values from
both left and right lambda
indices.
The object returned depends on type.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
cpernet
, coef.cpernet
,
plot.cpernet
, print.cpernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) predict(m2, newx = x, s = m2$lambda[50])
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) predict(m2, newx = x, s = m2$lambda[50])
This function makes predictions from a cross-validated cpernet model, using
the fitted cv.cpernet
object, and the optimal value chosen for
lambda
.
## S3 method for class 'cv.cpernet' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.cpernet' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
object |
fitted |
newx |
matrix of new values for |
s |
value(s) of the penalty parameter |
... |
not used. Other arguments to predict. |
This function makes it easier to use the results of cross-validation to make a prediction.
The object returned depends the ... argument which is passed on
to the predict
method for cpernet
objects.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
cv.cpernet
, coef.cv.cpernet
,
plot.cv.cpernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) as.vector(predict(m2.cv, newx = x, s = "lambda.min"))
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2.cv <- cv.cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) as.vector(predict(m2.cv, newx = x, s = "lambda.min"))
This function makes predictions from a cross-validated ernet model, using
the fitted cv.ernet
object, and the optimal value chosen for
lambda
.
## S3 method for class 'cv.ernet' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
## S3 method for class 'cv.ernet' predict(object, newx, s = c("lambda.1se", "lambda.min"), ...)
object |
fitted |
newx |
matrix of new values for |
s |
value(s) of the penalty parameter |
... |
not used. Other arguments to predict. |
This function makes it easier to use the results of cross-validation to make a prediction.
The object returned depends the ... argument which is passed on
to the predict
method for ernet
objects.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
cv.ernet
, coef.cv.ernet
,
plot.cv.ernet
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) as.vector(predict(m1.cv, newx = x, s = "lambda.min"))
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1.cv <- cv.ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) as.vector(predict(m1.cv, newx = x, s = "lambda.min"))
Similar to other predict methods, this functions predicts fitted values from a fitted ernet object.
## S3 method for class 'ernet' predict(object, newx, s = NULL, type = "response", ...)
## S3 method for class 'ernet' predict(object, newx, s = NULL, type = "response", ...)
object |
fitted |
newx |
matrix of new values for |
s |
value(s) of the penalty parameter |
type |
type of prediction required. Only |
... |
Not used. Other arguments to predict. |
s
is the new vector at which predictions are to be made. If
s
is not in the lambda sequence used for fitting the model, the
predict
function will use linear interpolation to make predictions.
The new values are interpolated using a fraction of predicted values from
both left and right lambda
indices.
The object returned depends on type.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
ernet
, coef.ernet
,
plot.ernet
, print.ernet
Print a summary of the cpernet
path at each step along the path.
## S3 method for class 'cpernet' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'cpernet' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
fitted |
digits |
significant digits in the output. |
... |
additional print arguments. |
The call that produced the cpernet
object is printed,
followed by a three-column matrix with columns Df1
, Df2
and
Lambda
. The Df1
and Df2
columns are the number of
nonzero mean and scale coefficients respectively.
a three-column matrix, the first two columns are the number of
nonzero mean and scale coefficients respectively and the third column is
Lambda
.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) print(m2)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.30 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) w <- 2.0 lambda2 <- 1 m2 <- cpernet(y = y, x = x, w = w, tau = tau, eps = 1e-8, pf.mean = pf, pf.scale = pf2, standardize = FALSE, lambda2 = lambda2) print(m2)
Print a summary of the ernet path at each step along the path.
## S3 method for class 'ernet' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'ernet' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
fitted |
digits |
significant digits in the output. |
... |
additional print arguments. |
The call that produced the ernet
object is printed,
followed by a two-column matrix with columns Df
and Lambda
.
The Df
column is the number of nonzero coefficients.
a two-column matrix, the first columns is the number of nonzero
coefficients and the second column is Lambda
.
Yuwen Gu and Hui Zou
Maintainer: Yuwen Gu <[email protected]>
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) print(m1)
set.seed(1) n <- 100 p <- 400 x <- matrix(rnorm(n * p), n, p) y <- rnorm(n) tau <- 0.90 pf <- abs(rnorm(p)) pf2 <- abs(rnorm(p)) lambda2 <- 1 m1 <- ernet(y = y, x = x, tau = tau, eps = 1e-8, pf = pf, pf2 = pf2, standardize = FALSE, intercept = FALSE, lambda2 = lambda2) print(m1)