//CoData.macroVersion( 6.202);
/**
 * This program gets data from a comma-separated-value
 * ASCII file, runs a polynomial regression, 
 * and prints the regression equation.
 * Copyright 1999-2003 CoHort Software.
 */
public class Regress extends com.cohort.CoData {

  void checkRunError() {
    if (length(getRunError())>0) error(getRunError());
  }

  void error(String s) {
    System.out.println("Error: "+s);
    exit(1);
  }

  public void run() {
    //reset the data file (not necessary, but to be safe)
    runDataReset();
    checkRunError();
    
    //create x and y double columns
    runDataInsertColumns(1, "dd", "X,Y");
    checkRunError();

    //create 10 rows for the data
    runDataInsertRows(1, 10);
    checkRunError();
    
    //put the data in the file
    setDataInt(1, 1, 10); setDataDouble(2, 1, 0.75);
    setDataInt(1, 2, 12); setDataDouble(2, 2, 1.22);
    setDataInt(1, 3, 14); setDataDouble(2, 3, 1.63);
    setDataInt(1, 4, 16); setDataDouble(2, 4, 2.29);
    setDataInt(1, 5, 18); setDataDouble(2, 5, 3.44);
    setDataInt(1, 6, 20); setDataDouble(2, 6, 3.70);
    setDataInt(1, 7, 22); setDataDouble(2, 7, 4.51);
    setDataInt(1, 8, 24); setDataDouble(2, 8, 6.22);
    setDataInt(1, 9, 26); setDataDouble(2, 9, 7.35);
    setDataInt(1,10, 28); setDataDouble(2,10, 8.90);

    //do the regression (0=polynomial, 1=xCol  2=yCol, 2=Degree, ...) 
    runDataRegressionXY(0, 1, 2, 2, "", true, false, 0);
    checkRunError();

    //print the regression equation
    println(dataRegressionXY.getEquation());    
  } 

  public static void main(String args[]) {
    Regress instance=new Regress();
    instance.run();
  }
  
}
