Linear regression comparable to excel

조회 수: 48 (최근 30일)
David Polcari
David Polcari 2013년 7월 30일
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.

답변 (2개)

dpb
dpb 2013년 7월 30일
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 2013년 7월 30일
You can get all those results when you use the LinearModel functionality in the Statistics Toolbox:

카테고리

Help CenterFile Exchange에서 Support Vector Machine Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by