predict.ocf: Prediction Method for ocf Objects

View source: R/generic-s3.R

predict.ocfR Documentation

Prediction Method for ocf Objects

Description

Prediction method for class ocf.

Usage

## S3 method for class 'ocf'
predict(object, data = NULL, type = "response", ...)

Arguments

object

An ocf object.

data

Data set of class data.frame. It must contain at least the same covariates used to train the forests. If data is NULL, then object$full_data is used.

type

Type of prediction. Either "response" or "terminalNodes".

...

Further arguments passed to or from other methods.

Details

If type == "response", the routine returns the predicted conditional class probabilities and the predicted class labels. If forests are honest, the predicted probabilities are honest.

If type == "terminalNodes", the IDs of the terminal node in each tree for each observation in data are returned.

Value

Desired predictions.

Author(s)

Riccardo Di Francesco

References

  • Di Francesco, R. (2025). Ordered Correlation Forest. Econometric Reviews, 1–17. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/07474938.2024.2429596")}.

See Also

ocf, marginal_effects

Examples

## Generate synthetic data.
set.seed(1986)

data <- generate_ordered_data(100)
sample <- data$sample
Y <- sample$Y
X <- sample[, -1]

## Training-test split.
train_idx <- sample(seq_len(length(Y)), floor(length(Y) * 0.5))

Y_tr <- Y[train_idx]
X_tr <- X[train_idx, ]

Y_test <- Y[-train_idx]
X_test <- X[-train_idx, ]

## Fit ocf on training sample.
forests <- ocf(Y_tr, X_tr)

## Predict on test sample.
predictions <- predict(forests, X_test)
head(predictions$probabilities)
predictions$classification

## Get terminal nodes.
predictions <- predict(forests, X_test, type = "terminalNodes")
predictions$forest.1[1:10, 1:20] # Rows are observations, columns are forests.


ocf documentation built on April 4, 2025, 4:44 a.m.