Using Bayesian Linear Regression to account for uncertainty

Linear regression is among the most frequently used — and most useful — modelling tool.

While no form of regression analysis can ever approximate reality, it can do quite a good job at both making predictions for the dependent variable and determining the extent to which each independent variable impacts the dependent variable, i.e. the size and significance of each coefficient.

However, traditional linear regression can have shortcomings in that this method cannot really account for uncertainty in the estimates.

However, Bayesian linear regression can serve as a solution to this problem — by providing many different estimates of the coefficient values through repeated simulations. e.g. if we wish to make 20,000 simulations — this method can return 20,000 different regression lines which would account for potential fluctuations in the dependent variable under a wide range of scenarios.

To illustrate this, let’s take a look at how the arm library in R can be used to forecast car sales using a Bayesian linear regression.

The analysis is conducted on a car sales dataset available at Kaggle, which is made available under the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication license.

In the first instance, a linear regression is devised to determine how sales (in thousands) can fluctuate based on the following factors:

  • Engine size
  • Vehicle type
  • Horsepower
  • Wheelbase
  • Width
  • Length
  • Curb Weight
  • Fuel Capacity
  • Fuel Efficiency
  • Power Performance Factor

Here is the linear regression and output results.

Call:
lm(formula = Sales_in_thousands ~ Engine_size + Vehicle_type +
Horsepower + Wheelbase + Width + Length + Curb_weight + Fuel_capacity +
Fuel_efficiency + Power_perf_factor)
Residuals:
Min 1Q Median 3Q Max
-104.47 -29.09 -6.86 14.00 337.19
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -302.7471 154.7623 -1.956 0.05242 .
Engine_size 31.7419 11.0641 2.869 0.00475 **
Vehicle_typePassenger -45.1881 19.3850 -2.331 0.02117 *
Horsepower -0.5830 0.8825 -0.661 0.50990
Wheelbase 3.7231 1.3670 2.724 0.00727 **
Width 0.8454 2.4341 0.347 0.72889
Length 0.7609 0.8295 0.917 0.36054
Curb_weight -63.7597 20.4988 -3.110 0.00226 **
Fuel_capacity -1.1049 2.7603 -0.400 0.68955
Fuel_efficiency ...

Continue reading: https://towardsdatascience.com/bayesian-linear-regression-analysis-of-car-sales-with-arm-in-r-b1147e79a9a4?source=rss—-7f60cf5620c9—4

Source: towardsdatascience.com