示例#1
0
void bootweights()
{   /* sets up weights by resampling data */
    long i, j, k, blocks;
    double p, q, r;
    long grp = 0, site = 0;

    ws = newgroups;
    for (i = 0; i < (ws); i++)
        weight[i] = 0;
    blocks = fracsample * newgroups / blocksize;
    for (i = 1; i <= (blocks); i++) {
        j = (long)(newgroups * randum(seed)) + 1;
        for (k = 0; k < blocksize; k++) {
            weight[j - 1]++;
            j++;
            if (j > newgroups)
                j = 1;
        }
    }

    /* Count number of replicated groups */
    newergroups = 0;
    newersites  = 0;
    for (i = 0; i < newgroups; i++) {
        newergroups += weight[i];
        newersites  += newhowmany[i] * weight[i];
    }

    if (newergroups < 1) {
        fprintf(stdout, "ERROR: sampling frequency or number of sites is too small\n");
        exxit(-1);
    }

    /* reallocate "newer" arrays, sized by output groups:
     * newerfactor, newerwhere, newerhowmany, and charorder */
    allocnewer(newergroups, newersites);

    /* Replicate each group i weight[i] times */
    grp = 0;
    site = 0;
    for (i = 0; i < newgroups; i++) {
        for (j = 0; j < weight[i]; j++) {
            for (k = 0; k < newhowmany[i]; k++) {
                newerfactor[site] = grp + 1;
                site++;
            }
            newerwhere[grp] = newwhere[i];
            newerhowmany[grp] = newhowmany[i];
            grp++;
        }
    }
}  /* bootweights */
示例#2
0
void bootweights()
{ /* sets up weights by resampling data */
  long i, j, k, blocks;
  double p, q, r;
  long grp = 0, site = 0;

  ws = newgroups;
  for (i = 0; i < (ws); i++)
    weight[i] = 0;
  if (jackknife) {
    if (fabs(newgroups*fracsample - (long)(newgroups*fracsample+0.5))
       > 0.00001) {
      if (randum(seed)
          < (newgroups*fracsample - (long)(newgroups*fracsample))
            /((long)(newgroups*fracsample+1.0)-(long)(newgroups*fracsample)))
        q = (long)(newgroups*fracsample)+1;
      else
        q = (long)(newgroups*fracsample);
    } else
      q = (long)(newgroups*fracsample+0.5);
    r = newgroups;
    p = q / r;
    ws = 0;
    for (i = 0; i < (newgroups); i++) {
      if (randum(seed) < p) {
        weight[i]++;
        ws++;
        q--;
      }
      r--;
      if (i + 1 < newgroups)
        p = q / r;
    }
  } else if (permute) {
    for (i = 0; i < (newgroups); i++)
      weight[i] = 1;
  } else if (bootstrap) {
    blocks = fracsample * newgroups / blocksize;
    for (i = 1; i <= (blocks); i++) {
      j = (long)(newgroups * randum(seed)) + 1;
      for (k = 0; k < blocksize; k++) {
        weight[j - 1]++;
        j++;
        if (j > newgroups)
          j = 1;
      }
    }
  } else             /* case of rewriting data */
    for (i = 0; i < (newgroups); i++)
      weight[i] = 1;

  /* Count number of replicated groups */
  newergroups = 0;
  newersites  = 0;
  for (i = 0; i < newgroups; i++) {
    newergroups += weight[i];
    newersites  += newhowmany[i] * weight[i];
  }

  if (newergroups < 1) {
    fprintf(stdout, "ERROR: sampling frequency or number of sites is too small\n");
    exxit(-1);
  }
  
  /* reallocate "newer" arrays, sized by output groups:
   * newerfactor, newerwhere, newerhowmany, and charorder */
  allocnewer(newergroups, newersites);
  
  /* Replicate each group i weight[i] times */
  grp = 0;
  site = 0;
  for (i = 0; i < newgroups; i++) {
    for (j = 0; j < weight[i]; j++) {
      for (k = 0; k < newhowmany[i]; k++) {
        newerfactor[site] = grp + 1;
        site++;
      }
      newerwhere[grp] = newwhere[i];
      newerhowmany[grp] = newhowmany[i];
      grp++;
    }
  }
}  /* bootweights */