<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/how-important-is-that-variable/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://hagutierrezro.blogspot.com/2016/12/how-important-is-that-variable.html"> Data Literacy - The blog of Andrés Gutiérrez</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>When modeling any phenomena by including explanatory variables that highly relates the variable of interest, one question arises: which of the auxiliary variables have a higher influence on the response? I am not writing about significance testing or something like this. I am just thinking like a researcher who wants to know the ranking of variables that influence the response and their related weight.</p>
<p>There are a variety of methods that try to answer that question. The one inducing this thread is very simple:<strong> isolate units from variables</strong>. Assume a linear model with the following structure (for the sake of simplicity, assume only two explanatory variables):</p>
<p>$$y = \beta_1 x_1 + \beta_2 x_2 + \varepsilon$$</p>
<p>If you assume this model as true and $\beta_i > 0$, then the influence of variable $x_i$, over response $y$ could be found when isolating measure units from variables. Then, one could fit a model over the standardized variables (explanatory and response) and then directly comparing the regression coefficients. Another way to do this is by means of the following expression:</p>
<p>$$I(i) = \frac{\beta_i}{sd(\beta_i)} = \beta_i\frac{ sd(x_i)}{sd(y)}$$</p>
<p>For example, let’s consider the following model $y = -500 x_1 + 50 x_2 + \varepsilon$, then the relative importance of the first and second variable is around 500/(500+50) = 0.9, and 50/(500+50) = 0.1, respectively. The following code shows how to perform this simple analysis in R.</p>
<pre>n <span>&lt;-</span> <span>10000</span><br><br>x1 <span>&lt;-</span> runif(n)<br>x2 <span>&lt;-</span> runif(n)<br>y <span>&lt;-</span> <span>-</span><span>500</span> <span>*</span> x1 <span>+</span> <span>50</span> <span>*</span> x2 <span>+</span> rnorm(n)<br><br>model <span>&lt;-</span> lm(y <span>~</span> <span>0</span> <span>+</span> x1 <span>+</span> x2)<br><br><span># 1a. Standardized betas</span><br>summary(model)<span>$</span>coe[,<span>2</span>]<br>sd.betas <span>&lt;-</span> summary(model)<span>$</span>coe[,<span>2</span>]<br>betas <span>&lt;-</span> model<span>$</span>coefficients<br>imp <span>&lt;-</span> abs(betas)<span>/</span>sd.betas<br>imp <span>&lt;-</span> imp<span>/</span>sum(imp)<br>imp<br><br><span># 1b. Standardized betas</span><br>imp1 <span>&lt;-</span> abs(model<span>$</span>coefficients[<span>1</span>] <span>*</span> sd(x1)<span>/</span>sd(y))<br>imp2 <span>&lt;-</span> abs(model<span>$</span>coefficients[<span>2</span>] <span>*</span> sd(x2)<span>/</span>sd(y))<br><br>imp1 <span>/</span> (imp1 <span>+</span> imp2)<br>imp2 <span>/</span> (imp1 <span>+</span> imp2)<br><br><span># 2. Standardized variables</span><br>model2 <span>&lt;-</span> lm(I(scale(y)) <span>~</span> <span>0</span> <span>+</span> I(scale(x1)) <span>+</span> I(scale(x2)))<br>summary(model2)<br>abs(model2<span>$</span>coefficients)<span>/</span>sum(abs(model2<span>$</span>coefficients))<br><br></pre>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://hagutierrezro.blogspot.com/2016/12/how-important-is-that-variable.html"> Data Literacy - The blog of Andrés Gutiérrez</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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/Utjx47CjbHU"></a></div>