timeLagLasso.cv: Cross-validation function for timeLagLasso

Description Usage Arguments Value Examples

View source: R/funcs.R

Description

Uses cross-validation to estimate the regularization parameter for timeLagLasso model

Usage

1
2
3
4
5
timeLagLasso.cv(x, y, maxlag, lamlist = NULL, minlam = NULL,
  maxlam = NULL, nlam = 10, flmin = 0.01, flmax = 1, intercept = TRUE,
  standardize = TRUE, method = c("Solve.QP", "GG"),
  strongly.ordered = TRUE, nfolds = 10, folds = NULL, maxiter = 500,
  inneriter = 100, iter.gg = 100, trace = FALSE, epsilon = 1e-04)

Arguments

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)

maxlag

Maximum time-lag variable chosen by user

lamlist

Optional vector of values of lambda (the regularization parameter)

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; default 1e-2

flmax

Multiplication of maxlam maxlam = flmax * maxlam; default 1

intercept

True if there is an intercept in the model.

standardize

Standardize the data matrix x.

method

Two options available, Solve.QP and Generalized Gradient. Details about two options can be seen in the orderedLasso description.

strongly.ordered

An option which allows users to order the coefficients in absolute value.

nfolds

Number of cross-validation folds

folds

(Optional) user-supplied cross-validation folds. If provided, nfolds is ignored.

maxiter

maximum iterations run by time-lag lasso. Initialized to 500.

inneriter

maximum iterations run by orderedLasso. Initialized to 100.

iter.gg

Maximum iterations run by generalized gradient. Intialized to 100

trace

Output option; trace = TRUE gives verbose output.

epsilon

Error tolerance parameter for convergence criterion; default 1e-5

Value

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

folds

Indices of folds used in cross-validation

lamhat.1se

largest lambda value with cv.err less than or equal to min(cv.err)+ SE

nonzero

Vector giving number of non-zero coefficients for each lambda value

call

The call to timeLagLasso.cv

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
set.seed(3)
n = 50
maxlag = 5
num_rows_needed = n + maxlag + 1
sigma = 4
x = matrix(rnorm(num_rows_needed * 4), nrow = num_rows_needed)
x_new = time_lag_matrix(x, maxlag)
b = c(3,1,1,0,0,
      4,1,0,0,0,
      3,2,1,0,0,
      1,0,0,0,0)
y = x_new %*% b + sigma* rnorm(nrow(x_new))
y = as.vector(y)
y = c(y, rnorm(maxlag + 1))
cvmodel = timeLagLasso.cv(x= x, y = y, maxlag = 5, method = "Solve.QP")

Example output

Loading required package: Matrix
build the matrix for timeLagLasso.cv,  6 observations in y are deleted

orderedLasso documentation built on May 2, 2019, 6:36 a.m.