@Test public void testOneWayTestEqualVars() { logger.info("oneWayTestEqualVars"); TransposeDataCollection transposeDataCollection = new TransposeDataCollection(); transposeDataCollection.put(0, new FlatDataCollection(Arrays.asList(new Object[]{86,79,81,70,84}))); transposeDataCollection.put(1, new FlatDataCollection(Arrays.asList(new Object[]{90,76,88,82,89}))); transposeDataCollection.put(2, new FlatDataCollection(Arrays.asList(new Object[]{82,68,73,71,81}))); double aLevel = 0.05; AssociativeArray2D outputTable = new AssociativeArray2D(); boolean expResult = false; boolean result = Anova.oneWayTestEqualVars(transposeDataCollection, aLevel, outputTable); assertEquals(expResult, result); }
public static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable) { int n = 0; int k = transposeDataCollection.size(); if(k<=1) { throw new IllegalArgumentException("The collection must contain observations from at least 2 groups."); } Map<Object, Integer> nj = new HashMap<>(); double Ymean = 0.0; Map<Object, Double> Yjmean = new HashMap<>(); for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); int m = flatDataCollection.size(); if(m==0) { throw new IllegalArgumentException("The number of observations in each group but be larger than 0."); } nj.put(j, m); n+=m; double sum = Descriptives.sum(flatDataCollection); Yjmean.put(j, sum/m); Ymean+=sum; } if(n-k<=0) { throw new IllegalArgumentException("The number of observations must be larger than the number of groups."); } Ymean/=n; double RSS=0.0; double BSS=0.0; for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); Iterator<Double> it = flatDataCollection.iteratorDouble(); while(it.hasNext()) { RSS+=Math.pow( it.next() - Yjmean.get(j), 2); } BSS+=nj.get(j) * Math.pow( Yjmean.get(j) - Ymean, 2); } double F = (BSS/(k-1))/(RSS/(n-k)); double pvalue = ContinuousDistributions.fCdf(F, k-1, n-k); boolean rejectH0=false; double a=aLevel/2; if(pvalue<=a || pvalue>=(1-a)) { rejectH0=true; } if(outputTable!=null) { double TSS = RSS+BSS; outputTable.clear(); outputTable.put2d("BG", "SSq", BSS); outputTable.put2d("BG", "DF", k-1); outputTable.put2d("BG", "MSq", BSS/(k-1)); outputTable.put2d("BG", "F", F); outputTable.put2d("BG", "p", 1-pvalue); outputTable.put2d("WG", "SSq", RSS); outputTable.put2d("WG", "DF", n-k); outputTable.put2d("WG", "MSq", RSS/(n-k)); outputTable.put2d("R", "SSq", TSS); outputTable.put2d("R", "DF", n-1); } return rejectH0; }
Anova { public static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable) { int n = 0; int k = transposeDataCollection.size(); if(k<=1) { throw new IllegalArgumentException("The collection must contain observations from at least 2 groups."); } Map<Object, Integer> nj = new HashMap<>(); double Ymean = 0.0; Map<Object, Double> Yjmean = new HashMap<>(); for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); int m = flatDataCollection.size(); if(m==0) { throw new IllegalArgumentException("The number of observations in each group but be larger than 0."); } nj.put(j, m); n+=m; double sum = Descriptives.sum(flatDataCollection); Yjmean.put(j, sum/m); Ymean+=sum; } if(n-k<=0) { throw new IllegalArgumentException("The number of observations must be larger than the number of groups."); } Ymean/=n; double RSS=0.0; double BSS=0.0; for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); Iterator<Double> it = flatDataCollection.iteratorDouble(); while(it.hasNext()) { RSS+=Math.pow( it.next() - Yjmean.get(j), 2); } BSS+=nj.get(j) * Math.pow( Yjmean.get(j) - Ymean, 2); } double F = (BSS/(k-1))/(RSS/(n-k)); double pvalue = ContinuousDistributions.fCdf(F, k-1, n-k); boolean rejectH0=false; double a=aLevel/2; if(pvalue<=a || pvalue>=(1-a)) { rejectH0=true; } if(outputTable!=null) { double TSS = RSS+BSS; outputTable.clear(); outputTable.put2d("BG", "SSq", BSS); outputTable.put2d("BG", "DF", k-1); outputTable.put2d("BG", "MSq", BSS/(k-1)); outputTable.put2d("BG", "F", F); outputTable.put2d("BG", "p", 1-pvalue); outputTable.put2d("WG", "SSq", RSS); outputTable.put2d("WG", "DF", n-k); outputTable.put2d("WG", "MSq", RSS/(n-k)); outputTable.put2d("R", "SSq", TSS); outputTable.put2d("R", "DF", n-1); } return rejectH0; } }
Anova { public static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable) { int n = 0; int k = transposeDataCollection.size(); if(k<=1) { throw new IllegalArgumentException("The collection must contain observations from at least 2 groups."); } Map<Object, Integer> nj = new HashMap<>(); double Ymean = 0.0; Map<Object, Double> Yjmean = new HashMap<>(); for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); int m = flatDataCollection.size(); if(m==0) { throw new IllegalArgumentException("The number of observations in each group but be larger than 0."); } nj.put(j, m); n+=m; double sum = Descriptives.sum(flatDataCollection); Yjmean.put(j, sum/m); Ymean+=sum; } if(n-k<=0) { throw new IllegalArgumentException("The number of observations must be larger than the number of groups."); } Ymean/=n; double RSS=0.0; double BSS=0.0; for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); Iterator<Double> it = flatDataCollection.iteratorDouble(); while(it.hasNext()) { RSS+=Math.pow( it.next() - Yjmean.get(j), 2); } BSS+=nj.get(j) * Math.pow( Yjmean.get(j) - Ymean, 2); } double F = (BSS/(k-1))/(RSS/(n-k)); double pvalue = ContinuousDistributions.fCdf(F, k-1, n-k); boolean rejectH0=false; double a=aLevel/2; if(pvalue<=a || pvalue>=(1-a)) { rejectH0=true; } if(outputTable!=null) { double TSS = RSS+BSS; outputTable.clear(); outputTable.put2d("BG", "SSq", BSS); outputTable.put2d("BG", "DF", k-1); outputTable.put2d("BG", "MSq", BSS/(k-1)); outputTable.put2d("BG", "F", F); outputTable.put2d("BG", "p", 1-pvalue); outputTable.put2d("WG", "SSq", RSS); outputTable.put2d("WG", "DF", n-k); outputTable.put2d("WG", "MSq", RSS/(n-k)); outputTable.put2d("R", "SSq", TSS); outputTable.put2d("R", "DF", n-1); } return rejectH0; }  }
Anova { public static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable) { int n = 0; int k = transposeDataCollection.size(); if(k<=1) { throw new IllegalArgumentException("The collection must contain observations from at least 2 groups."); } Map<Object, Integer> nj = new HashMap<>(); double Ymean = 0.0; Map<Object, Double> Yjmean = new HashMap<>(); for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); int m = flatDataCollection.size(); if(m==0) { throw new IllegalArgumentException("The number of observations in each group but be larger than 0."); } nj.put(j, m); n+=m; double sum = Descriptives.sum(flatDataCollection); Yjmean.put(j, sum/m); Ymean+=sum; } if(n-k<=0) { throw new IllegalArgumentException("The number of observations must be larger than the number of groups."); } Ymean/=n; double RSS=0.0; double BSS=0.0; for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); Iterator<Double> it = flatDataCollection.iteratorDouble(); while(it.hasNext()) { RSS+=Math.pow( it.next() - Yjmean.get(j), 2); } BSS+=nj.get(j) * Math.pow( Yjmean.get(j) - Ymean, 2); } double F = (BSS/(k-1))/(RSS/(n-k)); double pvalue = ContinuousDistributions.fCdf(F, k-1, n-k); boolean rejectH0=false; double a=aLevel/2; if(pvalue<=a || pvalue>=(1-a)) { rejectH0=true; } if(outputTable!=null) { double TSS = RSS+BSS; outputTable.clear(); outputTable.put2d("BG", "SSq", BSS); outputTable.put2d("BG", "DF", k-1); outputTable.put2d("BG", "MSq", BSS/(k-1)); outputTable.put2d("BG", "F", F); outputTable.put2d("BG", "p", 1-pvalue); outputTable.put2d("WG", "SSq", RSS); outputTable.put2d("WG", "DF", n-k); outputTable.put2d("WG", "MSq", RSS/(n-k)); outputTable.put2d("R", "SSq", TSS); outputTable.put2d("R", "DF", n-1); } return rejectH0; }  static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable); static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel); static boolean oneWayTestNotEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable); static boolean oneWayTestNotEqualVars(TransposeDataCollection transposeDataCollection, double aLevel); static boolean twoWayTestEqualCellsEqualVars(TransposeDataCollection2D twoFactorDataCollection, double aLevel, AssociativeArray2D outputTable); static boolean twoWayTestEqualCellsEqualVars(TransposeDataCollection2D twoFactorDataCollection, double aLevel); }
Anova { public static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable) { int n = 0; int k = transposeDataCollection.size(); if(k<=1) { throw new IllegalArgumentException("The collection must contain observations from at least 2 groups."); } Map<Object, Integer> nj = new HashMap<>(); double Ymean = 0.0; Map<Object, Double> Yjmean = new HashMap<>(); for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); int m = flatDataCollection.size(); if(m==0) { throw new IllegalArgumentException("The number of observations in each group but be larger than 0."); } nj.put(j, m); n+=m; double sum = Descriptives.sum(flatDataCollection); Yjmean.put(j, sum/m); Ymean+=sum; } if(n-k<=0) { throw new IllegalArgumentException("The number of observations must be larger than the number of groups."); } Ymean/=n; double RSS=0.0; double BSS=0.0; for(Map.Entry<Object, FlatDataCollection> entry : transposeDataCollection.entrySet()) { Object j = entry.getKey(); FlatDataCollection flatDataCollection = entry.getValue(); Iterator<Double> it = flatDataCollection.iteratorDouble(); while(it.hasNext()) { RSS+=Math.pow( it.next() - Yjmean.get(j), 2); } BSS+=nj.get(j) * Math.pow( Yjmean.get(j) - Ymean, 2); } double F = (BSS/(k-1))/(RSS/(n-k)); double pvalue = ContinuousDistributions.fCdf(F, k-1, n-k); boolean rejectH0=false; double a=aLevel/2; if(pvalue<=a || pvalue>=(1-a)) { rejectH0=true; } if(outputTable!=null) { double TSS = RSS+BSS; outputTable.clear(); outputTable.put2d("BG", "SSq", BSS); outputTable.put2d("BG", "DF", k-1); outputTable.put2d("BG", "MSq", BSS/(k-1)); outputTable.put2d("BG", "F", F); outputTable.put2d("BG", "p", 1-pvalue); outputTable.put2d("WG", "SSq", RSS); outputTable.put2d("WG", "DF", n-k); outputTable.put2d("WG", "MSq", RSS/(n-k)); outputTable.put2d("R", "SSq", TSS); outputTable.put2d("R", "DF", n-1); } return rejectH0; }  static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable); static boolean oneWayTestEqualVars(TransposeDataCollection transposeDataCollection, double aLevel); static boolean oneWayTestNotEqualVars(TransposeDataCollection transposeDataCollection, double aLevel, AssociativeArray2D outputTable); static boolean oneWayTestNotEqualVars(TransposeDataCollection transposeDataCollection, double aLevel); static boolean twoWayTestEqualCellsEqualVars(TransposeDataCollection2D twoFactorDataCollection, double aLevel, AssociativeArray2D outputTable); static boolean twoWayTestEqualCellsEqualVars(TransposeDataCollection2D twoFactorDataCollection, double aLevel);  }