Specifying FFTs directly

options(digits = 3)
knitr::opts_chunk$set(echo = TRUE, 
                      fig.width = 7.5, 
                      fig.height = 7.5, 
                      dpi = 100, 
                      out.width = "600px", 
                      fig.align='center', 
                      message = FALSE)
library(FFTrees)

There are two ways to define fast-and-frugal trees manually when using the FFTrees() function, either as a sentence using the my.tree argument (the easier way), or as a dataframe using the tree.definitions argument (the harder way). Both of these methods will bypass the tree construction algorithms built into FFTrees.

my.tree

The first method is to use the my.tree argument, where my.tree is a sentence describing a (single) FFT. When this argument is specified in FFTrees(), the function (specifically wordstoFFT() will try to extract the specified FFT from the argument.

For example, let's look at the columns sex, age and thal in the heartdisease data:

head(heartdisease[c("sex", "age", "thal")])

Here's how we could specify an FFT using these cues as a sentence:

my.tree = "If sex = 1, predict True.
           If age < 45, predict False. 
           If thal = {fd, normal}, predict True. Otherwise, predict False"

Here are some notes on specifying trees manually:

Now, let's pass the my.tree argument to FFTrees() to force apply our FFT to the heartdisease data:

# Pass a verbally defined FFT to FFTrees with the my.tree argument
my.heart.fft <- FFTrees(diagnosis ~.,
                        data = heartdisease,
                        my.tree = "If sex = 1, predict True.
                                   If age < 45, predict False. 
                                   If thal = {fd, normal}, predict True. 
                                   Otherwise, predict False")

Let's see how well our FFT did:

# Plot 
plot(my.heart.fft)

As you can see, this FFT is pretty terrible -- it has a high sensitivity, but a terrible specificity.

Let's see if we can come up with a better one using the cues thal, cp, and ca

# Specify an FFt verbally with the my.tree argument
my.heart.fft <- FFTrees(diagnosis ~.,
                        data = heartdisease,
                        my.tree = "If thal = {rd,fd}, predict True.
                                   If cp != {a}, predict False. 
                                   If ca > 1, predict True. 
                                   Otherwise, predict False")

# Plot 
plot(my.heart.fft)

This one looks much better!



Try the FFTrees package in your browser

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

FFTrees documentation built on July 2, 2020, 2:13 a.m.