formula for coefficients of Least Squares Regression Quad?

71 Views Asked by At

According to Maths Is Fun, the formula for coefficients of Least Squares Regression Line is:

To find the line of best fit for N points:

The Line: y = m×x + b

The formula for the coefficients:

m = (N×Σxy − Σx×Σy) ÷ (N×Σx² − (Σx)²)

b = (Σy − m×Σx) ÷ N

But what is the formula for coefficients of Least Squares Regression Quad?

That is:

To find the curve of best fit for N points:

The curve: y = A×x² + B×x + C

The formula for the coefficients:

A = ?

B = ?

C = ?

My question is what's the formula for the the coefficients A, B, C.

What I have researched so far:

The matrix equation for the quadratic curve is given by: QuadRegCoefMatrix.JPG

So according to this article, the formula can be:

  [ S40  S30  S20 ] [ a ]   [ S21 ]
  [ S30  S20  S10 ] [ b ] = [ S11 ]
  [ S20  S10  S00 ] [ c ]   [ S01 ] 

  D = [ S40  S30  S20 ] 
      [ S30  S20  S10 ] 
      [ S20  S10  S00 ]  
  
    = S40(S20*S00 - S10*S10) - S30(S30*S00 - S10*S20) + S20(S30*S10 - S20*S20)

 Da = [ S21  S30  S20 ]
      [ S11  S20  S10 ] 
      [ S01  S10  S00 ]  

    = S21(S20*S00 - S10*S10) - S11(S30*S00 - S10*S20) + S01(S30*S10 - S20*S20)

 Db = [ S40  S21  S20 ] 
      [ S30  S11  S10 ] 
      [ S20  S01  S00 ]  

    = S40(S11*S00 - S01*S10) - S30(S21*S00 - S01*S20) + S20(S21*S10 - S11*S20)
  
 Dc = [ S40  S30  S21 ] 
      [ S30  S20  S11 ] 
      [ S20  S10  S01 ] 
  
    = S40(S20*S01 - S10*S11) - S30(S30*S01 - S10*S21) + S20(S30*S11 - S20*S21)  

a = Da/D
b = Db/D
c = Dc/D

So basically, the formula is:

a = Da/D
  = (s21*(s20 * s00 - s10 * s10) - 
    s11*(s30 * s00 - s10 * s20) + 
    s01*(s30 * s10 - s20 * s20))
    /
    (s40*(s20 * s00 - s10 * s10) -
     s30*(s30 * s00 - s10 * s20) + 
     s20*(s30 * s10 - s20 * s20));
b = Db/D
  = (s40*(s11 * s00 - s01 * s10) - 
     s30*(s21 * s00 - s01 * s20) + 
     s20*(s21 * s10 - s11 * s20))
     /
     (s40 * (s20 * s00 - s10 * s10) - 
      s30 * (s30 * s00 - s10 * s20) + 
      s20 * (s30 * s10 - s20 * s20));
c = Dc/D
  = s40*(s20 * s01 - s10 * s11) - 
    s30*(s30 * s01 - s10 * s21) + 
    s20*(s30 * s11 - s20 * s21))
    /
    (s40 * (s20 * s00 - s10 * s10) - 
     s30 * (s30 * s00 - s10 * s20) + 
     s20 * (s30 * s10 - s20 * s20));

But I'm still new in this field so I don't know if there is a better formula than this (e.g, more optimized, or some tips like "Note for Programmers" like in this article)? so I think it'd be better to consult to make sure no unexpected error might happen.

1

There are 1 best solutions below

0
On BEST ANSWER

The easiest way is to solve the system using elimination. This would give $$\color{red}{a}=\frac{n \,(\text{S11}\, \text{S30}- \text{S20}\, \text{S21})-\text{S10}\, (\text{S01} \,\text{S30}+\text{S11}\, \text{S20})+\text{S01} \,\text{S20}^2+\text{S10}^2 \,\text{S21}}{n \left(\text{S30}^2-\text{S20}\, \text{S40}\right)+\text{S10}^2 \,\text{S40}-2\, \text{S10}\, \text{S20}\, \text{S30}+\text{S20}^3}$$ $$\color{red}{b}=\frac {n \,(\text{S11}-\color{red}{a}\,\text{S30})+\color{red}{a} \,\text{S10}\, \text{S20}-\text{S01} \,\text{S10} } {n \,\text{S20}-\text{S10}^2 }$$ $$\color{red}{c}=\frac{\text{S01}-\color{red}{a} \,\text{S20}-\color{red}{b}\, \text{S10}}{n}$$