How can i develop a Regression line with a confidence level bracket around this line?
4 views (last 30 days)
Show older comments
Tushar Agarwal
on 29 Sep 2016
Commented: Star Strider
on 1 Oct 2016
I have a data set of temperature and energy use.
Temp Energy
I wanted to draw a scatter plot (which i could),and find a confidence level regression line over this scatter plot - any help? I want to see the shaded bracket around the regression line. I have just started with matlab, any help would be golden.
0 Comments
Accepted Answer
Star Strider
on 29 Sep 2016
I would use the polyfit and polyval functions for the regression, and the File Exchange contribution polypredci for the confidence intervals on the regression.
When you download polypredci, put it in your MATLAB user directory. That will allow you to use it as you would use any other function. On Windows computers, this is:
C:\Users\YourUserName\Documents\MATLAB\
4 Comments
Star Strider
on 1 Oct 2016
That is the accepted way to draw confidence intervals on the regression, because the uncertainty in the prediction increases with increasing distance from the mean of the x and y values. The built-in MATLAB routines in the Statistics and Machine Learning Toolbox and all the other statistics packages do the same. More data will make them straighter. (The ‘delta’ values calculated by polyval do the same, although I’ve never been able to figure out exactly what those are.)
How do you want to calculate the confidence intervals? One way might be to take ±1.96 times the standard error (standard deviation divided by the square root of the number of data points) of the y-data and draw lines parallel to the slope at those distances. This was the standard way to draw them back before computers made the precise computation of the confidence intervals easy.
More Answers (0)
See Also
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!