<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/using-machine-learning-for-causal-inference/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.statworx.com/de/blog/using-machine-learning-for-causal-inference/"> r-bloggers – STATWORX</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Machine Learning (ML) is still an underdog in the field of economics. However, it gets more and more recognition in the recent years. One reason for being an underdog is, that in economics and other social sciences one is not only interested in predicting but also in making causal inference. Thus many &quot;off-the-shelf&quot; ML algorithms are solving a fundamentally different problem. We here at <a rel="nofollow" href="https://www.statworx.com/" target="_blank">STATWORX</a> are also facing a variety of problems e.g. <a rel="nofollow" href="https://www.statworx.com/blog/empirische-bestimmung-von-elastizitaet-teil-1/" target="_blank">dynamic pricing optimization</a>. </p>
<blockquote>
<p>&quot;Prediction by itself is only occasionally sufficient. The post office is happy with any method that predicts correct addresses from hand-written scrawls…[But] most statistical surveys have the identification of causal factors as their ultimate goal.&quot; – Bradley Efron</p>
</blockquote>
<h2>Introduction</h2>
<p>However, the literature of combining ML and casual inferencing is growing by the day. One common problem of causal inference is the estimation of heterogeneous treatment effects. So, we will take a look at three interesting and different approaches for it and focus on a very recent paper by Athey et al. which is forthcoming in &quot;The Annals of Statistics&quot;<sup>1</sup>. </p>
<h3>Model-based Recursive Partitioning</h3>
<p>One of the earlier papers about causal trees is by Zeileis et al., 2008<sup>2</sup>. They describe an algorithm for Model-based Recursive Partitioning (MOB), which looks at recursive partitioning for more complex models. They fit at first a parametric model to the data set, while using Maximum-Likelihood, then test for parameter instability for a set of predefined variables and lastly split the model with the variable regarding the highest parameter instability. Those steps are repeated in each of the daughter nodes till a stopping criterion is reached. However, they do not provide statistical properties for the mob and the partitions are still quite large.</p>
<h3>Bayesian Additive Regression Tree</h3>
<p>Another paper uses Bayesian Additive Regression Tree (BART) for the estimation of heterogeneous treatment effects<sup>3</sup>. Hereby, one advantage of this approach is, that BART can detect and handle interactions and non-linearity in the response surface. It uses a Sum-of-Tree Model. First, a weak-learning tree is grown, whereby the residuals are calculated and the next tree is fitted according to these residuals. Similar to Boosting Algorithms, BART wants do avoid overfitting. This is achieved by using a regularization prior, which restricts overfitting and the contribution of each tree to the final result.</p>
<h2>Generalized Random Forest</h2>
<p>However, this and the next blog post will be mainly focused on the Generalized Random Forest (GRF) by Athey et al., who have already been exploring the possibilities of ML in economics before. It is a method for non-parametric statistical estimation, which uses the basic ideas of the Random Forest. Therefore, it keeps the recursive partitioning, subsampling and random split selection. Nevertheless, the final outcome is not estimated via simple averaging over the trees. The Forest is used to estimate an adaptive weighting function. So, we grow a set of trees and each observation gets weighted equalling how often it falls into the same leaf as the target observation. Those weights are used to solve a &quot;local GMM&quot; model. </p>
<p>Another important piece of the GRF is the split selection algorithm, which emphasizes maximizing heterogeneity. With this framework, a wide variety of applications is possible like quantile regressions but also the estimation of heterogeneous treatment effects. Therefore, the split selection must be suitable for a lot of different purposes. As in Breiman's Random Forest, splits are selected greedily. However, in the case of general moment estimation, we don't have a direct loss criterion to minimize. So instead we want to maximize a criterion ∆ , which favors splits that are increasing the heterogeneity of our in-sample estimation. Maximizing ∆ directly on the other side would be computationally costly, therefore Athey et al. are using a gradient-based approximation for it. This results in a computational performance, similar to standard CART- approaches. </p>
<h2>Comparing the regression forest of GRF to standard random forest</h2>
<p>Athey et al. are claiming in their paper that in the special case of a regression forest, the GRF gets the same results as the standard random forest by Breiman (2001). So, one already implemented estimation method in the <code>grf-package</code><sup>4</sup> is a regression forest. Therefore, I will compare those results, with the random forest implementations of the <code>randomForest</code>-package as well as the implementation of the <code>ranger</code>-packages. For tuning porpuses, I will use a random search with 50 iterations for the <code>randomForest</code> and <code>ranger</code>-package and for the grf the implemented <code>tune_regression_forest()</code>-function. The Algorithms will be benchmarked on 3 data sets, which have been already used in another <a rel="nofollow" href="https://www.statworx.com/blog/regularized-greedy-forest-the-scottish-play-act-ii/" target="_blank">blog post</a>, while using the RMSE to compare the results. For easy handling, I implemented the <code>regression_forest()</code> into the caret framework, which can be found on <a rel="nofollow" href="https://github.com/MarkusBerroth/caret-grf" target="_blank">my GitHub</a>.</p>
<figure>
<table>
<thead>
<tr>
<th>Data Set</th>
<th>Metric</th>
<th>grf</th>
<th>ranger</th>
<th>randomForest</th>
</tr>
</thead>
<tbody>
<tr>
<td>air</td>
<td>RMSE</td>
<td>0.25</td>
<td>0.24</td>
<td>0.24</td>
</tr>
<tr>
<td>bike</td>
<td>RMSE</td>
<td>2.90</td>
<td>2.41</td>
<td>2.67</td>
</tr>
<tr>
<td>gas</td>
<td>RMSE</td>
<td>36.0</td>
<td>32.6</td>
<td>34.4</td>
</tr>
</tbody>
</table>
</figure>
<p>The GRF performs a little bit worse in comparison with the other implementations. However, this could be also due to the tuning of the parameters, because there are more parameters to tune. According to their GitHub, they are planning on improving the <code>tune_regression_forest()</code>-Function.<br>
One advantage of the GRF is, that it produces unbiased confidence intervals for each estimation point. In order to do so, they are performing honest tree splitting, which was first described in their paper about causal trees<sup>5</sup>. With honest stree splitting, one sample is used to make the splits and another distinct sample is used to estimate the coefficients. </p>
<p>However, standard regression is not the exciting part of the Generalized Random Forest. Therefore, I will take a look at how the GRF performs in estimating heterogeneous treatment effects with simulated data and compare it to the estimation results of the MOB and the BART in my next blog post.</p>
<h2>References</h2>
<ol>
<li>Athey, Tibshirani, Wager. Forthcoming.&quot;Generalized Random Forests&quot;</li>
<li>Zeileis, Hothorn, Hornik. 2008.&quot;Model-based Recursive Partitioning&quot; </li>
<li>Hill. 2011.&quot;Bayesian Nonparametric Modeling for Causal Inference&quot;</li>
<li><a rel="nofollow" href="https://github.com/swager/grf" target="_blank">https://github.com/swager/grf</a></li>
<li>Athey and Imbens. 2016.&quot;Recursive partitioning for heterogeneous causal effects.&quot;</li>
</ol>
<div>
<h6>Über den Autor</h6>
<p><img src="https://i2.wp.com/www.statworx.com/wp-content/uploads/markus-1-300x300.jpg?resize=180%2C180&ssl=1" width="180" alt="Markus Berroth" class="wp-user-avatar wp-user-avatar-180" data-recalc-dims="1" height="180"></p>
<div>
<h4>Markus Berroth</h4>
<p>Markus ist Mitglied in unserem Data Science Team und Python Experte. In seiner Freizeit geht er gerne übers Wochenende auf Städtetrips.</p>
</div>
</div>
<p>Der Beitrag <a rel="nofollow" href="https://www.statworx.com/de/blog/using-machine-learning-for-causal-inference/" target="_blank">Using Machine Learning for Causal Inference</a> erschien zuerst auf <a rel="nofollow" href="https://www.statworx.com/de/" target="_blank">STATWORX</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.statworx.com/de/blog/using-machine-learning-for-causal-inference/"> r-bloggers – STATWORX</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/uAT6u0I50xg" height="1"></a></div>