Beispiel #1
0
double equivalent_gaussian_sigma(double logp)
/* Return the approximate significance in Gaussian sigmas */
/* corresponding to a natural log probability logp        */
{
    double x;

    if (logp < -600.0) {
        x = extended_equiv_gaussian_sigma(logp);
    } else {
        int which, status;
        double p, q, bound, mean = 0.0, sd = 1.0;
        q = exp(logp);
        p = 1.0 - q;
        which = 2;
        status = 0;
        /* Convert to a sigma */
        cdfnor(&which, &p, &q, &x, &mean, &sd, &status, &bound);
        if (status) {
            if (status == -2) {
                x = 0.0;
            } else if (status == -3) {
                x = 38.5;
            } else {
                printf("\nError in cdfnor() (candidate_sigma()):\n");
                printf("   status = %d, bound = %g\n", status, bound);
                printf("   p = %g, q = %g, x = %g, mean = %g, sd = %g\n\n",
                       p, q, x, mean, sd);
                exit(1);
            }
        }
    }
    if (x < 0.0)
        return 0.0;
    else
        return x;
}
Beispiel #2
0
double candidate_sigma(double power, int numsum, double numtrials)
/* Return the approximate significance in Gaussian       */
/* sigmas of a candidate of numsum summed powers,        */
/* taking into account the number of independent trials. */
{
   double x = 0.0;

   if (power <= 0.0) {
      return 0.0;
   }

   if (power > 100.0) {
      double logp;

      /* Use some asymtotic expansions for the chi^2 distribution */
      logp = log_asymtotic_incomplete_gamma(numsum, power) -
          log_asymtotic_gamma(numsum);
      /* Now adjust for the number of trials */
      logp += log(numtrials);
      /* Convert to a sigma */
      x = extended_equiv_gaussian_sigma(logp);
   } else {
      int which, status;
      double p, q, bound, mean = 0.0, sd = 1.0, shape, scale = 1.0;

      which = 1;
      status = 0;
      shape = (double) numsum;
      x = power;
      /* Determine the basic probability */
      cdfgam(&which, &p, &q, &x, &shape, &scale, &status, &bound);
      if (status) {
         printf("\nError in cdfgam() (candidate_sigma()):\n");
         printf("   status = %d, bound = %g\n", status, bound);
         printf("   p = %g, q = %g, x = %g, shape = %g, scale = %g\n\n",
                p, q, x, shape, scale);
         exit(1);
      }
      /* Adjust it for the number of trials */
      if (p == 1.0)
         q *= numtrials;
      else
         q = 1.0 - pow(p, numtrials);
      p = 1.0 - q;
      which = 2;
      status = 0;
      /* Convert to a sigma */
      cdfnor(&which, &p, &q, &x, &mean, &sd, &status, &bound);
      if (status) {
         if (status == -2) {
            x = 0.0;
         } else if (status == -3) {
            x = 38.5;
         } else {
            printf("\nError in cdfnor() (candidate_sigma()):\n");
            printf("   status = %d, bound = %g\n", status, bound);
            printf("   p = %g, q = %g, x = %g, mean = %g, sd = %g\n\n",
                   p, q, x, mean, sd);
            exit(1);
         }
      }
   }
   if (x < 0.0)
      return 0.0;
   else
      return x;
}