get_pred_estimates: Plug-in function for prediction estimates and confidence...

Description Usage Arguments Details Value Examples

View source: R/node_predictions.R

Description

This function provides maximum likelihood point estimates of the outcome for each node in the tree (albeit it can be used with any vector of values). It optionally also computes the confidence intervals around those estimates, using a normal approximation mean ± Zα SE for continuous values and stats::binom.test() exact binomial intervals for discrete (i.e.: character, factor, logical) ones.

Usage

1
get_pred_estimates(values, add_interval = FALSE, interval_level = 0.95)

Arguments

values

Values of the outcome in a tree node.

add_interval

Whether to compute confidence intervals.

interval_level

Confidence level. Must be strictly greater than 0 and less than 1. Defaults to 0.95, which corresponds to a 95 percent confidence interval.

Details

The function is passed as the est_fun argument of tidy_tree(), but works also as stand-alone. This is a default estimation method Estimates can be extremely noisy in decision trees, especially in small terminal nodes; therefore more robust solutions (e.g. Bayesian regularized intervals) are a better choice.

Value

A tibble with the estimates and the interval boundaries, with differences based on the type of input:

Continuous values

One row with the mean and optionally the confidence intervals of the mean

Discrete values

One row for each unique value, identified in the y.level column, with the value probability and the binomial confidence interval around the probability.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Stand alone usage
get_pred_estimates(iris$Species)
get_pred_estimates(iris$Sepal.Width)


## Usage with `tidy_tree()`

mod <- rpart::rpart(iris$Species ~ iris$Sepal.Length, iris)

tidy_tree(mod, add_estimates = T, est_fun = get_pred_estimates, add_interval = T)
## (actually est_fun = get_pred_estimates is redundant since it's the default)

bakaburg1/tidytrees documentation built on Dec. 19, 2021, 6:40 a.m.