package circulardata; /* This is the Range Test. * * Author: Ivan Ramler, Jake Krohn, and Brian Gluth * Date: 29 April 2002 */ import java.io.*; public class RangeTest { //calculateRangePValue method public double calculateRangePValue(CircularData cd, double r) { int obs = cd.getObservations(); double pvalue = 0; //Probablity of W <= r //used to calculate upper bound of summation double x = (2 * Math.PI) / (2 * Math.PI - r); //upper bound of summation, largest integer <= x int upperbound = (int) Math.floor(x); //formula to calculate pvalue for (int k = 1; k < upperbound + 1; k++) { pvalue += Math.pow(-1, k - 1) * (cd.factorial(obs) / (cd.factorial(k) * cd.factorial(obs - k))) * Math.pow((1 - (k * (2 * Math.PI - r) / (2 * Math.PI))), obs - 1); } return pvalue; } //findRangeTestStatistic method public double findRangeTestStatistic(CircularData cd) { int obs = cd.getObservations(); //#observation in data set double[] data = cd.getData(); //array 'data' of data points double r; //circular range - test statistic in radians double w; //circular range - in degrees double maxdiff = 0; //maximum difference between adjacent sorted observations //find maxdiff between adjacent observations (in a linear sense) for (int i = 0; i < obs - 2; i++) { if (maxdiff < data[i + 1] - data[i]) maxdiff = data[i + 1] - data[i]; } //check if difference between last and first observations are larger than current maxdiff if (maxdiff < 360 + data[0] - data[obs - 1]) maxdiff = 360 + data[0] - data[obs - 1]; w = 360 - maxdiff; //get circular range r = (w / 180) * Math.PI; //convert w to radians - Test Statistic return r; } //main method public static void main(String[] args) { //Prints authors' names and date of creation System.out.println("Created by Ivan Ramler, Jake Krohn, and Brian Gluth."); System.out.println("April 2002"); //Declare variables double r; //Circular range in radians - Test Statistic double pvalue = 0.0; //P(W <= r) String fileName = args[0]; File f = new File(fileName); //create objects CircularData data1 = new CircularData(f); RangeTest rt = new RangeTest(); //sort data data1.selectionSort(); //find r r = rt.findRangeTestStatistic(data1); //calculate p-value pvalue = rt.calculateRangePValue(data1, r); //Print test statistic and p-value System.out.println("The Test Statistic for the Range Test is " + r); System.out.println("The Test Statistic in degrees is " + r*180/Math.PI); System.out.println("The P(W <= " + r + ") = " + pvalue); } }