Linear regression comparable to excel
Show older comments
Hi, I am trying to create a function similar to the LINEST function in excel, which does linear regression. The excel function outputs the following parameters:
- m: slope
- Sm: standard deviation of the slope
- b: intercept
- Sb: standard deviation of the intercept
- Sy: standard deviation about regression
- R^2: coefficient of determination
- SSreg: The regression sum of squares
- SSres: The residual sum of squares
I am aware that I can use polyfit to obtain m and b but I am not sure how to obtain the other without manually inputting formulas. Can anyone help?
I am using a simple set of test data:
- x = [1 2 3 4 5]
- y = [5 15 25 30 35]
Excel gives me the following result: * m: 7.5 * Sm: 0.76 * b: -0.5 * Sb: 2.5 * Sy: 2.4 * R^2: 0.97 * SSreg: 562.5 * SSres: 17.5
I don't expect to get the EXACT same result but something close. Thanks.
Answers (2)
dpb
on 30 Jul 2013
0 votes
If you have Statistics Toolbox there's regstats that's close (missing SS terms) or the LinearModel that has all of 'em. That notwithstanding it's code 'em up yourself or see if there's something on the FEX that has done so already.
Shashank Prasanna
on 30 Jul 2013
0 votes
You can get all those results when you use the LinearModel functionality in the Statistics Toolbox:
Categories
Find more on Linear Predictive Coding 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!