predict.sevt {stagedtrees}R Documentation

Predict method for staged event tree

Description

Predict class values from a staged event tree model.

Usage

## S3 method for class 'sevt'
predict(object, newdata = NULL, class = NULL, prob = FALSE, log = FALSE, ...)

Arguments

object

an object of class sevt with fitted probabilities.

newdata

the newdata to perform predictions

class

character, the name of the variable to use as the class variable, if NULL the first element names(object$tree) will be used.

prob

logical, if TRUE the probabilities of class are returned

log

logical, if TRUE log-probabilities are returned

...

additional parameters, see details

Details

Predict the most probable a posterior value for the class variable given all the other variables in the model. Ties are broken at random and if, for a given vector of predictor variables, all conditional probabilities are 0, NA is returned.

if prob = TRUE, a matrix with number of rows equals to the number of rows in the newdata and number of columns as the number of levels of the class variable is returned. if log = TRUE, log-probabilities are returned.

if prob = FALSE, a vector of length as the number of rows in the newdata with the level with higher estimated probability for each new observations is returned.

Value

A vector of predictions or the corresponding matrix of probabilities.

Examples

DD <- generate_xor_dataset(p = 4, n = 600)
order <- c("C", "X1", "X2", "X3", "X4")
train <- DD[1:500, order]
test <- DD[501:600, order]
model <- full(train)
model <- stages_bhc(model)
pr <- predict(model, newdata = test, class = "C")
table(pr, test$C)
# class values:
predict(model, newdata = test, class = "C")
# probabilities:
predict(model, newdata = test, class = "C", prob = TRUE)
# log-probabilities:
predict(model, newdata = test, class = "C", prob = TRUE, log = TRUE)

[Package stagedtrees version 2.3.0 Index]