commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joni8a <jon...@yahoo.de>
Subject Re: Commons Math 3.0 Java Multiple Regression
Date Tue, 09 Oct 2012 12:18:44 GMT
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);
       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-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message