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

Fine tuning a Hugging Face transformer model for multi-track music generation

To train a PyTorch Transformer for multi-track music generation, the standard paradigm is to convert…

3 weeks ago

what are Transformer, LLM , and GPT

In the field of AI and Natural Language Processing (NLP), The Transformer is the engine…

3 weeks ago

Main framework for PyTorch music generation model

If your goal is purely symbolic melody generation (e.g., generating MIDI files or notes rather…

4 weeks ago

affine_grid() in pytorch

According to PyTorch document, In PyTorch, torch.nn.functional.affine_grid generates a 2D or 3D flow field (sampling…

3 months ago

How to create an Android mobile app with a deep learning AI model ?

Creating an Android mobile app with a deep learning AI model involves several key steps:…

12 months ago

Download source files for R Machine learning

Click here to go to source files for R Machine Learning

1 year ago