Multiple Linear Regression using R
Multiple linear regression is a statistical method that is used to model the relationship between a dependent variable and multiple independent variables. The independent variables are believed to cause the change in the dependent variable. The dependent variable is the variable that is being predicted.
In multiple linear regression, the equation for the line is:
where y is the dependent variable, x1, x2, x3, ..., n are the independent variables, and a, b, c, ... are the coefficients of the independent variables.
The coefficients of the independent variables tell us how much each independent variable affects the dependent variable. For example, if the coefficient of x1 is 1, then we know that for every 1 unit increase in x1, there is a 1 unit increase in y.
Multiple linear regression in R
Multiple linear regression can be performed in R using the lm() function. The lm() function takes three arguments:
- formula: A formula that specifies the relationship between the dependent variable and the independent variables. The formula is in the following format:
where y is the dependent variable and x1, x2, x3, ..., n are the independent variables.
- data: A data frame that contains the data for the dependent variable and the independent variables.
- subset: An optional argument that specifies the subset of data to use.
For example, the following code performs a multiple linear regression to model the relationship between the sales of a product, the price of the product, the advertising budget, and the number of stores that sell the product:
The output of the lm() function is an object that contains the results of the multiple linear regression. You can use the summary() function to view the results of the multiple linear regression:
The summary of the linear regression shows that the coefficients of the independent variables are all statistically significant. This means that all of the independent variables are affecting the dependent variable. The R-squared value is 0.900, which means that 90% of the variation in sales is explained by the linear regression model.
Multiple linear regression is a powerful tool for modeling complex relationships in data, making predictions, and understanding how multiple predictors collectively impact the dependent variable. It is widely used in various fields, including economics, finance, and data science.