@Test public void testXbarVariance() { logger.info("xbarVariance"); TransposeDataCollection sampleDataCollection = generateSampleDataCollection(); AssociativeArray nh = generateNh2(); AssociativeArray populationNh = generatePopulationNh(); double expResult = 0.17901234567; double result = StratifiedSampling.xbarVariance(sampleDataCollection, nh, populationNh); assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh) { double populationN = Descriptives.sum(populationNh.toFlatDataCollection()); if(populationN<=0) { throw new IllegalArgumentException("The populationN parameter must be positive."); } double variance = 0.0; for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); Integer strataSample = ((Number)nh.get(strata)).intValue(); if(strataPopulation==null || strataSample==null) { throw new IllegalArgumentException("Invalid strata population or sample size."); } double Wh = strataPopulation/populationN; variance+= Wh*Wh* SimpleRandomSampling.xbarVariance(SimpleRandomSampling.variance(entry.getValue()), strataSample, strataPopulation); } return variance; }
StratifiedSampling { public static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh) { double populationN = Descriptives.sum(populationNh.toFlatDataCollection()); if(populationN<=0) { throw new IllegalArgumentException("The populationN parameter must be positive."); } double variance = 0.0; for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); Integer strataSample = ((Number)nh.get(strata)).intValue(); if(strataPopulation==null || strataSample==null) { throw new IllegalArgumentException("Invalid strata population or sample size."); } double Wh = strataPopulation/populationN; variance+= Wh*Wh* SimpleRandomSampling.xbarVariance(SimpleRandomSampling.variance(entry.getValue()), strataSample, strataPopulation); } return variance; } }
StratifiedSampling { public static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh) { double populationN = Descriptives.sum(populationNh.toFlatDataCollection()); if(populationN<=0) { throw new IllegalArgumentException("The populationN parameter must be positive."); } double variance = 0.0; for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); Integer strataSample = ((Number)nh.get(strata)).intValue(); if(strataPopulation==null || strataSample==null) { throw new IllegalArgumentException("Invalid strata population or sample size."); } double Wh = strataPopulation/populationN; variance+= Wh*Wh* SimpleRandomSampling.xbarVariance(SimpleRandomSampling.variance(entry.getValue()), strataSample, strataPopulation); } return variance; }  }
StratifiedSampling { public static double xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh) { double populationN = Descriptives.sum(populationNh.toFlatDataCollection()); if(populationN<=0) { throw new IllegalArgumentException("The populationN parameter must be positive."); } double variance = 0.0; for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); Integer strataSample = ((Number)nh.get(strata)).intValue(); if(strataPopulation==null || strataSample==null) { throw new IllegalArgumentException("Invalid strata population or sample size."); } double Wh = strataPopulation/populationN; variance+= Wh*Wh* SimpleRandomSampling.xbarVariance(SimpleRandomSampling.variance(entry.getValue()), strataSample, strataPopulation); } 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 xbarVariance(TransposeDataCollection sampleDataCollection, AssociativeArray nh, AssociativeArray populationNh) { double populationN = Descriptives.sum(populationNh.toFlatDataCollection()); if(populationN<=0) { throw new IllegalArgumentException("The populationN parameter must be positive."); } double variance = 0.0; for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) { Object strata = entry.getKey(); Integer strataPopulation = ((Number)populationNh.get(strata)).intValue(); Integer strataSample = ((Number)nh.get(strata)).intValue(); if(strataPopulation==null || strataSample==null) { throw new IllegalArgumentException("Invalid strata population or sample size."); } double Wh = strataPopulation/populationN; variance+= Wh*Wh* SimpleRandomSampling.xbarVariance(SimpleRandomSampling.variance(entry.getValue()), strataSample, strataPopulation); } 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);  }