Learn what is multiple linear regression with this simple tutorial explained with formula and an example.
What is Multiple Linear Regression?
Multiple regression is an extension of linear regression. The multiple regression describes the relationship between more than two variables. The variables used in multiple regression is called as predictor and response variable.
Multiple Regression Formula:
Mathematical equation for multiple regression is defined as:
y = a + b1x1 + b2x2 +...bnxn
y is the response variable.
a, b1, b2...bn are the coefficients.
x1, x2, ...xn are the predictor variables.
The lm() function:
When you want to know the relationship model between the predictor and the response variable, the lm() function is used. The below syntax presents the relation between the response variable and predictor variables. This function is most widely used to determine the value of the coefficients using the input data, which is helpful in predicting the given set of predictor variables using the below functions.
lm() function Syntax:
lm(y ̃ x1+x2+x3...,data)
lm() function Example:
Consider an R environment with the data set "mtcars". Use the dataset to compare between the different car models in terms of mileage per gallon (mpg), cylinder displacement ("disp"), horse power("hp"), weight of the car("wt") and some more parameters. Create a subset of these variables from the mtcars data set.
The below formula gives you the relationship between "mpg" as a response variable and "disp","hp" and "wt" as predictor variables.
input <- mtcars[,c("mpg","disp","hp","wt")]
Executing the program....
mpg disp hp wt Suzuki SX4 21.0 170 128 2.647 Toyota Wag 21.0 170 129 2.871 Datsun Go+ 22.8 128 94 2.234 Tata Ecodrive 21.4 268 110 3.493 Honda City+ 18.7 160 147 3.593 Mahindra Scorpio 18.1 255 139 3.103