大样本西格玛

时间:2019-02-07 18:17:51

标签: java loops statistics

我试图通过绘制不同大小的N的大小为N的样本集合来计算均匀[0,1)分布的平均值和标准偏差。

我有一个SAMPLE_SIZES [] {2,5,10,20,40,80}数组 并且NUM_SAMPLES为10000;

我能够计算出均值的平均值,但是我对标准偏差(sigma)感到困惑。

   private static void plotSampleMeans(int sizeIndex){

  int
     i,j = 0,

     // the number of draws in each group
     sampleSize = SAMPLE_SIZES[sizeIndex];

  double
     mean = 0,
     mnSum = 0,
     mnSqrSum = 0,
     sum = 0;


  long seed;

  // reset the random number generator

  // check for overflow
  if (Long.MAX_VALUE - CURR_SEED < SEED_INCREMENT)
        CURR_SEED = Long.MIN_VALUE;
  seed = CURR_SEED + SEED_INCREMENT;
  CURR_SEED = seed;
  rng.setSeed(seed);


  // array of counts for each pixel column
  int[] valCounts = new int[PANEL_WIDTH];

  for (i = 0; i < NUM_SAMPLES; i++){
      for (j = 0; j < sampleSize; j++) {
          double x = rng.nextDouble();
          sum += x;
          mean = sum/sampleSize;
          mnSum += mean;
          mnSqrSum += Math.pow(mnSum, 2);
          valCounts[j]++;

          }

}
      sampleMeans[sizeIndex] = mean/NUM_SAMPLES;
      sampleStdDevs[sizeIndex] = Math.sqrt(mnSqrSum);

输出:

 n  sample mean  sample sigma approximate normal sigma
 2      0.50038 3154150872.19213                 0.20412
 5      0.50291 12572436666.74340                 0.12910
10      0.50080 35403680532.40556                 0.09129
20      0.49916 99950947154.05588                 0.06455
40      0.49982 282781992497.35280                 0.04564
80      0.50006 799937088950.25340                 0.03227

我应该接近这张表中的正常sigma。

0 个答案:

没有答案