This is a simple adaptation of the getOptcv.glmnet function from glmnet. The code takes a grid of lambda penalties along with a vector of associated mean squared errors (mse), standard errors (se), and the mean squared error from each cross-validation run (fullMSE). From this three potential options for the cross-validated penalty parameter are computed. 1) The lambda that has the minimum average mean squared error across all the cross-validation runs (lambda$lambda.min), 2) The lambda the largest lambda that is associated with an average cross-validated mean squared error within one standard error of the minimum average cross-validated mean squared error (lambda$lambda.1se), and 3) the lamda that is the median of the set of lambdas (lambda$lambda.median).

# S3 method for cv
plot(
  lambdapath,
  mse,
  se,
  lambda,
  save.figure = TRUE,
  OutputFilePath = SCUL.input$OutputFilePath
)

Arguments

lambdapath

A grid of lambdas that is used in each cross-validation run as potential options for the optimal penalty parameter.

mse

A vector of the average mean squared error (average across cross-validation runs) for each given lambda in the lambdapath grid.

se

A vector of the standard error associated with each average mean squared error (average across cross-validation runs) for each given lambda in the lambdapath grid.

lambda

Output from the getOptcv.scul function. Will have three candidate lambdas.

save.figure

Boolean if you want to save figure. Default is to save (save.figure = TRUE).

OutputFilePath

File path prefix if you are saving the figure. Default is file path set in SCUL.inut (OutputFilePath = SCUL.input$OutputFilePath).

fullMSE

A matrix of the mean squared error for each cross-validation run and each given lambda in the lambdapath grid.