Equations for 2 variable linear regressions

We use a programming language that does not have a linear regression function in it. We have already implemented one variable linear equation:

y = Ax + B

and simply computed the coefficients A and B from the data using a solution similar to this answer .

I know that this problem becomes geometrically more difficult as variables are added, but for our purposes we need to add one more:

z = Ax + By + C

Does anyone have closed-loop equations or code in any language that can solve for A, B and C given an array of x, y and z?

+2
source share
3 answers

so you have three linear equations

k = aX1 + bY1 + cZ1 k = aX2 + bY2 + cZ2 k = aX3 + bY3 + cZ3 

What you can do is rewrite it as matriz

 | x1 y1 z1 | | a | | k | | x2 y2 z2 | | b | = | k | | x3 y3 y3 | | c | | k | 

to perform [abc ] do the following matrix operation

 | a | | x1 y1 z1 | | k | | b | = inverse( | x2 y2 z2 | ) | k | | c | | x3 y3 y3 | | k | 

The formula for the inverse 3x3 matrix can be found here.

+6
source

Yes, this is a simple linear algebra problem if you think about it in the Gil Strang way. Here is a written explanation.

+2
source

Can you use MatLab or do the calculation in your software?

MatLab instructions for multiple regression analysis .

Integration of MatLab with C # .

0
source

All Articles