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

summary method #2

Closed
sbrockhaus opened this issue Jul 13, 2015 · 0 comments
Closed

summary method #2

sbrockhaus opened this issue Jul 13, 2015 · 0 comments
Assignees

Comments

@sbrockhaus
Copy link
Member

In my opinion it would be nice to have a summary-function for mboostLSS-objects. In the following is code for a summary function (model taken from help).

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)


### summary just tells you that the model is a list
summary(model)


### summary function based on print.mboostLSS() and summary.mboost()
summary.mboostLSS <- function(object, ...) {

  ####cl <- match.call()
  cat("\n")
  cat("\t LSS Models fitted via Model-based Boosting\n")
  cat("\n")
  if (!is.null(attr(object, "call"))) 
    cat("Call:\n", deparse(attr(object, "call")), "\n\n", sep = "")
  cat("Number of boosting iterations: mstop =", mstop(object), "\n")
  cat("Step size: ", sapply(1:length(object), function(i) object[[i]]$control$nu), "\n\n")

  cat("Families:\n")
  lapply(object, function(xi){

    show(xi$family)

    nm <- variable.names(xi)
    selprob <- tabulate(selected(xi), nbins = length(nm)) / length(selected(xi))
    names(selprob) <- names(nm)
    selprob <- sort(selprob, decreasing = TRUE)
    selprob <- selprob[selprob > 0] 
    show(selprob) 

  } )
  invisible(object)
}


### summary of the model 
summary(model)
@hofnerb hofnerb self-assigned this Jul 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants