Linear Regression plot with Confidence Intervals in MATLAB

Abhilash Singh
Nerd For Tech
Published in
1 min readJul 29, 2020

--

The final output from the code.

In this article, we will discuss a simple code to plot a Linear Regression (LR) curve. The code is written in MATLAB and can be downloaded from my MATLAB repository. You can write to me (abhilash.singh@ieee.org) if you have any question or visit my web page for more updates.

In LR, our main objective is to find the best fitting straight line through the observed values. The best fitting line is called the regression line. The formula for LR is

y = m *x + c

where y is the predicted value, m is the slope of the line, and c is the intercept.

In MATLAB, we have used the regression command given by

[b,bint] = regress(y,x)

were, b is a vector containing the coefficient estimates (only for Multiple LR) and bint is a matrix containing 95% confidence intervals for the coefficient estimates (only for Multiple LR).

You can refer to the publication from where the code is originated.

--

--

Abhilash Singh
Nerd For Tech

Researcher at Indian Institute of Science Education and Research Bhopal. Subscribe my YouTube channel: https://www.youtube.com/channel/UC3YYrAOSNRXvG8Tud3XepYA