boost-R / mboost

Boosting algorithms for fitting generalized linear, additive and interaction models to potentially high-dimensional data. The current relase version can be found on CRAN (http://cran.r-project.org/package=mboost).
73 stars 27 forks source link

Multinomial should throw a proper error is not called within gamboost function #46

Closed hofnerb closed 7 years ago

hofnerb commented 8 years ago

see #44

mvkorpel commented 8 years ago

The following piece of code may not be exactly what you are looking for (and what the title says), and I'm not sure if this will eliminate all possible crashes. However, ?Family has the following note about Multinomial():

Note that this family does not work with tree-based base-learners at the moment.

To me, it seems useful to check for this combination in mboost_fit():

diff --git a/R/mboost.R b/R/mboost.R
index 6d97af3..45039da 100644
--- a/R/mboost.R
+++ b/R/mboost.R
@@ -52,6 +52,10 @@ mboost_fit <- function(blg, response, weights = rep(1, NROW(response)),

     ### set up the fitting functions
     bl <- lapply(blg, dpp, weights = weights)
+    if (identical("Negative Multinomial Likelihood", family@name) &&
+        any(vapply(bl, inherits, FALSE, what = "bl_tree"))) {
+        stop("Multinomial() does not work with tree-based base-learners")
+    }
     blfit <- lapply(bl, function(x) x$fit)
     fit1 <- blfit[[1]]

This will stop execution in the previously crashing examples of #44.