Description Usage Arguments Details Value Examples
View source: R/node_predictions.R
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.
1 | get_pred_estimates(values, add_interval = FALSE, interval_level = 0.95)
|
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. |
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.
A tibble with the estimates and the interval boundaries, with differences based on the type of input:
One row with the mean and optionally the confidence intervals of the mean
One row for
each unique value, identified in the y.level
column, with the value
probability and the binomial confidence interval around the probability.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.