title: (R) Plot dendrograms BRT models from gbm.step
body: <p>(previously posted <a href="https://stackoverflow.com/questions/27880856/how-to-plot-dendrograms-of-gbm-aka-brt-models-r">here</a>, to the wrong sub, with not enough info, which was closed, I edited, the edits seem to have been deleted, &amp; the post consigned to purgatory, so apologies for re-posting, I don't know whether the previous post can/should be resurrected)</p>
  
  <p>In R, I've run some Boosted Regression Trees, aka Generalized Boosting Models, using <code>dismo</code> which uses <code>gbm</code>. Reproducible example to get people to where I am currently:</p>
  
  <pre><code>library(dismo); data(Anguilla_train)
  angaus.tc5.lr01 &lt;- gbm.step(data=Anguilla_train, gbm.x = 3:13, gbm.y = 2, family = "bernoulli", tree.complexity = 5, learning.rate = 0.01, bag.fraction = 0.5)
  </code></pre>
  
  <p>(From <a href="http://cran.r-project.org/web/packages/dismo/vignettes/brt.pdf" rel="nofollow noreferrer">here</a>). This leaves you with gbm model object "angaus.tc5.lr01".
  I'd like to generate dendrograms of the splits (folds?), i.e. plot the trees, as per De'ath 2007 (see pic, left pane). BUT: De'ath's plot is of a single regression tree, not a boosted regression tree which is the average of potentially thousands of trees each run with a different set of data randomly drawn from the dataset.</p>
  
  <p>User <strong>ckluss</strong> kindly suggested rpart, however that needs the model to be generated by <code>rpart</code> so doesn't work for BRTs/GBMs produced by <code>gbm.step</code>. The same is true of <code>prp</code> from <code>rpart.plot</code>.</p>
  
  <p><code>pretty.gbm.tree</code> in <code>gbm</code> extracts a matrix of info for any one tree selected (try <code>pretty.gbm.tree(angaus.tc5.lr01, i.tree=1)</code> for the first) so I'm wondering if this might be a plausible route to success? E.g. by writing some script which creates an averaged tree matrix using all of the available trees, then converting this into a tree-like object, possibly using some of the methods <a href="https://stats.stackexchange.com/questions/41443/how-to-actually-plot-a-sample-tree-from-randomforestgettree">here</a>.</p>
  
  <p>People have asked varyingly similar questions seemingly with no success elsewhere on the net. BRT models are regularly described as being 'black boxes' so maybe the general opinion is that one shouldn't need/be able/bother to probe into them and display their inner processes.</p>
  
  <p>If anyone knows enough about BRTs / <code>gbm</code> and has any ideas, they'd be gratefully received.
  Thanks.</p>
  
  <p><img src="https://i.stack.imgur.com/I6orv.png" alt="De&#39;ath tree diagram"></p>