Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print methods, truncate output of data #11

Closed
sbrockhaus opened this issue Jul 13, 2015 · 1 comment
Closed

print methods, truncate output of data #11

sbrockhaus opened this issue Jul 13, 2015 · 1 comment
Assignees
Labels

Comments

@sbrockhaus
Copy link
Member

@sbrockhaus sbrockhaus commented Jul 13, 2015

I think it would be very nice if the print-methods (print.mboost and print.glmboost) would have a check so that they do not print very long calls directly into the console. This is especially an issue when using gamboostLSS / mboostLSS as in this case at the moment the whole dataset is printed.

A small example in R showing the problem and giving a possible solution (model fit taken from the help of gamboostLSS):

library(gamboostLSS)

### Data generating process:
set.seed(1907)
x1 <- rnorm(1000)
x2 <- rnorm(1000)
x3 <- rnorm(1000)
x4 <- rnorm(1000)
x5 <- rnorm(1000)
x6 <- rnorm(1000)
mu    <- exp(1.5 +1 * x1 +0.5 * x2 -0.5 * x3 -1 * x4)
sigma <- exp(-0.4 * x3 -0.2 * x4 +0.2 * x5 +0.4 * x6)
y <- numeric(1000)
for( i in 1:1000)
  y[i] <- rnbinom(1, size = sigma[i], mu = mu[i])
dat <- data.frame(x1, x2, x3, x4, x5, x6, y)

### linear model with y ~ . for both components: 400 boosting iterations
model <- glmboostLSS(y ~ ., families = NBinomialLSS(), data = dat,
                     control = boost_control(mstop = 400),
                     center = TRUE)

####### very long output in console
model$mu

####### I do not have a nice solution, but something that works for my problem 
####### only one line added to print.glmboost

print.glmboost <- function(x, ...) {

  cat("\n")
  cat("\t Generalized Linear Models Fitted via Gradient Boosting\n")
  cat("\n")
  if (!is.null(x$call)){
    ## EXTRA LINE
    if(length(deparse(x$call$data))>20) x$call$data <- deparse(x$call$data, nlines=1)
    ## EXTRA LINE
    cat("Call:\n", deparse(x$call), "\n\n", sep = "")
  } 
  show(x$family)
  cat("\n")
  cat("Number of boosting iterations: mstop =", mstop(x), "\n")
  cat("Step size: ", x$control$nu, "\n")
  cat("Offset: ", x$offset, "\n")
  cat("\n")
  cat("Coefficients: \n")
  cf <- coef(x)
  attr(x, "offset") <- NULL
  print(cf)
  cat("\n")
  invisible(x)
}

####### now the output of the data is truncated, and I get a nice overview on the model specification
model$mu
@hofnerb
Copy link
Member

@hofnerb hofnerb commented Jul 29, 2015

Use the proposed solution above to make sure that the printed call is not overly rich. In gamboostLSS however, we need to modify the call by replacing the actual data with the name of the data set provided.

hofnerb added a commit that referenced this issue Jul 29, 2015
@hofnerb hofnerb closed this Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.