What is the regress function doing?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
John
am 24 Dez. 2015
Beantwortet: Star Strider
am 24 Dez. 2015
I don't understand what the regress function is returning. My understanding that it should be the gradient of the line of best fit. For example:
x = [1:5]'
y = [2 4 6 8 10]'
b = regress(y, x)
returns b = 2 as expected, whereas:
x = [1:5]'
y = [5 4 3 2 1]'
b = regress(y, x)
returns b = 0.6364 as opposed to -1.
What is the regress function calculating in this case? Where does this value for b come from?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 24 Dez. 2015
The reason the first data set returned the slope you expected is that the intercept was zero, and your design forced a zero intercept. The reason the second data set is not returning -1 for the slope is because you are forcing it to have an intercept at zero.
If you include an intercept term, you get the expected -1 slope with a y-intercept of +6:
x = [1:5]'
y = [5 4 3 2 1]'
b = regress(y, [x ones(size(x))])
b =
-1
6
0 Kommentare
Weitere Antworten (1)
Matt J
am 24 Dez. 2015
Bearbeitet: Matt J
am 24 Dez. 2015
It is returning x\y
>> x = [1:5]'; y = [5 4 3 2 1]'; b=x\y
b =
0.6364
In other words, the best fit to the equation y=b*x. It is just a coincidence that, in the first case, this happens to also be the slope of the line of best fit.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!