FileDocCategorySizeDatePackage
SimpleRegressionExample.javaAPI DocExample2449Wed May 18 09:39:00 BST 2005com.discursive.jccook.math

SimpleRegressionExample

public class SimpleRegressionExample extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


		SimpleRegression sr = new SimpleRegression();

		// Add data points 		
		sr.addData( 0, 0 );
		sr.addData( 1, 1.2 );
		sr.addData( 2, 2.6 );
		sr.addData( 3, 3.2 );
		sr.addData( 4, 4 );
		sr.addData( 5, 5 );
		
		NumberFormat format = NumberFormat.getInstance();
		
		// Print the value of y when line intersects the y axis
		System.out.println( "Intercept: " + format.format( sr.getIntercept() ) );
		
		// Print the number of data points
		System.out.println( "N: " + sr.getN() );

		// Print the Slope and the Slop Confidence
		System.out.println( "Slope: " + format.format( sr.getSlope() ) );
		System.out.println( "Slope Confidence: " + format.format( sr.getSlopeConfidenceInterval() ) );

		// Print RSquare a measure of relatedness
		System.out.println( "RSquare: " + format.format( sr.getRSquare() ) );

		sr.addData( 400, 100 );
		sr.addData( 300, 105 );
		sr.addData( 350, 70 );
		sr.addData( 200, 50 );
		sr.addData( 150, 300 );
		sr.addData( 50, 500 );
		
		System.out.println( "Intercept: " + format.format( sr.getIntercept() ) );
		System.out.println( "N: " + sr.getN() );
		System.out.println( "Slope: " + format.format( sr.getSlope() ) );
		System.out.println( "Slope Confidence: " + format.format( sr.getSlopeConfidenceInterval() ) );
		System.out.println( "RSquare: " + format.format( sr.getRSquare() ) );