<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/making-fast-good-decisions-with-the-fftrees-r-package/"></div></div><div><a data-url="https://www.r-bloggers.com/making-fast-good-decisions-with-the-fftrees-r-package/" data-counturl="https://www.r-bloggers.com/making-fast-good-decisions-with-the-fftrees-r-package/" data-count="horizontal" data-text="Making fast, good decisions with the FFTrees R package" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://nathanieldphillips.com/2016/08/making-fast-good-decisions-with-the-fftrees-r-package/"> R – Nathaniel D. Phillips, PhD</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" href="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/08/fftblogimage.jpg"><img sizes="(max-width: 959px) 100vw, 959px" alt="fftblogimage" class="wp-image-728" src="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/08/fftblogimage.jpg?resize=456%2C335" data-recalc-dims="1"></a></p>
<p>“…[W]e are suspicious of rapid cognition. We live in a world that assumes that the quality of a decision is directly related to the time and effort that went into making it” Malcom Gladwell, Blink</p>
<p>In his book Blink, Malcolm Gladwell summarises a common misconception about good decision making. According to folk wisdom, the more time, information, and effort you put into a decision, the better it gets. In other words, “More is better.” If you are a doctor making a diagnosis, more medical tests are always better. If you are trying to decide if your new Tinder match is worthy of a date, try to find them on Facebook, Instagram <em>and </em>Snapchat first. If you deciding how to invest in the stock market, get as much data as you can and build a statistical model so complex that it describes the past perfectly.</p>
<p>However, decades of research in cognitive science and machine learning have shown that the “More is better” theory is, in many real-world decisions, flat wrong. In contrast, there are many cases where, as <a target="_blank" href="https://www.mpib-berlin.mpg.de/en/staff/gerd-gigerenzer">Dr. Gerd Gigerenzer</a> has put it, “Less is more.” Why? For two key reasons. The first reason is statistical: Complex decision models with many parameters can lead to <em>overfitting</em>. In essence, overfitting occurs when a model is very good at describing one specific past dataset, but fails in predicting new, unseen data (Gigerenzer &amp; Brighton, 2009). For example, a complex economic model might describe changes in <em>past</em> stock prices very well, but is largely unable to predict future changes. This is why, as Burton Malkiel shows, it is so hard for complex trading algorithms to outperform simple index funds in the stock market (Malkiel, 1999). The second reason is psychological: Even if a complex decision model is good at predicting new data, if a person can’t understand it, or easily implement it in a real-world decision, like a doctor trying to use logistic regression in an emergency room, they won’t use it.</p>
<p>What simple decision rules can people use to make good decisions? One popular class of simple decision rules are <strong>Fast and Frugal Trees</strong> (FFTs, Gigerenzer &amp; Todd, 1999). Fast and frugal trees make very fast decisions based on a few (usually 1 to 5) pieces of information and <em>ignore</em> all other information. In other words, Fast and frugal trees are <em>noncompensatory</em>, meaning that once they make a decision based on a few pieces of information, no additional information can ever change the decision. Because they are so simple to use, they have been used in many real-world decision tasks from making <a target="_blank" href="https://www.researchgate.net/profile/Arthur_Evans/publication/11524821_Triage_of_patients_with_chest_pain_in_the_emergency_department_A_comparative_study_of_physicians%27_decisions/links/0c9605319d9402e9e0000000.pdf">coronary artery disease diagnoses</a> (Green &amp; Mehr, 1997), to <a target="_blank" href="http://www.sciencedirect.com/science/article/pii/S2211368113000533">detecting depression</a> (<a target="_blank" href="https://www.harding-center.mpg.de/en/persons/mirjam-jenny-0">Jenny</a>, Pachur, Williams, Becker &amp; Margraf, 2013). However, lest you think that fast and frugal trees are only useful when time is limited, research has shown that fast and frugal trees can out-predict more complex models in decidedly non-human simulations (Gigerenzer, Czerlinski &amp; Martignon, 1999).</p>
<p>While fast and frugal trees have shown promise, there are currently no off-the-shelf methods to create them. How can you create your own fast and frugal decision trees for your own dataset? Starting today, you can use the <strong>FFTrees</strong> R package <a target="_blank" href="https://cran.rstudio.com/web/packages/FFTrees/index.html">available on CRAN</a>. The main function in the package is fft(), which takes a standard formula and data argument, and returns a fast and frugal tree (fft) object. From this object, you can view its underlying trees, along with many standard classification statistics (e.g.; hit-rate, false alarm rate, AUC) applied to both training and test (i.e.; prediction) datasets. Finally, the function has two alternative classification algorithms, logistic regression and CART, built in, so you can always compare the accuracy of your fast and frugal trees to two gold-standards in the classification literature. If you’re like me, you’ll be amazed at how well simple, transparent fast and frugal trees perform relative to these gold-standards, especially in predicting new data!</p>
<p><strong>The FFTrees package in action</strong></p>
<p>You can install and load the FFTrees package from CRAN:</p>
<pre>
install.packages(&quot;FFTrees&quot;)
library(&quot;FFTrees&quot;)
</pre>
<p>Once you’ve installed the package, you can view the overview vignette by running the code FFTrees.guide(). However, for this blog post I’ll show you how to create fast and frugal trees for predicting breast cancer. The data we’ll use comes from the Wisconsin Breast Cancer Database (<a target="_blank" href="https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Original)">data source</a>). The data is stored as a dataframe with 699 rows, representing 699 patients, and 10 columns. The 10 columns represent 9 physiological measurements, from cell sizes to cell shapes, and 1 binary variable (diagnosis) indicating whether the woman truly does, or does not have breast cancer. Here is how the first few rows of the dataframe look:</p>
<table>
<thead>
<tr>
<th>thickness</th>
<th>cellsize.unif</th>
<th>cellshape.unif</th>
<th>adhesion</th>
<th>epithelial</th>
<th>nuclei.bare</th>
<th>chromatin</th>
<th>nucleoli</th>
<th>mitoses</th>
<th>diagnosis</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>2</td>
<td>1</td>
<td>3</td>
<td>1</td>
<td>1</td>
<td>FALSE</td>
</tr>
<tr>
<td>5</td>
<td>4</td>
<td>4</td>
<td>5</td>
<td>7</td>
<td>10</td>
<td>3</td>
<td>2</td>
<td>1</td>
<td>FALSE</td>
</tr>
<tr>
<td>3</td>
<td>1</td>
<td>1</td>
<td>1</td>
<td>2</td>
<td>2</td>
<td>3</td>
<td>1</td>
<td>1</td>
<td>FALSE</td>
</tr>
<tr>
<td>6</td>
<td>8</td>
<td>8</td>
<td>1</td>
<td>3</td>
<td>4</td>
<td>3</td>
<td>7</td>
<td>1</td>
<td>FALSE</td>
</tr>
<tr>
<td>4</td>
<td>1</td>
<td>1</td>
<td>3</td>
<td>2</td>
<td>1</td>
<td>3</td>
<td>1</td>
<td>1</td>
<td>FALSE</td>
</tr>
<tr>
<td>8</td>
<td>10</td>
<td>10</td>
<td>8</td>
<td>7</td>
<td>10</td>
<td>9</td>
<td>7</td>
<td>1</td>
<td>TRUE</td>
</tr>
</tbody>
</table>
<p>To create a fast and frugal tree from the dataset, we’ll use the fft() function, entering formula = diagnosis ~., meaning that we want to predict diagnosis as a function of (potentially), all other variables, and data = breastcancer. We’ll assign the result to a new object of class fft called breastcancer.fft</p>
<pre>
breastcancer.fft &lt;- fft(formula = diagnosis ~.,
                        data = breastcancer)
</pre>
<p>Now that we’ve created the object, we can print it to the console to get basic information</p>
<pre>
breastcancer.fft
# &quot;An fft object containing 6 trees using 4 cues {cellsize.unif,cellshape.unif,nuclei.bare,epithelial} out of an original 9&quot;
# &quot;Data were trained on 683 exemplars. There were no test data&quot;
# &quot;FFT AUC: (Train = 0.98, Test = NA)&quot;
# &quot;My favorite tree is #3 [Training: HR = 0.93, FAR = 0.05], [Testing: HR = NA, FAR = NA]&quot;
</pre>
<p>The printout tells us that the final fft object contains 6 different trees, and the largest tree only uses 4 of the original 9 cues. To see the best tree, we can simply plot the fft object:</p>
<pre>
plot(breastcancer.fft, 
     main = &quot;Breastcancer FFT&quot;, 
     decision.names = c(&quot;Healthy&quot;, &quot;Cancer&quot;))
</pre>
<p> </p>
<p><a target="_blank" href="https://i0.wp.com/nathanieldphillips.com/wp-content/uploads/2016/08/bcfft-1.png"><img sizes="(max-width: 700px) 100vw, 700px" alt="bcfft" class="wp-image-722" src="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/08/bcfft-1-1024x1024.png?resize=456%2C456" data-recalc-dims="1"></a></p>
<p> </p>
<p>There’s one of our fast and frugal trees! In the top section of the plot, we see that the data had 444 true healthy cases, and 239 true cancer cases. In the middle section, we see the actual tree. The tree then starts by looking at the cue cellsize.u. If the value is less than 3, the tree decides that the person is healthy. If the value is not less than 3, then the tree looks at cellshape. If the cellshape. &lt;= 2, the tree decides the patient is healthy. If cellshape. > 2, the tree decides that the person does have cancer. That’s the whole decision algorithm! Now isn’t that a lot easier to interpret than something like logistic regression? Again, imagine giving <a target="_blank" href="http://logisticregressionanalysis.com/wp/wp-content/ql-cache/quicklatex.com-b32f7aface7affd4b40e7a23318cfded_l3.png">this logistic regression equation</a> to anyone without a degree in statistics.</p>
<p><strong>Performance</strong></p>
<p>Ok, so our fast and frugal tree easy to understand and use, but how well does it perform? The bottom section of the above plot shows a series of performance statistics. On the bottom left hand corner, we can see a classification table, which shows how the tree’s decisions compare to the truth. Entries on the main diagonal (Cor Rej and Hit) correspond to correct decisions, while the other entries correspond to incorrect decisions. As you can see, the tree performed exceptionally well:  it made correct diagnoses in 646 (424 + 222) out of all 683 cases (95% correct). Additional performance statistics, including specificity (1 – false alarm rate), hit rate, d-prime, AUC (area under the curve) are also displayed. Finally, in the bottom right plot, you can see an ROC curve which compares the performance of the trees to CART (in red) and logistic regression (in blue).</p>
<p><strong>Viewing other trees</strong></p>
<p>While this tree did well, it still made some errors in both detecting true cancer cases (i.e.; hit rate) and in correctly rejecting true healthy cases (i.e.; specificity). Now, what if you want a tree that rarely misses true cases, at the cost of additional false alarms? As  Luan, Schooler, &amp; Gigerenzer (2011) have shown, you can easily shift the balance of errors in a fast and frugal tree by adjusting the decisions it makes at each level of a tree. The fft function automatically builds several versions of the same general tree that make different error trade-offs. We can see the performance of each of these trees in the bottom-right ROC curve. Looking at the ROC curve, we can see that tree number 5 has a very high hit-rate, but a smaller specificity. We can look at this tree by adding the tree = 5 argument to plot():</p>
<pre>
plot(breastcancer.fft, 
     main = &quot;Breastcancer FFT&quot;, 
     decision.names = c(&quot;Healthy&quot;, &quot;Cancer&quot;),
     tree = 5)
</pre>
<p> </p>
<p><a target="_blank" href="https://i2.wp.com/nathanieldphillips.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-16-at-15.21.31.png"><img sizes="(max-width: 700px) 100vw, 700px" alt="Screen Shot 2016-08-16 at 15.21.31" class="wp-image-726" src="https://i1.wp.com/nathanieldphillips.com/wp-content/uploads/2016/08/Screen-Shot-2016-08-16-at-15.21.31-1022x1024.png?resize=456%2C457" data-recalc-dims="1"></a></p>
<p> </p>
<p>Here is the resulting tree. As you can see, this tree uses an extra cue called nuclei.bar. This tree has a perfect hit rate of 100% (just as we wanted), but at a cost of a lower specificity of 80%.</p>
<p><strong>Additional arguments</strong></p>
<p>– <em>Cross-validation</em>: The fft() function allows you to easily create trees from a training dataset, and test the performance of the trees with a test dataset (aka, cross-validation). You can do this by either entering an explicit test dataset in the data.test argument, or by randomly splitting the main dataset into a separate training and testing sample with train.p. For example, train.p = .5 will randomly split the data into a 50% training set, which will be used to build the trees, and a 50% test set, which will be used to evaluate their prediction performance.</p>
<pre>
# Create a 50% training and 50% testing dataset with train.p = .5
 breastcancer.test.fft &lt;- fft(formula = diagnosis ~ ,
                              data = breastcancer,
                              train.p = .5)
</pre>
<p> </p>
<p>– <em>Restricting trees: </em>If you want to explicitly decide which cues you want in the tree, you can specify this in the formula argument. For example, the following code will generate a tree from the breast cancer data, but only using cues thickness, mitosis, and adhesion.</p>
<pre>
# Only use 3 cues in the trees
 breastcancer.r.fft &lt;- fft(formula = diagnosis ~ thickness + mitoses + adhesion,
                          data = breastcancer)
</pre>
<p><strong>Summary</strong></p>
<p>The FFTrees package contains lots of other functions for visualising and comparing trees. To see all the details, be sure to check out the package vignettes either in the package or on CRAN (<a target="_blank" href="https://cran.rstudio.com/web/packages/FFTrees/index.html">here</a>). For all you judgment and decision making researchers out there, I will also be presenting the package at the annual meeting of the <a target="_blank" href="http://sjdm.org/">Society for Judgment and Decision Making (SJDM)</a> in Boston in November 2016</p>
<p>The package is also very much in development, so I am grateful for any recommendations, bug-reports, or criticisms. You can post bug-reports at <a target="_blank" href="https://github.com/ndphillips/FFTrees/issues">www.github.com/ndphillips/FFTrees/Issues</a>, or email me directly at Nathaniel.D.Phillips.is@gmail.com</p>
<p><strong>Coauthors</strong></p>
<p>This package was developed in collaboration with <a target="_blank" href="http://www.spds.uni-konstanz.de/people/neth/">Dr. Hansjoerg Neth</a> and <a target="_blank" href="http://www.spds.uni-konstanz.de/?page_id=86">Dr. Wolfgang Gaissmaier</a> at the University of Konstanz, and <a target="_blank" href="https://www.mpib-berlin.mpg.de/en/staff/jan-k-woike">Dr. Jan Woike</a> at the Max Planck Institute for Human Development in Berlin.</p>
<p> <strong>References</strong></p>
<p><span>Gigerenzer, G., &amp; Brighton, H. (2009). Homo heuristicus: Why biased minds make better inferences. <i>Topics in Cognitive Science</i>, <i>1</i>(1), 107–143.</span></p>
<p><span>Gigerenzer, G., &amp; Todd, P. M. (1999). Fast and frugal heuristics: The adaptive toolbox. In <i>Simple heuristics that make us smart</i> (pp. 3–34). Oxford University Press.</span></p>
<p><span>Gigerenzer, G., Czerlinski, J., &amp; Martignon, L. (1999). How good are fast and frugal heuristics? In <i>Decision science and technology</i> (pp. 81–103). Springer.</span></p>
<p>Gladwell, M. (2007). <i>Blink: The power of thinking without thinking</i>. Back Bay Books.</p>
<p><span>Green, L., &amp; Mehr, D. R. (1997). What alters physicians’ decisions to admit to the coronary care unit? <i>Journal of Family Practice</i>, <i>45</i>(3), 219–226.</span></p>
<p><span>Jenny, M. A., Pachur, T., Williams, S. L., Becker, E., &amp; Margraf, J. (2013). Simple rules for detecting depression. <i>Journal of Applied Research in Memory and Cognition</i>, <i>2</i>(3), 149–157.</span></p>
<p>Malkiel, B. G. (1999). <i>A random walk down Wall Street: including a life-cycle guide to personal investing</i>. WW Norton &amp; Company.</p>
<p><span>Marewski, J. N., &amp; Gigerenzer, G. (2012). Heuristic decision making in medicine. <i>Dialogues Clin Neurosci</i>, <i>14</i>(1), 77–89.</span></p>
<p>Luan, S., Schooler, L. J., &amp; Gigerenzer, G. (2011). A signal-detection analysis of fast-and-frugal trees. <i>Psychological Review</i>, <i>118</i>(2), 316.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/making-fast-good-decisions-with-the-fftrees-r-package/"></div></div><div><a data-url="https://www.r-bloggers.com/making-fast-good-decisions-with-the-fftrees-r-package/" data-counturl="https://www.r-bloggers.com/making-fast-good-decisions-with-the-fftrees-r-package/" data-count="vertical" data-text="Making fast, good decisions with the FFTrees R package" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://nathanieldphillips.com/2016/08/making-fast-good-decisions-with-the-fftrees-r-package/"> R – Nathaniel D. Phillips, PhD</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/UEWpE7lJLTg"></a></div>