Beispiel #1
0
double power_for_sigma(double sigma, int numsum, double numtrials)
/* Return the approximate summed power level required */
/* to get a Gaussian significance of 'sigma', taking  */
/* into account the number of independent trials.     */
{
    int which, status;
    double p, q, x, bound, mean = 0.0, sd = 1.0, df, scale = 1.0;

    which = 1;
    status = 0;
    x = sigma;
    cdfnor(&which, &p, &q, &x, &mean, &sd, &status, &bound);
    if (status) {
        printf("\nError in cdfnor() (power_for_sigma()):\n");
        printf("   cdfstatus = %d, bound = %g\n\n", status, bound);
        printf("   p = %g, q = %g, x = %g, mean = %g, sd = %g\n\n", p, q, x, mean,
               sd);
        exit(1);
    }
    q = q / numtrials;
    p = 1.0 - q;
    which = 2;
    df = 2.0 * numsum;
    status = 0;
    cdfchi(&which, &p, &q, &x, &df, &status, &bound);
    if (status) {
        printf("\nError in cdfchi() (power_for_sigma()):\n");
        printf("   status = %d, bound = %g\n", status, bound);
        printf("   p = %g, q = %g, x = %g, df = %g, scale = %g\n\n",
               p, q, x, df, scale);
        exit(1);
    }
    return 0.5 * x;
}
Beispiel #2
0
inline double dcdflib_norm_quantile(double p, double mean, double sd)
{
   int what = 2;
   int status = 0;
   double x, bound, q(1 - p);
   cdfnor(&what, &p, &q, &x, &mean, &sd, &status, &bound);
   return x;
}
Beispiel #3
0
inline double dcdflib_norm_cdf(double x, double mean, double sd)
{
   int what = 1;
   int status = 0;
   double p, q, bound;
   cdfnor(&what, &p, &q, &x, &mean, &sd, &status, &bound);
   return p;
}
Beispiel #4
0
void V_cdfnor(int *which, double *p, double *q, double *x, double *mean,
	      double *sd, int *status, double *bound, int *len)
{
    int i;
    for (i = 0; i < *len; i++) {
	cdfnor((int *)which, &p[i], &q[i], &x[i], &mean[i],
	       &sd[i], (int *)&status[i], &bound[i]);
    }
}
Beispiel #5
0
/********************************************************************
** CNORM--subfunction used to compute cumulative normal distribution.

*********************************************************************/
double 
  CNORM (double x)
{
  int which, status;
  double p, q, mean, sd, bound;
  which = 1;
  mean = 0.0;
  sd = 1.0;
  cdfnor(&which, &p, &q, &x, &mean, &sd, &status, &bound);
  return(p);
}
Beispiel #6
0
static int stat_pnorm (lua_State *L) {
  /* stack should contain x, and opt. mean and sd */
  lua_Number x = luaL_checknumber(L, 1);
  lua_Number mean = luaL_optnumber(L, 2, 0);
  lua_Number sd = luaL_optnumber(L, 3, 1);
  lua_Number p, q, bound;
  int which = 1;
  int status;
  check_norm(L, 1, x, sd);
  cdfnor(&which, &p, &q, &x, &mean, &sd, &status, &bound);
  check_status(L, status, bound);
  lua_pushnumber(L, p);
  return 1;
}
Beispiel #7
0
static int cdf_qnorm (lua_State *L) {
  /* stack should contain p, and opt. mean and sd */
  lua_Number p = luaL_checknumber(L, 1);
  lua_Number mean = luaL_optnumber(L, 2, 0);
  lua_Number sd = luaL_optnumber(L, 3, 1);
  lua_Number x;
  check_norm(L, 2, p, sd);
  if (p==0 || p==1) x = (p==0) ? -HUGE_VAL : HUGE_VAL;
  else {
    lua_Number q = 1-p;
    lua_Number bound;
    int which = 2;
    int status;
    cdfnor(&which, &p, &q, &x, &mean, &sd, &status, &bound);
    check_status(status, bound);
  }
  lua_pushnumber(L, x);
  return 1;
}
Beispiel #8
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 #9
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;
}