code: 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;
                  
              //this is the formula when we do SimpleRandomSampling in each strata. nevertheless in order to keep our code DRY, instead of writing directly the formula of SimpleRandomSampling here, we will call SimpleRandomSampling xbarVariance function to estimate it.
              //$fh=$nh[$strata]/$populationNh[$strata];
              //$variance+=$Wh*$Wh*SimpleRandomSampling::variance($flatDataCollection)*(1-$fh)/$nh[$strata]; 
              variance+= Wh*Wh* SimpleRandomSampling.xbarVariance(SimpleRandomSampling.variance(entry.getValue()), strataSample, strataPopulation);
          }
          
          return variance;
      }
docs: Calculates Variance for Xbar
  
  @param sampleDataCollection
  @param nh
  @param populationNh
  @return