Exemplo n.º 1
0
  public static double dsignrank(double x, double n, boolean give_log) {
    double d;

    /* NaNs propagated correctly */
    if (Double.isNaN(x) || Double.isNaN(n)) {
      return (x + n);
    }

    n = Math.floor(n + 0.5);
    if (n <= 0) {
      return Double.NaN;
    }

    if (Math.abs(x - Math.floor(x + 0.5)) > 1e-7) {
      return (R_D__0(true, give_log));
    }

    x = Math.floor(x + 0.5);
    if ((x < 0) || (x > (n * (n + 1) / 2))) {
      return (R_D__0(true, give_log));
    }

    w_init_maybe((int) n);
    d = R_D_exp(Math.log(csignrank((int) x, (int) n)) - n * Math.log(2.), true, give_log);

    return (d);
  }
Exemplo n.º 2
0
  public static double psignrank(double x, double n, boolean lower_tail, boolean log_p) {
    int i;
    double f, p;

    if (Double.isNaN(x) || Double.isNaN(n)) {
      return (x + n);
    }

    if (Double.isInfinite(n)) {
      return Double.NaN;
    }

    n = Math.floor(n + 0.5);
    if (n <= 0) {
      return Double.NaN;
    }

    x = Math.floor(x + 1e-7);
    if (x < 0.0) {
      return (R_DT_0(lower_tail, log_p));
    }

    if (x >= n * (n + 1) / 2) {
      return (R_DT_1(lower_tail, log_p));
    }

    w_init_maybe((int) n);
    f = Math.exp(-n * Math.log(2.));
    p = 0;
    if (x <= (n * (n + 1) / 4)) {
      for (i = 0; i <= x; i++) {
        p += csignrank(i, (int) n) * f;
      }
    } else {
      x = n * (n + 1) / 2 - x;
      for (i = 0; i < x; i++) {
        p += csignrank(i, (int) n) * f;
      }
      lower_tail = !lower_tail; /* p = 1 - p; */
    }

    return (R_DT_val(p, lower_tail, log_p));
  } /* psignrank() */
Exemplo n.º 3
0
  public static double qsignrank(double x, double n, boolean lower_tail, boolean log_p) {
    double f, p, q;

    if (Double.isNaN(x) || Double.isNaN(n)) {
      return (x + n);
    }

    if (Double.isInfinite(x) || Double.isInfinite(n)) {
      return Double.NaN;
    }

    if ((log_p && x > 0) || (!log_p && (x < 0 || x > 1))) {
      return Double.NaN;
    }

    n = Math.floor(n + 0.5);
    if (n <= 0) {
      return Double.NaN;
    }

    if (x == R_DT_0(lower_tail, log_p)) {
      return (0);
    }

    if (x == R_DT_1(lower_tail, log_p)) {
      return (n * (n + 1) / 2);
    }

    if (log_p || !lower_tail) {
      // x = R_DT_qIv(x); /* lower_tail,non-log "p" */
      x = Normal.R_DT_qIv(x, log_p ? 1. : 0., lower_tail ? 1. : 0.);
    }

    w_init_maybe((int) n);
    f = Math.exp(-n * Math.log(2.));

    p = 0;
    q = 0;
    if (x <= 0.5) {
      x = x - 10 * DBL_EPSILON;
      for (; ; ) {
        p += csignrank((int) q, (int) n) * f;
        if (p >= x) {
          break;
        }
        q++;
      }
    } else {
      x = 1 - x + 10 * DBL_EPSILON;
      for (; ; ) {
        p += csignrank((int) q, (int) n) * f;
        if (p > x) {
          q = n * (n + 1) / 2 - q;
          break;
        }
        q++;
      }
    }

    return (q);
  }