/**
 * This program calculates the linear regression size-estimationg parameters
 * for a set on n programs
 *
 * @version 	$Id: Regression.java,v 1.1 1998/10/14 17:58:32 tfm1584 Exp $ 
 * 
 * @author	Tom M
 *
 * Revisions:
 *		$Log: Regression.java,v $
 *		Revision 1.1  1998/10/14 17:58:32  tfm1584
 *		Initial revision
 *
 *
 */

import java.util.Vector;

public class Regression {

    /**
     * The constructor - this is the main part of the program and calls the
     * functions to calculate the B1 and B0 and print them out
     * out.
     *
     * @param	arguments	String[] passed from main 
     */

    public Regression( String arguments[]) {
	Vector x = new Vector();
	Vector y = new Vector();
	double average;
	double stdDev;
	boolean xend = false;

	/* Load the vector with the actual Doubles from the String array */
	for ( int i = 0; i < arguments.length; i++ ) {
	    if ( arguments[i].equals( "," ) ){
		xend = true;
	    }
	    else {
		if ( !xend ) {
		    x.addElement( Double.valueOf( arguments[ i ] ) ); 
		}
		else {
		    y.addElement( Double.valueOf( arguments[ i ] ) ); 
		}
	    }
	}

	RegressionCalc rc = new RegressionCalc();
	double b1 = rc.calculateB1( x, y );
	double b0 = rc.calculateB0( x,  y, b1 );
	double rSquared = rc.calculateRSquared( x, y, b0, b1 );

	/* print out the x and y data values */
	System.out.print( "X Data = [ " );
	for ( int i = 0; i < x.size(); i++ ) {
	    System.out.print( ((Double)x.elementAt(i)).doubleValue()+ " ");
	}
	System.out.print( "]\nY Data = [ " );
	for ( int i = 0; i < y.size(); i++ ) {
	    System.out.print( ((Double)y.elementAt(i)).doubleValue() +" " );
	}
	System.out.println( "]" );

	/* print out the rest of the calculated values */ 
	System.out.println( "N = " + x.size() );
	System.out.println( "Beta0 = " + b0 );
	System.out.println( "Beta1 = " + b1 );
	System.out.println( "rSquared = " + rSquared );
    }

    /** 
     * the main program - it just creates a new object 
     */

    public static void main( String args[] ) {
        Regression r = new Regression( args );
    }
}