Skip to content

Commit b3dbfdd

Browse files
authored
Merge pull request #93 from wevertonbio/main
Fix error when one of the partitions fails to fit in fit_eval_concave()
2 parents b5bcc37 + e5d40d4 commit b3dbfdd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

R/helpers_calibration.R

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ fit_eval_concave <- function(x, q_grids, data, formula_grid, error_considered, o
389389
data = data_i, weights = weights_i)
390390
}
391391

392+
# If mod_i fail to fit, return NULL
393+
if(inherits(mod_i, "try-error")){
394+
return(NULL)
395+
} else {
396+
392397
pred_i <- if (algorithm == "maxnet") {
393398
as.numeric(predict.glmnet_mx(object = mod_i,
394399
newdata = data$calibration_data,
@@ -414,14 +419,7 @@ fit_eval_concave <- function(x, q_grids, data, formula_grid, error_considered, o
414419
paste0("pval_pROC_at_", omr))
415420
return(proc_omr)
416421
})
417-
# proc_i <- lapply(error_considered, function(omr) {
418-
# proc_omr <- enmpa::proc_enm(test_prediction = suit_val_eval,
419-
# prediction = pred_i,
420-
# threshold = omr)$pROC_summary
421-
# names(proc_omr) <- c(paste0("Mean_AUC_ratio_at_", omr),
422-
# paste0("pval_pROC_at_", omr))
423-
# return(proc_omr)
424-
# })
422+
425423
proc_i <- unlist(proc_i)} else {
426424
#Or fill PROC with NA
427425
proc_i <- rep(NA, length(error_considered) * 2)
@@ -430,7 +428,6 @@ fit_eval_concave <- function(x, q_grids, data, formula_grid, error_considered, o
430428
}
431429

432430

433-
434431
df_eval_q <- if (algorithm == "maxnet") {
435432
data.frame(Partition = i,
436433
t(om_rate),
@@ -448,10 +445,22 @@ fit_eval_concave <- function(x, q_grids, data, formula_grid, error_considered, o
448445
Is_concave = is_c,
449446
row.names = NULL)
450447
}
451-
return(cbind(grid_x, df_eval_q))
448+
return(cbind(grid_x, df_eval_q))} #End of if mod_i is not error
452449
})
453-
names(mods) <- names(data$part_data)
454-
eval_final_q <- do.call("rbind", mods)
450+
451+
if (inherits(mods, "try-error") || any(sapply(mods, is.null))) {
452+
is_c <- NA
453+
eval_final <- cbind(grid_x,
454+
empty_replicates(error_considered = error_considered,
455+
n_row = length(data$part_data),
456+
replicates = names(data$part_data),
457+
is_c = is_c, algorithm = algorithm))
458+
} else {
459+
# Combine evaluation results
460+
names(mods) <- names(data$part_data)
461+
eval_final_q <- do.call("rbind", mods)
462+
}
463+
455464
eval_final_q_summary <- reorder_stats_columns(eval_stats(eval_final_q,
456465
error_considered,
457466
algorithm),

0 commit comments

Comments
 (0)