/* Example data generator for statistical applets 20.June, 1997 Bryan Lewis Department of Mathematics and Computer Science Kent State University This software is in the public domain. History: 24.December, 1997: Added system-independent line-termination 20-July, 1997: Added 3rd field for least squares 11-August, 1997: Added extra y for polynomial least squares examples */ import java.lang.*; public class ExampleData { public String example = new String(); // the example data String newln = System.getProperty("line.separator"); // system-independent line terminator public ExampleData(int index) { // constructor method for t-Test method StringBuffer f1 = new StringBuffer(); StringBuffer f2 = new StringBuffer(); switch (index) { case 1 : { f1.append(fill("Control Formula",24) + fill("New! Improved Formula!",24)); } break; case 2 : { f1.append(fill("Unexposed stength",24) + fill("Strength after exposure",24)); } break; case 3 : { f1.append(fill("Stabilizer A",24) + fill("Stabilizer B",24)); } break; case 4 : { f1.append(fill("Our Formula",24) + fill("Competitive Formula",24)); } break; case 5 : { f1.append(fill("Lab Sample",24) + fill("Production Sample",24)); } break; case 6 : { f1.append(fill("New Lot",24) + fill("Old Lot",24)); } break; case 7 : { f1.append(fill("Dick's formula",24) + fill("Warren's formula",24)); } break; } //now let's generate some data int i = 0; int size = (int) (Math.random() * 15) + 3; double theMiddle = Math.random() * 10 + 5; double center1 = theMiddle + Math.random() * 2 - 1; double center2 = theMiddle + Math.random() * 2 - 1; double spread1 = Math.random() * 2; double spread2 = Math.random() * 2.5; Double dummy = new Double(0); for (i = 0; (i <= size); i++) { dummy = new Double(center1 + Math.random() * spread1); f1.append(newln + fill(dummy.toString(),24)); dummy = new Double(center2 + Math.random() * spread2); f1.append(fill(dummy.toString(),24)); } example = new String(f1); } public ExampleData() { // constructor method for simple regression/correlation tests StringBuffer f3 = new StringBuffer(); //now let's generate some data int i = 0; int size = (int) (Math.random() * 15) + 3; double b = Math.random()*2; double c = Math.random()*.05; double d = Math.random()*0.05-0.025; double e = Math.random()*0.05-0.025; double coeff = Math.random()*3+1; double x = 0; double y = 0; double yy = 0; for (i = 0; i <= size*coeff; i=i+(int)coeff) { x = Math.abs(Math.random()*10-5 + Math.pow(c*i,2) + (b+Math.random()*0.5-0.25)*i); y = Math.abs(i + Math.random()*4-2); yy = y + e*Math.pow(x,2) + d*Math.pow(x,3); f3.append(fill(x,6) + ", " + fill(yy,6) + newln); } example = new String(f3); } public ExampleData(int index, int dummy) { // constructor method for anova (added later) switch (index) { case 2 : { example = "An example two-way ANOVA with replication" + newln + "Dependent Factor A Factor B " + newln + "6.0 1 1 " + newln + "4.0 1 1 " + newln + "5.0 1 1 " + newln + "5.0 1 1 " + newln + "4.0 1 1 " + newln + "5.0 1 2 " + newln + "7.0 1 2 " + newln + "4.0 1 2 " + newln + "6.0 1 2 " + newln + "8.0 1 2 " + newln + "10.0 2 1 " + newln + "8.0 2 1 " + newln + "7.0 2 1 " + newln + "7.0 2 1 " + newln + "9.0 2 1 " + newln + "7.0 2 2 " + newln + "9.0 2 2 " + newln + "12.0 2 2 " + newln + "8.0 2 2 " + newln + "8.0 2 2 " + newln + "7.0 3 1 " + newln + "5.0 3 1 " + newln + "6.0 3 1 " + newln + "5.0 3 1 " + newln + "9.0 3 1 " + newln + "9.0 3 2 " + newln + "7.0 3 2 " + newln + "5.0 3 2 " + newln + "4.0 3 2 " + newln + "6.0 3 2 " + newln + "8.0 4 1 " + newln + "4.0 4 1 " + newln + "6.0 4 1 " + newln + "5.0 4 1 " + newln + "5.0 4 1 " + newln + "5.0 4 2 " + newln + "7.0 4 2 " + newln + "9.0 4 2 " + newln + "7.0 4 2 " + newln + "10.0 4 2 " + newln;} break; case 1 : { example = "An example one-way ANOVA with replication" + newln + "(note that there are not an equal number of replicates for each level)" + newln + "Dependent Factor A " + newln + "7.0 1 " + newln + "11.0 1 " + newln + "9.0 1 " + newln + "4.0 2 " + newln + "6.0 2 " + newln + "8.0 2 " + newln + "5.0 2 " + newln + "2.0 2 " + newln + "10.0 3 " + newln + "8.0 3 " + newln + "6.0 3 " + newln + "8.0 3 "+ newln;} break; case 3 : { example = "An example two-way ANOVA without replication"+ newln + "Dependent Factor A Factor B " + newln + "4.5 1 1 " + newln + "6.4 1 2 " + newln + "7.2 1 3 " + newln + "6.7 1 4 " + newln + "8.8 2 1 " + newln + "7.8 2 2 " + newln + "9.6 2 3 " + newln + "7.0 2 4 " + newln + "5.9 3 1 " + newln + "6.8 3 2 " + newln + "5.7 3 3 " + newln + "5.2 3 4 "+ newln;} break; } } String fill(double d, int l){ // returns a fixed character string representation of the double d String s = " " + d + " "; return s.substring(0,l); } String fill(String d, int l){ // returns a fixed character string representation of the string d String s = " " + d + " "; return s.substring(0,l); } }