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

Labeling of cvrisk plots #96

Closed davidruegamer closed 5 years ago

davidruegamer commented 5 years ago

In the most current version, plot of a cvrisk object has a messed up y label:

data("bodyfat", package = "TH.data")

  ### fit linear model to data
  model <- glmboost(DEXfat ~ ., data = bodyfat, center = TRUE)

  ### AIC-based selection of number of boosting iterations
  maic <- AIC(model)
  maic

  ### inspect coefficient path and AIC-based stopping criterion
  par(mai = par("mai") * c(1, 1, 1, 1.8))
  plot(model)
  abline(v = mstop(maic), col = "lightgray")

  ### 10-fold cross-validation
  cv10f <- cv(model.weights(model), type = "kfold")
  cvm <- cvrisk(model, folds = cv10f, papply = lapply)
  print(cvm)
  mstop(cvm)
  plot(cvm)

This is because in plot.cvrisk the argument ylab = attr(x, "risk") gets only evaluated when ylab is used. By this time, x (the cvrisk object) however is already overwritten and looses the attribute. Here are the correpsonding lines of code:

plot.cvrisk <- function(x, xlab = "Number of boosting iterations",
                        ylab = attr(x, "risk"),
                        ylim = range(x), main = attr(x, "type"), ...) {

    x <- x[, apply(x, 2, function(y) all(!is.na(y))), drop = FALSE] # drops attribute
    cm <- colMeans(x)
    plot(1:ncol(x), cm, ylab = ylab, ylim = ylim,
         type = "n", lwd = 2, xlab = xlab,
         main = main, axes = FALSE, ...)

Will send a pull request in a minute.

davidruegamer commented 5 years ago

And the same applies for the main label in the plot.

hofnerb commented 5 years ago

Thanks a lot @davidruegamer for spotting and fixing!