Le 2012-10-09 14:18, joni8a a écrit :
Hello,

thank you for your advise. I found out that I made something wrong creating
the matrix, so I decided to use

regression.newSampleData(dataSet, 3, 2);

instead of:

regression.newSampleData(y, x);

So I wrote a little program to test it:

public static void testTwo()
    {
        OLSMultipleLinearRegression regression = new
OLSMultipleLinearRegression();
        double[] dataSet = new
double[]{11.0,2.0,4.0,12.0,3.5,2.1,6.3,6.9,0.0};
        regression.newSampleData(dataSet, 3, 2);

        System.out.println("R
Squared:"+regression.calculateTotalSumOfSquares());
    }


Everything works fine, so I went on and tried this way of the regression in
my code like this:

String query = "SELECT "+yData;
        for(int i=0;i<(xData.size());i++)
        {
            query = query+","+xData.get(i);
        }

        query = query + " FROM APP."+stock.stockName;
        System.out.println("QUERY:"+query);

PreparedStatement ps = DBHelperClass.conn.prepareStatement(query,
                ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rsData = DBHelperClass.getSingelton().getDataFromDB(ps);

        rsData.last();
        int numOfVars = 1+(xData.size());
        int dataSize = (rsData.getRow()*numOfVars);
        rsData.beforeFirst();

        double[] dataSet = new double[dataSize] ;




        int i = 0;
        while(rsData.next())
        {
            for(int s=1;s<(numOfVars+1);s++)
            {
                dataSet[i] = Double.parseDouble(rsData.getString(s));
                i++;
            }
        }

       OLSMultipleLinearRegression regression = new
OLSMultipleLinearRegression();
       int nvars = numOfVars-1;
       regression.newSampleData(dataSet, numOfVars, nvars);

I am not sure but shouldn't the previous line read:

regression.newSampleData(dataSet, rsData.getRow(), xData.size());

best regards,
Luc

       System.out.println("REGRESSION
CALCS:"+regression.calculateAdjustedRSquared());


But I get this error:

Exception in thread "AWT-EventQueue-0"
org.apache.commons.math3.exception.DimensionMismatchException: 294 != 9

I dont understand why.... I double checked every variable. I ask for 3 different data, with each 98 entries. So all in all my array needs a size
of: 294 -> Checked this, and it works fine.

Any hints what I could check?




--
View this message in context:

http://apache-commons.680414.n4.nabble.com/Commons-Math-3-0-Java-Multiple-Regression-tp4640491p4640499.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


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

Reply via email to