You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bias_quantile() wrong with unsorted quantile levels and crashes with na.rm = TRUE #1198
sorts predicted only — quantile_level stays unsorted. interpolate_median() then picks predicted[quantile_level == 0.5] from the reordered predictions (here 3 instead of the true median 2), and max(quantile_level[predicted <= observed]) pairs sorted predictions with unsorted levels. Some permutations happen to error with "Predictions must not be decreasing"; others silently return a wrong value.
Bug 2: Crash when na.rm = TRUE removes all quantile levels on one side of the median
bias_quantile(observed=2, c(NA, NA, 3), c(0.25, 0.5, 0.75), na.rm=TRUE)
#> Error in if (observed == median_prediction) { : argument is of length zero#> In addition: Warning message:#> In max(quantile_level[quantile_level < 0.5]) :#> no non-missing arguments to max; returning -Inf
Cause: after NA removal only quantile_level = 0.75 survives. In interpolate_median() (R/metrics-quantile.R:528), max(quantile_level[quantile_level < 0.5]) is max(numeric(0)), which warns and returns -Inf, so median_prediction has length 0 and the comparison at R/metrics-quantile.R:493 crashes. The top-level asserts at lines 425-426 only check the pre-NA-removal quantile levels, so they do not protect this path.
Intended fix
Sort quantile_level together with predicted (add quantile_level <- quantile_level[order]), so predictions and levels stay paired.
After NA removal, return NA_real_ silently when no quantile level <= 0.5 or none >= 0.5 remains (median non-interpolable) — consistent with na.rm = FALSE, which returns NA_real_ silently.
Activity