glmnet_get.main.model {easy.glmnet} | R Documentation |
Function to choose the glmnet
model most similar to the other models on the list according to the Dice coefficient.
glmnet_get.main.model(x, childname = NULL, verbose = TRUE)
x |
a list of objects of class |
childname |
name of the child of class |
verbose |
(optional) logical, whether to print some messages during execution. |
If there are several instances of the most similar model, it averages them.
An object of class "glmnet_fit"
, representing the model most similar to the other models of the list according to the Dice coefficient.
Joaquim Radua
Sobregrau, P., Bailles, E., Radua, J., Carreno, M., Donaire, A., Setoain, X., Bargallo, N., Rumia, J., Sanchez-Vives, M.V., Pintor, L. (2024) Design and validation of a diagnostic suspicion checklist to differentiate epileptic from psychogenic nonepileptic seizures (PNES-DSC). Journal of Psychosomatic Research, 180, 111656, doi:10.1016/j.jpsychores.2024.111656.
glmnet_predict
for obtaining predictions.
cv
for conducting a cross-validation.
# Create random x (predictors) and y (binary)
x = matrix(rnorm(25000), ncol = 50)
y = 1 * (plogis(apply(x[,1:5], 1, sum) + rnorm(500, 0, 0.1)) > 0.5)
# Predict y via cross-validation
fit_fun = function (x_training, y_training) {
list(
lasso = glmnet_fit(x_training, y_training, family = "binomial")
)
}
predict_fun = function (m, x_test) {
glmnet_predict(m$lasso, x_test)
}
# Only 2 folds to ensure the example runs quickly
res = cv(x, y, family = "binomial", fit_fun = fit_fun, predict_fun = predict_fun, nfolds = 2)
# Show the main model
lasso = glmnet_get.main.model(res$models, "lasso")
cat(
"Model: ~plogis(", round(lasso$a0, 2), "+",
paste0(round(lasso$beta, 2), "*", names(lasso$beta), collapse = " + "),
")\n"
)