Creating FFTs for heart disease

Nathaniel Phillips

2022-07-18

The following example follows the tutorial presented in Phillips et al. (2017) FFTrees: A toolbox to create, visualize, and evaluate fast-and-frugal decision trees. available online at https://journal.sjdm.org/17/17217/jdm17217.pdf

Step 1: Install and load the FFTrees package

You can install FFTrees from CRAN using install.packages() (you only need to do this once)

# Install the package from CRAN
install.packages("FFTrees")

To use the package, you first need to load it into your current R session. You can load the package using library()

# Load the package
library(FFTrees)

The package contains several guides (like this one). To open the main guide, run FFTrees.guide()

# Open the main package guide
FFTrees.guide() 

Step 2: Create FFTs from training data (and test on testing data)

In this example, we will create FFTs from a heart disease data set. The training data are in an object called heart.train, and the testing data are in an object called heart.test. For these data, we will predict diagnosis, a binary criterion that indicates whether each patent has or does not have heart disease (i.e., is at high-risk or low-risk).

To create the FFTrees object, we’ll use the function FFTrees() with two main arguments: formula, a formula indicating the binary criterion as a function of one or more predictors to be considered for the tree (the shorthand formula = diagnosis ~ . means to include all predictors), and data, the training data.

# Create an FFTrees object

heart.fft <- FFTrees(formula = diagnosis ~ .,           # Criterion and (all) predictors
                     data = heart.train,                # Training data
                     data.test = heart.test,            # Testing data
                     main = "Heart Disease",            # General label
                     decision.labels = c("Low-Risk", "High-Risk"))  # Labels for decisions

The resulting trees, decisions, and accuracy statistics are now stored in the FFTrees object called heart.fft.

Other arguments

The following arguments apply to the “ifan” and “dfan” algorithms only:

Step 3: Inspect and summarize FFTs

Now we can inspect and summarize the trees. We will start by printing the object to return basic information to the console:

heart.fft   # Print the object
## Heart Disease
## FFTrees 
## - Trees: 7 fast-and-frugal trees predicting diagnosis
## - Outcome costs: [hi = 0, mi = 1, fa = 1, cr = 0]
## 
## FFT #1: Definition
## [1] If thal = {rd,fd}, decide High-Risk.
## [2] If cp != {a}, decide Low-Risk.
## [3] If ca <= 0, decide Low-Risk, otherwise, decide High-Risk.
## 
## FFT #1: Prediction Accuracy
## Prediction Data: N = 153, Pos (+) = 73 (48%) 
## 
## |         | True + | True - |
## |---------|--------|--------|
## |Decide + | hi 64  | fa 19  | 83
## |Decide - | mi 9   | cr 61  | 70
## |---------|--------|--------|
##             73       80       N = 153
## 
## acc  = 81.7%  ppv  = 77.1%  npv  = 87.1%
## bacc = 82.0%  sens = 87.7%  spec = 76.2%
## E(cost) = 0.183
## 
## FFT #1: Prediction Speed and Frugality
## mcu = 1.73, pci = 0.87

The output tells us several pieces of information:

All statistics can be derived from a 2 x 2 confusion table like the one below. For definitions of all accuracy statistics, look at the accuracy statistic definitions vignette.

Confusion table illustrating frequencies of 4 possible outcomes.

Confusion table illustrating frequencies of 4 possible outcomes.

Step 4: Visualise the final FFT

Plotting FFTrees

To visualize a tree, use plot():

# Plot the best FFT when applied to the test data

plot(heart.fft,              # An FFTrees object
     data = "test")          # Which data to plot? "train" or "test"

Other arguments

# Plot only the tree without accuracy statistics
plot(heart.fft, 
     stats = FALSE)

# Show marginal cue accuracies in ROC space
plot(heart.fft, 
     what = "cues")

Additional Steps

Accesing outputs

An FFTrees object contains many different outputs, to see them all, run names()

# Show the names of all of the outputs in heart.fft

names(heart.fft)
## [1] "criterion_name" "cue_names"      "formula"        "trees"         
## [5] "data"           "params"         "competition"    "cues"

Predicting new data

To predict classifications for a new dataset, use the standard predict() function. For example, here’s how to predict the classifications for data in the heartdisease object (which actually is just a combination of heart.train and heart.test)

# Predict classifications for a new dataset
predict(heart.fft, 
        data = heartdisease)

Defining an FFT in words

Defining an FFT verbally

If you want to define a specific FFT and apply that tree to data, you can define it using the my.tree argument.

# Create an FFT manuly
my.heart.fft <- FFTrees(formula = diagnosis ~.,
                        data = heart.train,
                        data.test = heart.test,
                        main = "Custom Heart FFT",
                        my.tree = "If chol > 350, predict True. 
                                   If cp != {a}, predict False. 
                                   If age <= 35, predict False. Otherwise, predict True")

Here is the result (It’s actually not too bad, although the first node is pretty worthless)

plot(my.heart.fft)

References

Martignon, Laura, Konstantinos V Katsikopoulos, and Jan K Woike. 2008. “Categorization with Limited Resources: A Family of Simple Heuristics.” Journal of Mathematical Psychology 52 (6): 352–61.
Phillips, Nathaniel D, Hansjoerg Neth, Jan K Woike, and Wolfgang Gaissmaier. 2017. FFTrees: A Toolbox to Create, Visualize, and Evaluate Fast-and-Frugal Decision Trees.” Judgment and Decision Making 12 (4): 344–68.