Description Usage Arguments Details Value Note References See Also Examples
Does k-fold cross-validation for sail and determines the optimal tuning parameter λ.
1 2 3 |
x |
input matrix of dimension |
y |
response variable. For |
e |
exposure or environment vector. Must be a numeric vector. Factors must be converted to numeric. |
... |
other arguments that can be passed to |
weights |
observation weights. Default is 1 for each observation. Currently NOT IMPLEMENTED. |
lambda |
Optional user-supplied lambda sequence; default is NULL, and
|
type.measure |
loss to use for cross-validation. Currently only 3
options are implemented. The default is |
nfolds |
number of folds. Although |
foldid |
an optional vector of values between 1 and |
grouped |
This is an experimental argument, with default |
keep |
If |
parallel |
If |
The function runs sail
nfolds
+1 times; the
first to get the lambda
sequence, and then the remainder to compute
the fit with each of the folds omitted. Note that a new lambda sequence is
computed for each of the folds and then we use the predict
method to
get the solution path at each value of the original lambda sequence. The
error is accumulated, and the average error and standard deviation over the
folds is computed. Note that cv.sail
does NOT search for values for
alpha
. A specific value should be supplied, else alpha=0.5
is
assumed by default. If users would like to cross-validate alpha
as
well, they should call cv.sail
with a pre-computed vector
foldid
, and then use this same fold vector in separate calls to
cv.sail
with different values of alpha
. Note also that the
results of cv.sail
are random, since the folds are selected at
random. Users can reduce this randomness by running cv.sail
many
times, and averaging the error curves.
an object of class "cv.sail"
is returned, which is a list with
the ingredients of the cross-validation fit.
the
values of converged lambda
used in the fits.
The mean
cross-validated error - a vector of length length(lambda)
.
estimate of standard error of cvm
.
upper
curve = cvm+cvsd
.
lower curve = cvm-cvsd
.
number of non-zero coefficients at each lambda
. This is
the sum of the total non-zero main effects and interactions. Note that when
expand=TRUE
, we only count a variable once in the calculation of
nzero
, i.e., if a variable is expanded to three columns, then this
is only counted once even though all three coefficients are estimated to be
non-zero
a text string indicating type of measure (for plotting purposes).
a fitted sail
object for the full
data.
value of lambda
that gives minimum
cvm
.
largest value of lambda
such that
error is within 1 standard error of the minimum.
if
keep=TRUE
, this is the array of prevalidated fits. Some entries can
be NA
, if that and subsequent values of lambda
are not
reached for that fold
if keep=TRUE
, the fold
assignments used
The skeleton of this function and the documentation were taken straight
from the glmnet
package. See references for details.
Jerome Friedman, Trevor Hastie, Robert Tibshirani (2010). Regularization Paths for Generalized Linear Models via Coordinate Descent. Journal of Statistical Software, 33(1), 1-22. http://www.jstatsoft.org/v33/i01/.
Bhatnagar SR, Yang Y, Greenwood CMT. Sparse additive interaction models with the strong heredity property (2018+). Preprint.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | f.basis <- function(i) splines::bs(i, degree = 3)
data("sailsim")
# Parallel
library(doParallel)
cl <- makeCluster(2)
registerDoParallel(cl)
cvfit <- cv.sail(x = sailsim$x, y = sailsim$y, e = sailsim$e,
parallel = TRUE, nlambda = 10,
maxit = 25, basis = f.basis,
nfolds = 3, dfmax = 5)
stopCluster(cl)
# plot cross validated curve
plot(cvfit)
# solution at lambda.min
coef(cvfit, s = "lambda.min")
# solution at lambda.1se
coef(cvfit, s = "lambda.1se")
# non-zero coefficients at lambda.min
predict(cvfit, s = "lambda.min", type = "nonzero")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.