Evaluate relative importance of variables in regression using standardized regression coefficients approach in R

We provide effective and economically affordable online training courses for R and Python, click here for more details and course registration !

In linear regression analysis, one may be very interested in relative importance of independent variables, that is, which variable contributes most in explaining the variation of response variable. There are several approaches for this purpose. One of them is standardized regression coefficients, which measure how much change of response variable in standard deviation measure, from one unit change in standard deviation of a given independent variable. To implement this in R programming, we can just scale all variables, including response variable and independent variables first, before inputting them into regression model. Then the regression coefficients are called standardized regression coefficients, which tells the contribution from each variable in the model. Next example show how to carry out this example in RStudio for dataset ‘mtcars’.

#using dataset 'mtcars' in R
data(mtcars)
#show first observations of dataset 'mtcars'
head(mtcars)
                  mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
#create a new data frame 'zmtcars' from 'mtcars', and scale each variable
#so mean and standard deviation of 'zmtcars' is 0 and 1, respectively.
zmtcars <- mtcars[,c("mpg",  "disp", "hp" ,  "drat", "wt" ,  "qsec" )]
zmtcars <- as.data.frame(scale(zmtcars))
#run regression model with 'zmtcars',response variable is 'mpg'
#independent variables are 'disp','hp','drat','wt'
zfit <- lm(mpg ~ disp + hp + drat + wt  , data=zmtcars)
#show standardized regression coefficients from regression
coef(zfit)
#output
 (Intercept)          disp            hp          drat 
 8.397272e-17  7.845695e-02 -3.956993e-01  1.568519e-01 
           wt 
-5.649139e-01 

From standardized regression coefficients after linear regression, we can say that variable ‘wt’ is the most relative important independent variable in explaining response variable ‘mpg’.

For getting more knowledge of R and a preview of our training course, you can watch R tutorial videos on our YouTube channel !

wilsonzhang746

Recent Posts

Download R Course source files

Click here to download R Course source files !

2 months ago

Download Python Course source files

Click here to download Python Course Source Files !

2 months ago

How to create a data frame from nested dictionary with Pandas in Python

For online Python training registration, click here ! Pandas provides flexible ways of generating data…

5 months ago

How to delete columns of a data frame in Python

For online Python training registration, click here ! Data frame is the tabular data object…

5 months ago

Using isin() to check membership of a data frame in Python

Click her for course registration ! When a data frame in Python is created via…

5 months ago

How to assign values to Pandas data frame in Python

We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…

5 months ago