Skip to contents

The single interface to glmnet::cv.glmnet, which every glmnet fit in the package goes through. It returns the fit, not weights: glmnetWeights extracts the lambda.min coefficient vector from it, while the mr.mash initialisation paths need the coefficient matrix, the intercept row, the lambda sequence and predict() on held-out rows — the same fit-versus-extract split as fitMvsusie and mvsusieWeights.

Usage

fitGlmnetCv(
  x,
  y,
  alpha,
  family = NULL,
  standardize = NULL,
  intercept = NULL,
  nfolds = NULL,
  methodArgs = GlmnetOptions()
)

Arguments

x

Numeric design matrix (samples x features).

y

Response: a vector, or a matrix for family = "mgaussian".

alpha

Elastic-net mixing parameter in [0, 1]: 1 = lasso, 0 = ridge, 0.5 = elastic net. The penalty family is the calling wrapper's to choose, which is why GlmnetOptions() refuses it.

family

glmnet's response family, e.g. "gaussian" or "mgaussian" for a matrix response. NULL leaves glmnet's own default.

standardize

Logical; standardize the columns of x before fitting. NULL leaves glmnet's own default (TRUE).

intercept

Logical; fit an intercept. NULL leaves glmnet's own default (TRUE).

nfolds

Number of cross-validation folds. NULL leaves cv.glmnet's own default (10).

methodArgs

Further arguments forwarded to glmnet::cv.glmnet, built with GlmnetOptions. A bare list is refused, since it cannot be checked against the engine.

Value

The fit object returned by glmnet::cv.glmnet.

Details

The four knobs below are formals rather than GlmnetOptions entries because they are what the package's glmnet call sites genuinely differ on, and leaving them implicit is how three different conventions came to coexist. Each defaults to NULL, meaning the argument is not passed at all and cv.glmnet's own default stands; a value supplied through methodArgs still wins over the caller's, so none of them is refused by the constructor.

Examples

data(eqtlRegionExample)
X <- eqtlRegionExample$X[, 1:30]
y <- eqtlRegionExample$yRes
fit <- fitGlmnetCv(X, y, alpha = 0.5, nfolds = 5)
coef(fit, s = "lambda.min")[1:5]
#> [1] 4.618701e-17 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00