Borrar filtros
Borrar filtros

Linear regression comparable to excel

48 visualizaciones (últimos 30 días)
David Polcari
David Polcari el 30 de Jul. de 2013
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.

Respuestas (2)

dpb
dpb el 30 de Jul. de 2013
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
Shashank Prasanna el 30 de Jul. de 2013
You can get all those results when you use the LinearModel functionality in the Statistics Toolbox:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by