I am looking to perform a polynomial least squares regression and am looking for a C# library to do the calculations for me.
I pass in the data points and the degree of polynomal (2nd order, 3rd order, etc) and it returns either the C0, C1, C2 etc. constant values or the calculated values "predictions".
Note: I am using Least Squares to create some forecasting reports for disk usage, database size and table size.
The least squares principle provides a way of choosing the coefficients effectively by minimising the sum of the squared errors. That is, we choose the values of β0,β1,…,βk β 0 , β 1 , … , β k that minimise T∑t=1ε2t=T∑t=1(yt−β0−β1x1,t−β2x2,t−⋯−βkxk,t)2.
Least Squares Means can be defined as a linear combination (sum) of the estimated effects (means, etc) from a linear model. These means are based on the model used. In the case where the data contains NO missing values, the results of the MEANS and LSMEANS statements are identical.
The method of least squares is a standard approach in regression analysis to approximate the solution of overdetermined systems (sets of equations in which there are more equations than unknowns) by minimizing the sum of the squares of the residuals (a residual being the difference between an observed value and the ...
Here is a link for C# code on to do exactly this: http://www.trentfguidry.net/post/2009/08/01/Linear-Regression-of-Polynomial-Coefficients.aspx
Good luck!
Edit: Apparently the above link is broken. I made another solution awhile back: http://procbits.com/2011/05/02/linear-regression-in-c-sharp-least-squares/
In the general case you want an "optimizer" or "mimimizer". See http://en.wikipedia.org/wiki/Optimization_(mathematics)#Solvers for some exmples. I see that the first link (http://en.wikipedia.org/wiki/IMSL_Numerical_Libraries) claims to have c# support.
Edit: For the limited use that you propose (linear or quadratic polynomials), you could just go to any copy of Numerical Recipies, grab a straight ahead implementation, and translate to your language. A general minimizer is overkill.
But note, also, that polynomials may be poor predictors.
You can check library form ALGLIB under GPL licence 2.0. They have source code for C#, C++,...
http://www.alglib.net/interpolation/leastsquares.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With