You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2010/08/29 03:54:29 UTC

[math] Re: Fwd: problem to use OLSMultipleLinearRegression

sahar mohebi wrote:
> Hello
> 
> I have a cubic equation with known arrays of X and Y.the number of arrays
> change between 10 t0 100.
> Now I need to get equation coefficients .
> 
> known x=>double[50]
> known y=>double[50]
> 
> a*x^3+b*x^2+c*x+d -->a=?
>                                      b=?
>                                      c=?
>                                      d=?
> 
> Please guide me to use common math library to solve my problem.
> Thank you in advance.
> 
> sahar
> 

If you want to use ordinary least squares to estimate the
coefficients, you can do this using the OLSMultipleRegression class
as follows:

// Load data into a flat array of concatenated
// rows, each of the form
// y, x, x^2, x^3
double[] design = new double[200];
int j = 0;
for (int i = 0; i < 50; i++) {
    design[j] = y[i];
    double v = x[i];
    design[++j] = v;
    design[++j] = v * v;
    design[++j] = v * v * v;
    j++;
}
// Estimate the model
OLSMultipleLinearRegression model = new OLSMultipleLinearRegression();
model.newSampleData(design, 50, 3);
double[] coef = model.estimateRegressionParameters();

coef[0] is d
coef[1] <-> c
coef[2] <-> b
coef[3] <-> a

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [math] Re: Fwd: problem to use OLSMultipleLinearRegression

Posted by sahar mohebi <sa...@gmail.com>.
Hello

I have a Multiple Linear Regression with known arrays of A[] and B[] and
known c .

known A=>a1,a2,a3,...,an
known B=>b1,b2,b3,...,bn
known c

now I want to calculate array of *x[]* and value of *y* in such regressions:

a1+b1*x1=y
a2+b2*x2=y
a3+b3*x3=y
.
.
.
an+bn*xn=y

That:

x1+x2+x3+.....+xn=c;


Please guide me to use common math library to solve my problem.
Thank you in advance.