i

R Programming Complete Tutorial

Mathematical Analysis

In case of mathematical computation of Multiple Linear Regression, we will follow the below equations:

Multiple Linear regression equation:y = b0+b1*X1+b2*X2+……+bk*Xk

In the marketing data set, we have three predictors (youtube, facebook, and newspaper) and a target variable (sales). For this specific data set, the equation will be:

sales = b0 + b1*youtube + b2*facebook + b3*newspaper.

We can get the model coefficients b0, b1,b2, and b3 from mathematical equations and that is available in lm() function.

First, we will generate a linear model and display the model summary. We will get the value of the coefficients from the model summary. Then we will compute the sales mathematically and using R predict function. In this example, both are generating the same result.