Description Usage Arguments Value Examples
Computes prediction errors for a grid (over lambda and variable subsets) of ridge regression models
1 2 3 4 5 6 7 8 9 10 11 12 13 | grid_ridge(
x,
z,
y,
yz,
var_order = NULL,
lambda = NULL,
nlambda = 100,
lambda.min.ratio = 1e-05,
grid.size = p,
lambda.mult = 1e+05,
errors_mean = TRUE
)
|
x |
design matrix for training |
z |
design matrix for testing |
y |
response for training |
yz |
response for testing |
var_order |
For user-specified ordering of variables. Indices start at 0, start with least important variable and end with most. By default order will be induced from scaling of columns in design matrix |
lambda |
For user-specified sequence of tuning parameter lambda |
nlambda |
Length of automatically generated sequence of tuning parameters lambda |
lambda.min.ratio |
Ratio of max/min lambda for automatically generated sequence of tuning parameters lambda |
grid.size |
Number of subsets of variables for which a solution path will be computed for |
lambda.mult |
Scales the sequence of lambda by a constant |
errors_mean |
Controls whether MSPE or SPE (without dividing by sample size) is returned. Used only for within cv_grid_ridge |
A list of objects:
errors – a matrix of errors for the models (grid.size times nlambda)
lambda – sequence of lambda values used
1 2 3 4 5 6 7 8 9 10 11 | set.seed(1)
X = matrix(0, 50, 500)
Z = matrix(0, 10, 500)
betavec = c(rep(1,5),rep(0,495))
X[ , 1:5 ] = matrix(rnorm(250), 50, 5)
Z[ , 1:5 ] = matrix(rnorm(50), 10, 5)
YZ = as.vector(Z %*% betavec)
Y = as.vector(X %*% betavec)
Y = Y + rnorm(50)
X = X + matrix(rnorm(50*500), 50, 500)
mod1 = grid_ridge(X, Z, Y, YZ, grid.size = 50)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.