#' Fit an ada boosting model with decision stumps as base learners
#'
#' This function calls \code{ada} with a default \code{control} argument set to
#' \code{rpart.control(maxdepth=1,cp=-1,minsplit=0,xval=0)}
#'
#'
#' @param formula formula object describing the model to be fit, as in
#' \code{ada} function from "ada" package.
#'
#' @param data data.frame object to train the model. The variables named in
#' formula must be present in this object
#'
#' @param ...
#'
#' Further arguments to be passed to \emph{ada} function from "ada" package
#'
#' @return An object of class \emph{adaStump} containing:
#' \item{model }{a data.frame describing the stumps generated by \code{ada}.
#' The object is normally considerably smaller than the equivalent \code{ada}
#' object}
#' \item{type }{Type of execution performed. It is directly inherited
#' from the \code{adaStump} call}
#'
#' @examples
#' #Load Iris
#' data(iris)
#'
#' #Create Variable is Iris as numerical
#' iris$isSetosa <- as.numeric(iris$Species == "setosa")
#'
#' #Split sample in 70 train - 30 test
#' train.ind <- sample(nrow(iris), nrow(iris) * 0.7)
#'
#' #Train model. For obvious reasons, Species variable is not included in the fit
#' fit <- adaStump(isSetosa ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, iris[train.ind,],
#' type = "discrete", iter = 10, nu = 0.05, bag.frac = 0.6)
#' #Prediction
#' predict(fit,iris[-train.ind,])
#'
#' @export
adaStump <- function(formula, data, ...){
args <- list(formula = formula, data = data, control = rpart.control(maxdepth=1,cp=-1,minsplit=0,xval=0), ...)
model <- do.call("ada", args)
ret <- createStumpFrame(model)
ret <- list(model = ret, type = model$model$lossObj$type)
class(ret) <- "adaStump"
return(ret)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.