boost-R / gamboostLSS

Boosting models for fitting generalized additive models for location, shape and scale (GAMLSS) to potentially high dimensional data. The current relase version can be found on CRAN (https://cran.r-project.org/package=gamboostLSS).
26 stars 11 forks source link

summary method #2

Closed sbrockhaus closed 9 years ago

sbrockhaus commented 9 years ago

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)