Overview: Creating FFTs with FFTrees

knitr::opts_chunk$set(collapse = FALSE, 
                      comment = "#>", 
                      prompt = FALSE,
                      tidy = FALSE,
                      echo = TRUE, 
                      message = FALSE,
                      warning = FALSE,
                      # Default figure options:
                      dpi = 100, 
                      fig.align = 'center',
                      fig.height = 6.0,
                      fig.width  = 6.5, 
                      out.width = "580px")
library(FFTrees)
library(dplyr)
library(testthat)
library(tidyselect)
library(magrittr)
library(knitr)
# URLs:
url_pkg_CRAN   <- "https://CRAN.R-project.org/package=FFTrees"
url_pkg_GitHub <- "https://github.com/ndphillips/FFTrees"
url_pkg_issues <- "https://github.com/ndphillips/FFTrees/issues"

url_JDM_issue <- "https://journal.sjdm.org/vol12.4.html"
url_JDM_html  <- "https://journal.sjdm.org/17/17217/jdm17217.html"
url_JDM_pdf   <- "https://journal.sjdm.org/17/17217/jdm17217.pdf"

url_JDM_doi <- "https://doi.org/10.1017/S1930297500006239"

email_contact <- "Nathaniel.D.Phillips.is@gmail.com"
url_contact   <- "https://www.linkedin.com/in/nathanieldphillips/"

The R package FFTrees [@phillips2017FFTrees; @FFTrees-pkg] makes it easy to create, visualize, and evaluate fast-and-frugal decision trees\ (FFTs). FFTs are simple and transparent decision algorithms for solving binary classification problems in an\ effective and efficient fashion.

Fast-and-Frugal Trees (FFTs)

A fast-and-frugal tree (FFT) [@martignon2003naive] is a set of hierarchical rules for solving binary classification tasks based on very little pieces of information (usually using\ 4 or fewer cues). In contrast to more complex decision trees, each node of an\ FFT has exactly two branches. A branch can either contain another cue (i.e., ask another question) or lead to an exit (i.e., yield a decision or prediction outcome).
Each non-final node of an\ FFT has one exit branch and the final node has two exit branches.

FFTs are simple and effective decision strategies that use minimal information for making decisions in binary classification problems [see @gigerenzer1999fast;@gigerenzer1999good]. FFTs are often preferable to more complex decision strategies (such as logistic regression, LR) because they rarely over-fit data [@gigerenzer2009homo] and are easy to interpret, implement, and communicate in real-world settings [@marewski2012heuristic]. FFTs have been designed to tackle many real world tasks from making fast decisions in emergency rooms [@green1997alters] to detecting depression [@jenny2013simple].

Whereas their performance and success are empirical questions, a key theoretical advantage of FFTs is their transparency to decision makers and anyone aiming to understand and evaluate the details of an algorithm. In the words of @burton2020, "human users could interpret, justify, control, and interact with a fast-and-frugal decision aid" (p.\ 229).

Using the FFTrees package

The FFTrees package makes it easy to produce, display, and evaluate FFTs [@phillips2017FFTrees]. The package's main function is FFTrees() which takes formula\ formula and dataset\ data arguments and returns several FFTs that attempt to classify training cases into criterion classes. The FFTs created can then be used to predict new data to cross-validate their performance.

Here is an example of using the main FFTrees() function to fit FFTs to heart.train data:

# Create a fast-and-frugal tree (FFT) predicting heart disease:
heart.fft <- FFTrees(formula = diagnosis ~.,
                     data = heart.train,
                     data.test = heart.test,
                     main = "Heart Disease",
                     decision.labels = c("Healthy", "Diseased"))

The resulting FFTrees object heart.fft contains 7\ FFTs that were fitted to the heart.test data. To evaluate a tree's predictive performance, we compare its predictions for the un-trained heart.test data with their true criterion values. Here is how we can apply the best training FFT to the heart.test data:

# Visualize predictive performance:
plot(heart.fft, data = "test")

Getting started

To start using the FFTrees package, we recommend studying the Tutorial: Creating FFTs for heart disease. The tutorial illustrates the basics steps of creating, visualizing, and evaluating fast-and-frugal trees (FFTs). The scientific background of FFTs and the development of FFTrees are described in @phillips2017FFTrees (doi\ 10.1017/S1930297500006239 | html | PDF). The following vignettes provide details on related topics and corresponding examples.

Vignettes

Here is a complete list of the vignettes available in the FFTrees package:

| | Vignette | Description | |--:|:------------------------------|:-------------------------------------------------| | | Main guide: FFTrees overview | An overview of the FFTrees package | | 1 | Tutorial: FFTs for heart disease | An example of using FFTrees() to model heart disease diagnosis | | 2 | Accuracy statistics | Definitions of accuracy statistics used throughout the package | | 3 | Creating FFTs with FFTrees() | Details on the main FFTrees() function | | 4 | Manually specifying FFTs | How to directly create FFTs without using the built-in algorithms | | 5 | Visualizing FFTs | Plotting FFTrees objects, from full trees to icon arrays | | 6 | Examples of FFTs | Examples of FFTs from different datasets contained in the package |

Datasets

The FFTrees package contains several datasets ---\ mostly from the UCI Machine Learning Repository\ --- that allow you to address interesting questions when exploring FFTs:

Details about the datasets {-}

When preparing data to be predicted by FFTs, we usually distinguish between several (categorical or numeric) predictors and a (binary) criterion variable. Table\ 1 provides basic information on the datasets included in the FFTrees package (see their documentation for additional details).

Table\ 1: Key information on the datasets included in FFTrees.

## Preparations for applying the describe_data() function to all data sets
## When new data sets are included, add their info so that they will also be shown in the vignette-table!

# List all data sets: 
data_list <- list(blood, breastcancer, car, contraceptive, creditapproval, fertility, forestfires, 
                  heartdisease, iris.v, mushrooms, sonar, titanic, voting, wine) 

# Vector with all names of the data sets:
data_names <- c("blood", "breastcancer", "car", "contraceptive", "creditapproval", "fertility", "forestfires", 
                "heartdisease", "iris.v", "mushrooms", "sonar", "titanic", "voting", "wine")

# Vector with all criterion names:
criterion_names <- c("donation.crit", "diagnosis", "acceptability", "cont.crit", "crit", 
                     "diagnosis","fire.crit", "diagnosis", "virginica", "poisonous", "mine.crit", "survived", "party.crit", "type") 

# Vector with criterion values of interest: 
baseline_values <- c(1, TRUE, "acc", TRUE, TRUE, TRUE, TRUE, 
                     TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, "red")

# Use combined lists/vectors and apply describe_data() to each:
result_list <- mapply(describe_data, data = data_list, 
                      data_name = data_names, criterion_name = criterion_names, 
                      baseline_value = baseline_values, SIMPLIFY = FALSE)

# Combine results in df:
combined_result <- do.call(rbind, result_list)

# Round baseline and NA pct values for brevity:
combined_result$Baseline_pct<- round(combined_result$Baseline_pct, 1)
combined_result$NAs_pct<- round(combined_result$NAs_pct, 2)

# Rename columns:
colnames(combined_result) <- c("Dataset name", 
                               "Number of cases",
                               "Criterion name", 
                               "Baseline (`TRUE`,\\ in\\ %)",
                               "Number of predictors",
                               "Number of NAs", 
                               "NAs (in\\ %)")

# Render the table from the data frame
# use as many items per page as we have data sets
# redefine column names as we like them:

knitr::kable(combined_result, format = "html") 

Citing FFTrees

We had a lot of fun creating FFTrees and hope you like it too! For an accessible introduction to FFTs, we recommend reading our article in the journal Judgment and Decision Making (2017), entitled FFTrees: A toolbox to create, visualize, and evaluate fast-and-frugal decision trees (available in html | PDF\ ).

Citation (in APA format):

When using FFTrees in your own work, please cite our article and spread the word, so that we can continue developing the package.

BibTeX Citation:

@article{FFTrees,
 title = {FFTrees: A toolbox to create, visualize, and evaluate fast-and-frugal decision trees},
 author = {Phillips, Nathaniel D and Neth, Hansjörg and Woike, Jan K and Gaissmaier, Wolfgang},
 year = 2017, 
 journal = {Judgment and Decision Making},
 volume = 12,
 number = 4,
 pages = {344--368},
 url = {https://journal.sjdm.org/17/17217/jdm17217.pdf},
 doi = {10.1017/S1930297500006239}
}

Contact

knitr::include_graphics("../inst/FFTrees_Logo.jpg")

Bibliography



Try the FFTrees package in your browser

Any scripts or data that you put into this service are public.

FFTrees documentation built on June 7, 2023, 5:56 p.m.