VOOZH about

URL: https://www.geeksforgeeks.org/r-machine-learning/multiple-linear-regression-using-r/

⇱ Multiple Linear Regression using R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Multiple Linear Regression using R

Last Updated : 11 Jul, 2025

Prerequisite: Simple Linear-Regression using R
Linear Regression: 
It is the basic and commonly used type for predictive analysis. It is a statistical approach for modeling the relationship between a dependent variable and a given set of independent variables.
These are of two types: 
 

  1. Simple linear Regression
  2. Multiple Linear Regression


Let's Discuss Multiple Linear Regression using R.
Multiple Linear Regression : 
It is the most common form of Linear Regression. Multiple Linear Regression basically describes how a single response variable Y depends linearly on a number of predictor variables.
The basic examples where Multiple Regression can be used are as follows: 
 

  1. The selling price of a house can depend on the desirability of the location, the number of bedrooms, the number of bathrooms, the year the house was built, the square footage of the lot, and a number of other factors.
  2. The height of a child can depend on the height of the mother, the height of the father, nutrition, and environmental factors.


Estimation of the Model Parameters 
Consider a multiple linear Regression model with k independent predictor variable x1, x2......, xk, and one response variable y. 
 

πŸ‘ Image


Suppose we have n observation on the k+1 variables and the variable of n should be greater than k. 
 

πŸ‘ Image


The basic goal in least-squares regression is to fit a hyper-plane into (k + 1)-dimensional space that minimizes the sum of squared residuals. 
 

πŸ‘ Image


Before taking the derivative with respect to the model parameters set them equal to zero and derive the least-squares normal equations that the parameters would have to fulfill. 
These equations are formulated with the help of vectors and matrices. 
Let 
 

πŸ‘ Image


The linear Regression model is written in the form as follows: 
 

πŸ‘ Image


In linear regression the least square parameters estimate b 
 

πŸ‘ Image


Imagine the columns of X to be fixed, they are the data for a specific problem and say b to be variable. We want to find the β€œbest” b in the sense that the sum of squared residuals is minimized. 
The smallest that the sum of squares could be is zero. 
 

πŸ‘ Image


Here y is the estimated response vector.
Following R code is used to implement Multiple Linear Regression on following dataset data2.
the dataset looks like this: 
 

πŸ‘ Image


 

πŸ‘ Image

  
 

Output: 
 

πŸ‘ Image


 

πŸ‘ Image


 

Comment
Article Tags:
Article Tags:

Explore