I have searched stack overflow and have not found any question that really is the same as mine because none really have more than one independent variable. Basically I have an array of datapoints and I want to be able to find a regression equation for those data points. The code I have so far looks like this: (w,x,z are the independent variables and y is the dependent variable)
var dataPoints = [{
"w" : 1, "x" : 2, "z" : 1, "y" : 7
}, {
"w" : 2, "x" : 1, "z" : 4, "y" : 5
}, {
"w" : 1, "x" : 5, "z" : 3, "y" : 2
}, {
"w" : 4, "x" : 3, "z" : 5, "y" : 15
}];
I would like a function that would return a formula object like this:
var regressionEquation = [{
"var" : "w", "power" : 1, "coeff" : "1.5"
}, {
"var" : "x", "power" : 1, "coeff" : "2"
}, {
"var" : "z", "power" : 1, "coeff" : "1"
}];
Is there a way to come up with a regression equation like this without using a loop to step and plug in the values? Is there a way to come up with the regression equation for powers that are more than 1? Thanks in advance.
EDIT
Many people have suggested solving a system of equations made by plugging in the powers. The problem I have with this is when there is more than enough data points to solve for a system of equations. In the examples in the question, I have 3 variables in order to solve the system of equations that people are suggesting, I would need 3 datapoints but I have 4. This leads to a problem because there is more than one solution. There are 4 possible solutions because there are 4 ways to combine the 4 equations into different groups of 3. This would leave me with 4 answers with possibly none of them the best fit to all 4 points.