Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nullModel

Fit a simple, non-informative model


Description

Fit a single mean or largest class model

Usage

nullModel(x, ...)

## Default S3 method:
nullModel(x = NULL, y, ...)

## S3 method for class 'nullModel'
predict(object, newdata = NULL, type = NULL, ...)

Arguments

x

An optional matrix or data frame of predictors. These values are not used in the model fit

...

Optional arguments (not yet used)

y

A numeric vector (for regression) or factor (for classification) of outcomes

object

An object of class nullModel

newdata

A matrix or data frame of predictors (only used to determine the number of predictions to return)

type

Either "raw" (for regression), "class" or "prob" (for classification)

Details

nullModel emulates other model building functions, but returns the simplest model possible given a training set: a single mean for numeric outcomes and the most prevalent class for factor outcomes. When class probabilities are requested, the percentage of the training set samples with the most prevalent class is returned.

Value

The output of nullModel is a list of class nullModel with elements

call

the function call

value

the mean of y or the most prevalent class

levels

when y is a factor, a vector of levels. NULL otherwise

pct

when y is a factor, a data frame with a column for each class (NULL otherwise). The column for the most prevalent class has the proportion of the training samples with that class (the other columns are zero).

n

the number of elements in y

predict.nullModel returns a either a factor or numeric vector depending on the class of y. All predictions are always the same.

Examples

outcome <- factor(sample(letters[1:2],
                         size = 100,
                         prob = c(.1, .9),
                         replace = TRUE))
useless <- nullModel(y = outcome)
useless
predict(useless, matrix(NA, nrow = 10))

caret

Classification and Regression Training

v6.0-86
GPL (>= 2)
Authors
Max Kuhn [aut, cre], Jed Wing [ctb], Steve Weston [ctb], Andre Williams [ctb], Chris Keefer [ctb], Allan Engelhardt [ctb], Tony Cooper [ctb], Zachary Mayer [ctb], Brenton Kenkel [ctb], R Core Team [ctb], Michael Benesty [ctb], Reynald Lescarbeau [ctb], Andrew Ziem [ctb], Luca Scrucca [ctb], Yuan Tang [ctb], Can Candan [ctb], Tyler Hunt [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.