@Test public void testVariance() { logger.info("variance"); TransposeDataCollection sampleDataCollection = generateSampleDataCollection(); AssociativeArray populationNh = generatePopulationNh(); double expResult = 9.43856960409; double result = StratifiedSampling.variance(sampleDataCollection, populationNh); assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh) { double variance = 0.0; int populationN = 0; double mean = mean(sampleDataCollection, populationNh); for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); if(strataPopulation==null) { throw new IllegalArgumentException("Invalid strata population size."); } populationN+=strataPopulation; variance+=(strataPopulation-1)*SimpleRandomSampling.variance(entry.getValue()); variance+=strataPopulation*Math.pow(SimpleRandomSampling.mean(entry.getValue())-mean,2); } variance/=(populationN-1); return variance; }
StratifiedSampling { public static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh) { double variance = 0.0; int populationN = 0; double mean = mean(sampleDataCollection, populationNh); for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); if(strataPopulation==null) { throw new IllegalArgumentException("Invalid strata population size."); } populationN+=strataPopulation; variance+=(strataPopulation-1)*SimpleRandomSampling.variance(entry.getValue()); variance+=strataPopulation*Math.pow(SimpleRandomSampling.mean(entry.getValue())-mean,2); } variance/=(populationN-1); return variance; } }
StratifiedSampling { public static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh) { double variance = 0.0; int populationN = 0; double mean = mean(sampleDataCollection, populationNh); for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); if(strataPopulation==null) { throw new IllegalArgumentException("Invalid strata population size."); } populationN+=strataPopulation; variance+=(strataPopulation-1)*SimpleRandomSampling.variance(entry.getValue()); variance+=strataPopulation*Math.pow(SimpleRandomSampling.mean(entry.getValue())-mean,2); } variance/=(populationN-1); return variance; }  }
StratifiedSampling { public static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh) { double variance = 0.0; int populationN = 0; double mean = mean(sampleDataCollection, populationNh); for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); if(strataPopulation==null) { throw new IllegalArgumentException("Invalid strata population size."); } populationN+=strataPopulation; variance+=(strataPopulation-1)*SimpleRandomSampling.variance(entry.getValue()); variance+=strataPopulation*Math.pow(SimpleRandomSampling.mean(entry.getValue())-mean,2); } variance/=(populationN-1); return variance; }  static TransposeDataCollection weightedProbabilitySampling(AssociativeArray2D strataFrequencyTable, AssociativeArray nh, boolean withReplacement); static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement); static double mean(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double std(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static double xbarStd(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static AssociativeArray optimumSampleSize(int n, AssociativeArray populationNh, AssociativeArray populationStdh); }
StratifiedSampling { public static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh) { double variance = 0.0; int populationN = 0; double mean = mean(sampleDataCollection, populationNh); for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); if(strataPopulation==null) { throw new IllegalArgumentException("Invalid strata population size."); } populationN+=strataPopulation; variance+=(strataPopulation-1)*SimpleRandomSampling.variance(entry.getValue()); variance+=strataPopulation*Math.pow(SimpleRandomSampling.mean(entry.getValue())-mean,2); } variance/=(populationN-1); return variance; }  static TransposeDataCollection weightedProbabilitySampling(AssociativeArray2D strataFrequencyTable, AssociativeArray nh, boolean withReplacement); static TransposeDataCollection randomSampling(TransposeDataList strataIdList, AssociativeArray nh, boolean withReplacement); static double mean(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double variance(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double std(TransposeDataCollection sampleDataCollection, AssociativeArray populationNh); static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static double xbarStd(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh); static AssociativeArray optimumSampleSize(int n, AssociativeArray populationNh, AssociativeArray populationStdh);  }