Learn R Programming

orf: ordered random forests

Introduction

The R package orf is an implementation of the Ordered Forest estimator as developed in Lechner & Okasa (2019). The Ordered Forest flexibly estimates the conditional probabilities of models with ordered categorical outcomes (so-called ordered choice models). Additionally to common machine learning algorithms the orf package provides functions for estimating marginal effects as well as statistical inference thereof and thus provides similar output as in standard econometric models for ordered choice. The core forest algorithm relies on the fast C++ forest implementation from the ranger package (Wright & Ziegler, 2017).

Installation

In order to install the latest CRAN released version use:

install.packages("orf", dependencies = c("Imports", "Suggests"))

to make sure all the needed packages are installed as well. Note that if you install the package directly from the source a C++ compiler is required. For Windows users Rtools collection is required too.

Examples

The examples below demonstrate the basic functionality of the orf package.

## Ordered Forest
require(orf)

# load example data
data(odata)

# specify response and covariates
Y <- as.numeric(odata[, 1])
X <- as.matrix(odata[, -1])

# estimate Ordered Forest with default settings
orf_fit <- orf(X, Y, num.trees = 1000, mtry = 2, min.node.size = 5,
                     replace = FALSE, sample.fraction = 0.5,
                     honesty = TRUE, honesty.fraction = 0.5,
                     inference = FALSE, importance = FALSE)

# print output of the Ordered Forest estimation
print(orf_fit)

# show summary of the Ordered Forest estimation
summary(orf_fit, latex = FALSE)

# plot the estimated probability distributions
plot(orf_fit)

# predict with the estimated Ordered Forest
predict(orf_fit, newdata = NULL, type = "probs", inference = FALSE)

# estimate marginal effects of the Ordered Forest
margins(orf_fit, newdata = NULL, eval = "mean", window = 0.1, inference = FALSE)

For a more detailed examples see the package vignette.

References

Copy Link

Version

Install

install.packages('orf')

Monthly Downloads

196

Version

0.1.4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Gabriel Okasa

Last Published

July 23rd, 2022

Functions in orf (0.1.4)

check_honesty

check honesty
check_discrete_Y

check if Y is discrete
check_importance

check importance
check_X

check X data
check_inference

check inference
check_honesty_fraction

check honesty fraction
check_Y

check Y data
check_latex

check latex
check_min_node_size

check min.node.size
check_eval

check evaluation for margins
check_num_trees

check num.trees
get_forest_weights

Get Forest Weights
check_window

check window size
get_honest_C

Get honest predictions (C++)
get_honest

Get Honest Predictions
check_mtry

check mtry
check_newdata

check newdata
check_sample_fraction

check sample.fraction
check_type

check prediction type for predict.orf
orf-package

orf: Ordered Random Forests
odata

Simulated Example Dataset
margins.orf

Marginal Effects for the Ordered Forest
margins_output

Formatted output for marginal effects with inference
predict.orf

Prediction of the Ordered Forest
mse

Mean Squared Error
pred_honest_C

Predict honest predictions (C++)
predict_forest_preds_for_ME

ORF Predictions for Marginal Effects
margins_output_latex

Formatted latex output for marginal effects with inference
pred_weights_C

Predict honest weights (C++)
print.orf.prediction

Print of the Ordered Forest Prediction
pred_orf_variance

Predict ORF Variance
honest_split

honest sample split
predict_forest_weights

Predict Forest Weights
predict_forest_weights_for_ME

ORF Weight Predictions for Marginal Effects
predict_honest

Predict Honest Predictions
rps

Ranked Probability Score
summary.orf

Summary of the Ordered Forest
summary.margins.orf

Summary of the Ordered Forest Marginal Effects
summary.orf.prediction

Summary of the Ordered Forest Prediction
get_orf_variance

Get ORF Variance
print.margins.orf

Print of the Ordered Forest Marginal Effects
print.orf

Print of the Ordered Forest
get_weights_C

Get honest weights (C++)
check_replace

check replace
orf

Ordered Forest Estimator
plot.orf

Plot of the Ordered Forest
margins

Marginal Effects