What is the difference between R squared and adjusted R squared

This recipe explains what is the difference between R squared and adjusted R squared

Recipe Objective

What is the difference between R squared and adjusted R squared.

R squared value also known as coefficient of determination is a statistical performance measure for a regression model. R squared value always lies between 0 and 1 and it must be as high as possible. It explains the proportion of variance for a dependent variable (y) w.r.t an independent variable (x) or variables (x1,x2...) in the regression model. The difference between R squared and adjusted R squared value is that R squared value assumes that all the independent variables considered affect the result of the model, whereas the adjusted R squared value considers only those independent variables which actually have an effect on the performance of the model. When multiple linear regression models are built, say with forward addition method, at each iteration when an independent variable is added, the R squared value will keep increasing, but the adjusted R square will only increase when the variable actually affects the dependent variable. If a variable is non-significant, the R squared value will still increase, but the adjusted R squared value will decrease at that point. This recipe demonstrates an example of the difference between R squared and adjusted R squared value.

Step 1 - Install necessary libraries

install.packages("caTools") # For Linear regression library(caTools)

Step 2 - Define a dataframe

This example tests whether there is a relation between the marks scored by a student due to one factors as follows The dependent variable(y) : marks_scored and the independent variables : no_hours_studied, no_hours_played, attendance.

data <- data.frame(marks_scored = c(35,42,24,27,37), no_hours_studied = c(5,4,2,3,4), no_hours_played = c(3,3,4,3,2), attendance = c(8,8,4,6,9)) print(data)

"Dataframe :"
  marks_scored no_hours_studied no_hours_played attendance
1           35                5               3          8
2           42                4               3          8
3           24                2               4          4
4           27                3               3          6
5           37                4               2          9

Step 3 - Built a linear regression model

model <- lm(marks_scored ~ attendance, data=data) # with a single independent variable summary(model)

"R squared and adjusted R squared value is :" 
Multiple R-squared:  0.7752,	Adjusted R-squared:  0.7003 

model_all <- lm(marks_scored ~ ., data=data) # with all the independent variables in the dataframe summary(model_all)

"R squared and adjusted R squared value is :" 
Multiple R-squared:  0.9867,	Adjusted R-squared:  0.9466

{"mode":"full","isActive":false}

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

OpenCV Project for Beginners to Learn Computer Vision Basics
In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

Tensorflow Transfer Learning Model for Image Classification
Image Classification Project - Build an Image Classification Model on a Dataset of T-Shirt Images for Binary Classification

NLP Project for Multi Class Text Classification using BERT Model
In this NLP Project, you will learn how to build a multi-class text classification model using using the pre-trained BERT model.

Learn Hyperparameter Tuning for Neural Networks with PyTorch
In this Deep Learning Project, you will learn how to optimally tune the hyperparameters (learning rate, epochs, dropout, early stopping) of a neural network model in PyTorch to improve model performance.

Build Customer Propensity to Purchase Model in Python
In this machine learning project, you will learn to build a machine learning model to estimate customer propensity to purchase.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.