Post Reply 
HP 48G Linear Regression Best Fit Line
12-11-2021, 02:24 PM
Post: #18
RE: HP 48G Linear Regression Best Fit Line
(12-08-2021 10:41 AM)Rodger Rosenbaum Wrote:  MNH, have a look at the topic "Orthogonal regression" near the bottom of this page: https://en.wikipedia.org/wiki/Deming_regression

There is a flaw with the formula. It assumed slope is always positive.
We should solve the quadratic, then throw away the bad root instead.

Using MNH supplied example (solve orthogonal slope only)
For better accuracy, (X,Y) shifted so that ΣX = ΣY = 0
Shifted data have same regression slope, with simpler calculations.

Calculations done in XCas (data already somewhat shifted, to reduce typing) :

Y := [7.718, 7.053, 6.348, 1.655, 1.271, 1.231,
0.933, 0.418, 0.481, 8.981, 8.372, 0.268, 0.066]:;
X := [1617.749,1555.311,1492.757,1282.045,1161.978,1111.996,
1062.028,962.341,912.131,1742.725,1680.206,862.091,812.156]:;

X, Y := X .- mean(X), Y .- mean(Y) :;
N := len(X);       → 13

B1 := dot(X,Y) / dot(X,X) // slope (ind. var. X)
B2 := dot(X,Y) / dot(Y,Y) // slope (ind. var. Y)

XCas> B1*B2       // R² = 0.93256592979
XCas> [B1, 1/B2] // orthongal fit line slope range

[0.0104144648675, 0.0111675373664]

Note: if R² = 1, orthongal slope = B1

XCas> proot([1, 1/B1-1/B2, -1]       // ≡ proot([1, 1/B1-B1/R², -1])
[-96.0195430799, 0.0104145465384]

Product of roots = -1 implied 2 roots have opposite sign.
The slope we wanted (in bold) has same sign as B1

---

Proof: Let m = orthongal line slope

If we rotate (x,y) data by atan(-m), its linear regression slope must be 0.

X+Y*i = (x+y*i) * (1-m*i) = (x+y*m) + (y-x*m)*i

Let S(XY) = Σ((X-(ΣX/n)) * (Y-(ΣY/n))) = ΣXY - ΣX*ΣY/n
Linear regression slope = S(XY)/S(XX) = 0

S(XY) = 0
ΣXY = ΣX*ΣY / n
Σ((x+y*m)*(y-x*m)) = Σ(x+y*m) * Σ(y-x*m) / n
(1-m²)*Σxy + (Σy² - Σx²)*m = (1-m²)*Σx*Σy/n + m*((Σy)²-(Σx)²)/n
(1-m²) * S(xy) + m * (S(yy) - S(xx)) = 0
m² + (S(xx) - S(yy))/S(xy) * m - 1 = 0
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP 48G Linear Regression Best Fit Line - Albert Chan - 12-11-2021 02:24 PM



User(s) browsing this thread: 1 Guest(s)