<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/the-package-hdm-for-double-selection-inference-with-a-simple-example/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://insightr.wordpress.com/2017/08/04/the-package-hdm-for-double-selection-inference-with-a-simple-example/"> R – insightR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>By Gabriel Vasconcelos</strong></p>
<p>In a late <a rel="nofollow" href="https://insightr.wordpress.com/2017/05/12/problems-of-causal-inference-after-selection-of-controls/" target="_blank">post</a> I discussed the Double Selection (DS), a procedure for inference after selecting controls. I showed an example of the consequences of ignoring the variable selection step discussed in an article by <a rel="nofollow" href="https://arxiv.org/abs/1201.0224" target="_blank">Belloni, Chernozhukov and Hansen</a>.</p>
<p><span></span></p>
<p>Some of the authors of the mentioned article created the hdm package, which implements the double selection using the Rigorous LASSO (RLASSO) to select the controls. The RLASSO uses the theory they developed (instead of cross-validation or information criterion) to select the regularization parameter, normally referred as <img alt="lambda" title="lambda" src="https://s0.wp.com/latex.php?latex=%5Clambda&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">.</p>
<h2>Application</h2>
<p>I am going to show an application based on the package’s vignettes, which is based in an article from Barro and Lee (1994). The hypothesis we want to test is if less developed countries, with lower GDP per capita, grow faster than developed countries. In other words, there is a catch up effect. The model equation is as follows:</p>
<p><img alt="displaystyle y_i=alpha_0d_i+sum_{i=1}^pbeta_jx_{i,j}+varepsilon_i" title="displaystyle y_i=alpha_0d_i+sum_{i=1}^pbeta_jx_{i,j}+varepsilon_i" src="https://s0.wp.com/latex.php?latex=%5Cdisplaystyle+y_i%3D%5Calpha_0d_i%2B%5Csum_%7Bi%3D1%7D%5Ep%5Cbeta_jx_%7Bi%2Cj%7D%2B%5Cvarepsilon_i&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"></p>
<p>where <img alt="y_i" title="y_i" src="https://s0.wp.com/latex.php?latex=y_i&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is the GDP growth rate over a specific decade in country <img alt="i" title="i" src="https://s0.wp.com/latex.php?latex=i&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">, <img alt="d_i" title="d_i" src="https://s0.wp.com/latex.php?latex=d_i&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> is the log of the GDP at the beginning of the decade, <img alt="x_{i,j}" title="x_{i,j}" src="https://s0.wp.com/latex.php?latex=x_%7Bi%2Cj%7D&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> are controls that may affect the GDP. We want to know the effects of <img alt="d_i" title="d_i" src="https://s0.wp.com/latex.php?latex=d_i&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> on <img alt="y_i" title="y_i" src="https://s0.wp.com/latex.php?latex=y_i&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">, which is measured by <img alt="alpha_0" title="alpha_0" src="https://s0.wp.com/latex.php?latex=%5Calpha_0&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex">. If our catch up hypothesis is true, <img alt="alpha_0" title="alpha_0" src="https://s0.wp.com/latex.php?latex=%5Calpha_0&bg=ffffff&%23038;fg=333333&%23038;s=0" class="latex"> must be positive and hopefully significant.</p>
<p>The dataset is available in the package. It has 62 variables and 90 observations. Each observation is a country, but the same country may have more than one observation if analysed in two different decades. The large number of variables will require some variable selection, and I will show what happens if we use a single LASSO selection and the Double Selection. The hdm package does all the DS steps in a single line of code, we do not need to estimate the two selection models and the Post-OLS individually. I will also run a naive OLS will all variables just for illustration.</p>
<pre>library(hdm)
data(&quot;GrowthData&quot;) # = use ?GrowthData for more information = #
dataset=GrowthData[,-2] # = The second column is just a vector of ones = #

# = Naive OLS with all variables = #
# = I will select only the summary line that contains the initial log GDP = #
OLS = summary(lm(Outcome ~., data = dataset))$coefficients[1, ]

# = Single step selection LASSO and Post-OLS = #
# = I will select only the summary line that contains the initial log GDP = #
lasso = rlasso(Outcome~., data = dataset, post = FALSE) # = Run the Rigorous LASSO = #
selected = which(coef(lasso)[-c(1:2)] !=0) # = Select relevant variables = #
formula = paste(c(&quot;Outcome ~ gdpsh465&quot;, names(selected)), collapse = &quot;+&quot;)
SS = summary(lm(formula, data = dataset))$coefficients[1, ]

# = Double Selection = #
DS=rlassoEffects(Outcome~. , I=~gdpsh465, data=dataset)
DS=summary(DS)$coefficients[1,]
(results=rbind(OLS,SS,DS))
</pre>
<pre>##        Estimate Std. Error    t value    Pr(>|t|)
## OLS  0.24716089 0.78450163  0.3150547 0.755056170
## SS   0.31168793 0.09832465  3.1699876 0.002169693
## DS  -0.04432403 0.01531925 -2.8933558 0.003811493
</pre>
<p>The OLS estimate is positive, however the standard error is very big because we have only 90 observations for more than 60 variables. The Single Selection estimate is also positive and, in this case, significant. However, the Double Selection showed a negative and significant coefficient. If the DS is correct, our initial catch up hypothesis is wrong and poor countries grow less than rich countries. We can’t say that the DS is correct for sure, but it is backed up by a strong theory and lots of simulations that show that the SS is problematic. It is very, very unlikely that the SS results are more accurate than the DS. It is very surprising how much the results can change from one case to the other. You should at least be skeptic when you see this type of modelling and the selection of controls is not clear.</p>
<p>The hdm package has several other implementations in this framework such as instrumental variables and logit models and there are also more examples in the package vignette.</p>
<h2>References</h2>
<p>Belloni, A., V. Chernozhukov, and C. Hansen. “Inference on treatment effects after selection amongst high-dimensional controls.” <a rel="nofollow" href="https://arxiv.org/abs/1201.0224" target="_blank">https://arxiv.org/abs/1201.0224</a></p>
<p>Barro, Robert J., and Jong-Wha Lee. “Sources of economic growth.” Carnegie-Rochester conference series on public policy. Vol. 40. North-Holland, 1994. <a rel="nofollow" href="http://www.sciencedirect.com/science/article/pii/0167223194900027" target="_blank">http://www.sciencedirect.com/science/article/pii/0167223194900027</a></p>
<p> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/insightr.wordpress.com/529/" target="_blank"><img border="0" alt="" src="http://feeds.wordpress.com/1.0/comments/insightr.wordpress.com/529/"></a> <img border="0" alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" data-recalc-dims="1"></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://insightr.wordpress.com/2017/08/04/the-package-hdm-for-double-selection-inference-with-a-simple-example/"> R – insightR</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/3xeVUvImcKY" height="1"></a></div>