Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 10181D682 for ; Tue, 9 Oct 2012 12:19:21 +0000 (UTC) Received: (qmail 39991 invoked by uid 500); 9 Oct 2012 12:19:20 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 38891 invoked by uid 500); 9 Oct 2012 12:19:13 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 38839 invoked by uid 99); 9 Oct 2012 12:19:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Oct 2012 12:19:11 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.139.250.139] (HELO joe.nabble.com) (216.139.250.139) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Oct 2012 12:19:05 +0000 Received: from [192.168.236.139] (helo=joe.nabble.com) by joe.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1TLYlo-0006IM-SC for user@commons.apache.org; Tue, 09 Oct 2012 05:18:44 -0700 Date: Tue, 9 Oct 2012 05:18:44 -0700 (PDT) From: joni8a To: user@commons.apache.org Message-ID: <1349785124863-4640499.post@n4.nabble.com> In-Reply-To: <1349772190508-4640491.post@n4.nabble.com> References: <1349772190508-4640491.post@n4.nabble.com> Subject: Re: Commons Math 3.0 Java Multiple Regression MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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