コード例 #1
0
ファイル: pnorm.c プロジェクト: 6e441f9c/julia
double pnorm5(double x, double mu, double sigma, int lower_tail, int log_p)
{
    double p, cp;

    /* Note: The structure of these checks has been carefully thought through.
     * For example, if x == mu and sigma == 0, we get the correct answer 1.
     */
#ifdef IEEE_754
    if(ISNAN(x) || ISNAN(mu) || ISNAN(sigma))
	return x + mu + sigma;
#endif
    if(!R_FINITE(x) && mu == x) return ML_NAN;/* x-mu is NaN */
    if (sigma <= 0) {
	if(sigma < 0) ML_ERR_return_NAN;
	/* sigma = 0 : */
	return (x < mu) ? R_DT_0 : R_DT_1;
    }
    p = (x - mu) / sigma;
    if(!R_FINITE(p))
	return (x < mu) ? R_DT_0 : R_DT_1;
    x = p;

    pnorm_both(x, &p, &cp, (lower_tail ? 0 : 1), log_p);

    return(lower_tail ? p : cp);
}
コード例 #2
0
ファイル: gamma.c プロジェクト: amnh/poy5
double
pnorm(double x, double mu, double sigma, int lower_tail, int log_p){
    double p, cp;

    if (sigma == 0)
	    return (x < mu) ? 0.0 : 1.0;
    p = (x - mu) / sigma;
    x = p;
    pnorm_both(x, &p, &cp, (lower_tail ? 0 : 1), log_p);
    return(lower_tail ? p : cp);
}
コード例 #3
0
ファイル: wmw_test.c プロジェクト: Accio/BioQC
double wmw_test_stat(double rankSum, int nInds, int nTotal, double tieCoef, TestType type) {
  
  double uStat, mu, sigma2, zval, pgt, plt;
  double res;
  int nBg = nTotal-nInds;
  
  uStat = nInds*nBg+nInds*(nInds+1.0)*0.5-rankSum;
  
  if(type == U) {
    res = uStat;
  } else {
    mu = (double)nInds*nBg*0.5; // NOT mu=n1*n2*0.5
    sigma2 = nInds*nBg*(nTotal+1.0)/12.0*tieCoef; //NOT sigma2 = n1*n2*(n+1)/12*tieCoef
    
    if(type == greater || type == abslog10greater) { /* greater */
zval = (uStat+0.5-mu)/sqrt(sigma2); // z lower tail
      pnorm_both(zval, &pgt, &plt, 0, 0);
      res = type==greater ? pgt : ABSLOG(pgt);
    } else if (type == less || type == log10less) { /* less */
zval = (uStat-0.5-mu)/sqrt(sigma2); // z higher tail
      pnorm_both(zval, &pgt, &plt, 1, 0);
      res = type==less ? plt : log10(plt);
    } else if (type == twoSided || type == abslog10twoSided || type == Q) { /* two sided*/
zval = (uStat-mu-(uStat>mu ? 0.5 : -0.5))/sqrt(sigma2);
      pnorm_both(zval, &pgt, &plt, 2, 0);
      res = mu==0.0 ? 1.0 : 2.0*MIN(pgt, plt);
      if(type == abslog10twoSided) {
        res = ABSLOG(res);
      } else if (type == Q) {
        res = pgt<=plt ? ABSLOG(res) : -ABSLOG(res);
      }
    } else {
      error("Unrecognized type %d. Should not happen\n",
            type);
    }
  }
  return(res);
}
コード例 #4
0
ファイル: pnorm.cpp プロジェクト: MarkEdmondson1234/Boom
double pnorm(double x, double mu, double sigma, int lower_tail, int log_p)
{
    double p, cp;

    /* Note: The structure of these checks has been carefully thought through.
     * For example, if x == mu and sigma == 0, we still get the correct answer.
     */
#ifdef IEEE_754
    if(ISNAN(x) || ISNAN(mu) || ISNAN(sigma))
        return x + mu + sigma;
#endif
    if (sigma < 0) ML_ERR_return_NAN;

    x = (x - mu) / sigma;
    if(!R_FINITE(x)) {
        if(ISNAN(x)) /* e.g. x=mu=Inf */ return(numeric_limits<double>::quiet_NaN());
        if(x < 0) return R_DT_0;
        else return R_DT_1;
    }

    pnorm_both(x, &p, &cp, (lower_tail ? 0 : 1), log_p);

    return(lower_tail ? p : cp);
}