predict.brmultinom: Predict method for 'brmultinom' fits

Description Usage Arguments Details Value Examples

View source: R/brmultinom.R

Description

Obtain class and probability predictions from a fitted baseline category logits model.

Usage

1
2
## S3 method for class 'brmultinom'
predict(object, newdata, type = c("class", "probs"), ...)

Arguments

object

a fitted object of class inheriting from "brmultinom".

newdata

optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used.

type

the type of prediction required. The default is "class", which produces predictions of the response category at the covariate values supplied in "newdata", selecting the category with the largest probability; the alternative "probs" returns all category probabilities at the covariate values supplied in "newdata".

...

further arguments passed to or from other methods.

Details

If newdata is omitted the predictions are based on the data used for the fit.

Value

If type = "class" a vector with the predicted response categories; if type = "probs" a matrix of probabilities for all response categories at newdata.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
data("housing", package = "MASS")

# Maximum likelihood using brmultinom with baseline category 'Low'
houseML1 <- brmultinom(Sat ~ Infl + Type + Cont, weights = Freq,
                       data = housing, type = "ML", ref = 1)

# New data
newdata <- expand.grid(Infl = c("Low", "Medium"),
                       Type = c("Tower", "Atrium", "Terrace"),
                       Cont = c("Low", NA, "High"))

## Predictions
sapply(c("class", "probs"), function(what) predict(houseML1, newdata, what))

ikosmidis/brglm2 documentation built on Feb. 10, 2021, 3:27 a.m.