code: 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;
              
              //Analysis of Variance
              
              //Within Strata
              variance+=(strataPopulation-1)*SimpleRandomSampling.variance(entry.getValue());
              //Between Strata
              variance+=strataPopulation*Math.pow(SimpleRandomSampling.mean(entry.getValue())-mean,2);
          }
          
          variance/=(populationN-1);
  
          return variance;
      }
docs: Calculate the variance from the sample
  
  @param sampleDataCollection
  @param populationNh
  @return