diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Chisq.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Chisq.java index c39fa8c5e71ef0ff5c84add184ea21ccee6cd3df..62205497a7d92a5001454b1052b948a90fd643b7 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Chisq.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Chisq.java @@ -13,11 +13,18 @@ package com.oracle.truffle.r.library.stats; import static com.oracle.truffle.r.library.stats.GammaFunctions.dgamma; import static com.oracle.truffle.r.library.stats.GammaFunctions.pgamma; +import static com.oracle.truffle.r.library.stats.GammaFunctions.qgamma; +import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandFunction1_Double; +import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandomNumberProvider; import com.oracle.truffle.r.library.stats.StatsFunctions.Function2_1; import com.oracle.truffle.r.library.stats.StatsFunctions.Function2_2; public final class Chisq { + private Chisq() { + // only static members + } + public static final class PChisq implements Function2_2 { @Override public double evaluate(double x, double df, boolean lowerTail, boolean logP) { @@ -31,4 +38,25 @@ public final class Chisq { return dgamma(x, df / 2., 2., giveLog); } } + + public static final class QChisq implements Function2_2 { + @Override + public double evaluate(double p, double df, boolean lowerTail, boolean logP) { + return qgamma(p, 0.5 * df, 2.0, lowerTail, logP); + } + } + + public static final class RChisq extends RandFunction1_Double { + public static double rchisq(double df, RandomNumberProvider rand) { + if (!Double.isFinite(df) || df < 0.0) { + return RMath.mlError(); + } + return new RGamma().execute(df / 2.0, 2.0, rand); + } + + @Override + public double execute(double a, RandomNumberProvider rand) { + return rchisq(a, rand); + } + } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/DPQ.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/DPQ.java index 59cfce3ce6b4ff30ba5d5b9907f1b9fcc7ce4843..4509a1f64689f66db8aefc9e0e839648c10b4b84 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/DPQ.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/DPQ.java @@ -51,6 +51,11 @@ public final class DPQ { return logP ? Double.NEGATIVE_INFINITY : 0.; } + // R_D_half (log_p ? -M_LN2 : 0.5) + public static double rdhalf(boolean logP) { + return logP ? -M_LN2 : 0.5; + } + // R_D__1 public static double rd1(boolean logP) { return logP ? 0. : 1.; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/MathConstants.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/MathConstants.java index 61bc036c42e836445108ea3208bfecf9089332f2..1f257567fca09a92c5d911e6934d8762ae6c30e2 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/MathConstants.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/MathConstants.java @@ -86,6 +86,8 @@ public final class MathConstants { public static final double DBL_EPSILON = Math.ulp(1.0); + public static final double ML_NAN = Double.NaN; + /** * Compute the log of a sum from logs of terms, i.e., * diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pbeta.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pbeta.java index 02c713c68abadf8fe6755b5a2ead937269cc88bd..4c12e76f64cc9dc11324231c7a825de34b62abb3 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pbeta.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pbeta.java @@ -29,7 +29,7 @@ public final class Pbeta implements Function3_2 { } @TruffleBoundary - private static double pbetaRaw(double x, double a, double b, boolean lowerTail, boolean logProb) { + static double pbetaRaw(double x, double a, double b, boolean lowerTail, boolean logProb) { // treat limit cases correctly here: if (a == 0 || b == 0 || !Double.isFinite(a) || !Double.isFinite(b)) { // NB: 0 < x < 1 : diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QBeta.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QBeta.java new file mode 100644 index 0000000000000000000000000000000000000000..7af7d44a25bedc7d72d42edbc8005805d6c0e0d7 --- /dev/null +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QBeta.java @@ -0,0 +1,659 @@ +/* + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Copyright (c) 1995, 1996, Robert Gentleman and Ross Ihaka + * Copyright (c) 1998-2015, The R Core Team + * Copyright (c) 2016, Oracle and/or its affiliates + * + * All rights reserved. + */ +/* + * based on code (C) 1979 and later Royal Statistical Society + * + * Reference: + * Cran, G. W., K. J. Martin and G. E. Thomas (1977). + * Remark AS R19 and Algorithm AS 109, + * Applied Statistics, 26(1), 111-114. + * Remark AS R83 (v.39, 309-310) and the correction (v.40(1) p.236) + * have been incorporated in this version. + */ +package com.oracle.truffle.r.library.stats; + +import static com.oracle.truffle.r.library.stats.Arithmetic.powDi; +import static com.oracle.truffle.r.library.stats.LBeta.lbeta; +import static com.oracle.truffle.r.library.stats.MathConstants.DBL_MANT_DIG; +import static com.oracle.truffle.r.library.stats.MathConstants.DBL_MIN_EXP; +import static com.oracle.truffle.r.library.stats.MathConstants.ML_NAN; +import static com.oracle.truffle.r.library.stats.MathConstants.M_LN2; +import static com.oracle.truffle.r.library.stats.Pbeta.pbetaRaw; + +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.r.library.stats.RMath.MLError; +import com.oracle.truffle.r.library.stats.StatsFunctions.Function3_2; +import com.oracle.truffle.r.runtime.RError.Message; + +public final class QBeta implements Function3_2 { + private static final double USE_LOG_X_CUTOFF = -5.; + private static final int N_NEWTON_FREE = 4; + // TODO: find out why this??? Is swap_01 R logical?? + private static final int MLOGICAL_NA = -1; + + @Override + public double evaluate(double alpha, double p, double q, boolean lowerTail, boolean logP) { + if (Double.isNaN(p) || Double.isNaN(q) || Double.isNaN(alpha)) { + return p + q + alpha; + } + + if (p < 0. || q < 0.) { + return RMath.mlError(); + } + // allowing p==0 and q==0 <==> treat as one- or two-point mass + + double[] qbet = new double[2]; // = { qbeta(), 1 - qbeta() } + new QBetaRawMethod().qbeta_raw(alpha, p, q, lowerTail, logP, MLOGICAL_NA, USE_LOG_X_CUTOFF, N_NEWTON_FREE, qbet); + return qbet[0]; + + } + + /** + * Debugging printfs should print exactly the same output as GnuR, this can help with debugging. + */ + private static void debugPrintf(@SuppressWarnings("unused") String fmt, @SuppressWarnings("unused") Object... args) { + // System.out.printf(fmt + "\n", args); + } + + private static final double acu_min = 1e-300; + private static final double log_eps_c = M_LN2 * (1. - DBL_MANT_DIG); // = log(DBL_EPSILON) = + // -36.04..; + private static final double fpu = 3e-308; + private static final double p_lo = fpu; + private static final double p_hi = 1 - 2.22e-16; + + private static final double const1 = 2.30753; + private static final double const2 = 0.27061; + private static final double const3 = 0.99229; + private static final double const4 = 0.04481; + + private static final double DBL_very_MIN = Double.MIN_VALUE / 4.; + private static final double DBL_log_v_MIN = M_LN2 * (DBL_MIN_EXP - 2); + private static final double DBL_1__eps = 0x1.fffffffffffffp-1; // = 1 - 2^-53 + + // The fields and variables are named after local variables from GnuR, we keep the original + // names for the ease of debugging + // Checkstyle: stop field name check + private static class QBetaRawMethod { + private boolean give_log_q; + private boolean use_log_x; + private boolean add_N_step; + private double logbeta; + private boolean swap_tail; + private double a; + private double la; + private double pp; + private double qq; + private double r; + private double t; + private double tx; + private double u_n; + private double xinbta; + private double u; + private boolean warned; + private double acu; + private double y; + private double w; + private boolean log_; // or u < log_q_cut below + private double p_; + private double u0; + private double s; + private double h; + boolean bad_u; + boolean bad_init; + private double g; + private double D; + + /** + * + * @param alpha + * @param p + * @param q + * @param lower_tail + * @param log_p + * @param swap_01 {true, NA, false}: if NA, algorithm decides swap_tail + * @param log_q_cut if == Inf: return Math.log(qbeta(..)); otherwise, if finite: the bound + * for switching to Math.log(x)-scale; see use_log_x + * @param n_N number of "unconstrained" Newton steps before switching to constrained + * @param qb The result will be saved to this 2 dimensional array = qb[0:1] = { qbeta(), 1 - + * qbeta() }. + */ + @TruffleBoundary + private void qbeta_raw(double alpha, double p, double q, boolean lower_tail, boolean log_p, + int swap_01, + double log_q_cut, + int n_N, + double[] qb) { + give_log_q = (log_q_cut == Double.POSITIVE_INFINITY); + use_log_x = give_log_q; + add_N_step = true; + y = -1.; + + // Assuming p >= 0, q >= 0 here ... + + // Deal with boundary cases here: + if (alpha == DPQ.rdt0(lower_tail, log_p)) { + returnQ0(qb, give_log_q); + return; + } + if (alpha == DPQ.rdt1(lower_tail, log_p)) { + returnQ1(qb, give_log_q); + return; + } + + // check alpha {*before* transformation which may all accuracy}: + if ((log_p && alpha > 0) || + (!log_p && (alpha < 0 || alpha > 1))) { // alpha is outside + debugPrintf("qbeta(alpha=%g, %g, %g, .., log_p=%d): %s%s\n", + alpha, p, q, log_p, "alpha not in ", + log_p ? "[-Inf, 0]" : "[0,1]"); + // ML_ERR_return_NAN : + RMath.mlError(MLError.DOMAIN, ""); + qb[0] = qb[1] = ML_NAN; + return; + } + + // p==0, q==0, p = Inf, q = Inf <==> treat as one- or two-point mass + if (p == 0 || q == 0 || !Double.isFinite(p) || !Double.isFinite(q)) { + // We know 0 < T(alpha) < 1 : pbeta() is constant and trivial in {0, 1/2, 1} + debugPrintf( + "qbeta(%g, %g, %g, lower_t=%d, log_p=%d): (p,q)-boundary: trivial\n", + alpha, p, q, lower_tail, log_p); + if (p == 0 && q == 0) { // point mass 1/2 at each of {0,1} : + if (alpha < DPQ.rdhalf(log_p)) { + returnQ0(qb, give_log_q); + } else if (alpha > DPQ.rdhalf(log_p)) { + returnQ1(qb, give_log_q); + } else { + returnQHalf(qb, give_log_q); + } + return; + } else if (p == 0 || p / q == 0) { // point mass 1 at 0 - "flipped around" + returnQ0(qb, give_log_q); + } else if (q == 0 || q / p == 0) { // point mass 1 at 0 - "flipped around" + returnQ1(qb, give_log_q); + } else { + // else: p = q = Inf : point mass 1 at 1/2 + returnQHalf(qb, give_log_q); + } + return; + } + + p_ = DPQ.rdtqiv(alpha, lower_tail, log_p); + logbeta = lbeta(p, q); + boolean swap_choose = (swap_01 == MLOGICAL_NA); + swap_tail = swap_choose ? (p_ > 0.5) : swap_01 != 0; + if (swap_tail) { /* change tail, swap p <-> q : */ + a = DPQ.rdtciv(alpha, lower_tail, log_p); // = 1 - p_ < 1/2 + /* la := log(a), but without numerical cancellation: */ + la = DPQ.rdtclog(alpha, lower_tail, log_p); + pp = q; + qq = p; + } else { + a = p_; + la = DPQ.rdtlog(alpha, lower_tail, log_p); + pp = p; + qq = q; + } + + /* calculate the initial approximation */ + + /* + * Desired accuracy for Newton iterations (below) should depend on (a,p) This is from + * Remark .. on AS 109, adapted. However, it's not clear if this is "optimal" for IEEE + * double prec. + * + * acu = fmax2(acu_min, pow(10., -25. - 5./(pp * pp) - 1./(a * a))); + * + * NEW: 'acu' accuracy NOT for squared adjustment, but simple; ---- i.e., "new acu" = + * sqrt(old acu) + */ + acu = Math.max(acu_min, Math.pow(10., -13. - 2.5 / (pp * pp) - 0.5 / (a * a))); + // try to catch "extreme left tail" early + u0 = (la + Math.log(pp) + logbeta) / pp; // = log(x_0) + r = pp * (1. - qq) / (pp + 1.); + t = 0.2; + + debugPrintf( + "qbeta(%g, %g, %g, lower_t=%d, log_p=%d):%s\n" + + " swap_tail=%d, la=%g, u0=%g (bnd: %g (%g)) ", + alpha, p, q, lower_tail, log_p, + (log_p && (p_ == 0. || p_ == 1.)) ? (p_ == 0. ? " p_=0" : " p_=1") : "", + swap_tail, la, u0, + (t * log_eps_c - Math.log(Math.abs(pp * (1. - qq) * (2. - qq) / (2. * (pp + 2.))))) / 2., + t * log_eps_c - Math.log(Math.abs(r))); + + tx = 0.; + if (M_LN2 * DBL_MIN_EXP < u0 && // cannot allow exp(u0) = 0 ==> exp(u1) = exp(u0) = 0 + u0 < -0.01 && // (must: u0 < 0, but too close to 0 <==> x = exp(u0) = + // 0.99..) + // qq <= 2 && // <--- "arbitrary" + // u0 < t*log_eps_c - log(fabs(r)) && + u0 < (t * log_eps_c - Math.log(Math.abs(pp * (1. - qq) * (2. - qq) / (2. * (pp + 2.))))) / 2.) { + // TODO: maybe jump here from below, when initial u "fails" ? + // L_tail_u: + // MM's one-step correction (cheaper than 1 Newton!) + r = r * Math.exp(u0); // = r*x0 + if (r > -1.) { + u = u0 - RMath.log1p(r) / pp; + debugPrintf("u1-u0=%9.3g --> choosing u = u1\n", u - u0); + } else { + u = u0; + debugPrintf("cannot cheaply improve u0\n"); + } + tx = xinbta = Math.exp(u); + use_log_x = true; // or (u < log_q_cut) ?? + newton(n_N, log_p, qb); + return; + } + + // y := y_\alpha in AS 64 := Hastings(1955) approximation of qnorm(1 - a) : + r = Math.sqrt(-2 * la); + y = r - (const1 + const2 * r) / (1. + (const3 + const4 * r) * r); + + if (pp > 1 && qq > 1) { // use Carter(1947), see AS 109, remark '5.' + r = (y * y - 3.) / 6.; + s = 1. / (pp + pp - 1.); + t = 1. / (qq + qq - 1.); + h = 2. / (s + t); + w = y * Math.sqrt(h + r) / h - (t - s) * (r + 5. / 6. - 2. / (3. * h)); + debugPrintf("p,q > 1 => w=%g", w); + if (w > 300) { // Math.exp(w+w) is huge or overflows + t = w + w + Math.log(qq) - Math.log(pp); // = argument of log1pMath.exp(.) + u = // Math.log(xinbta) = - log1p(qq/pp * Math.exp(w+w)) = -Math.log(1 + + // Math.exp(t)) + (t <= 18) ? -RMath.log1p(Math.exp(t)) : -t - Math.exp(-t); + xinbta = Math.exp(u); + } else { + xinbta = pp / (pp + qq * Math.exp(w + w)); + u = // Math.log(xinbta) + -RMath.log1p(qq / pp * Math.exp(w + w)); + } + } else { // use the original AS 64 proposal, Scheffé-Tukey (1944) and Wilson-Hilferty + r = qq + qq; + /* + * A slightly more stable version of t := \chi^2_{alpha} of AS 64 t = 1. / (9. * + * qq); t = r * R_pow_di(1. - t + y * Math.sqrt(t), 3); + */ + t = 1. / (3. * Math.sqrt(qq)); + t = r * powDi(1. + t * (-t + y), 3); // = \chi^2_{alpha} of AS 64 + s = 4. * pp + r - 2.; // 4p + 2q - 2 = numerator of new t = (...) / chi^2 + debugPrintf("min(p,q) <= 1: t=%g", t); + if (t == 0 || (t < 0. && s >= t)) { // cannot use chisq approx + // x0 = 1 - { (1-a)*q*B(p,q) } ^{1/q} {AS 65} + // xinbta = 1. - Math.exp((Math.log(1-a)+ Math.log(qq) + logbeta) / qq); + double l1ma; /* + * := Math.log(1-a), directly from alpha (as 'la' above): FIXME: + * not worth it? log1p(-a) always the same ?? + */ + if (swap_tail) { + l1ma = DPQ.rdtlog(alpha, lower_tail, log_p); + } else { + l1ma = DPQ.rdtclog(alpha, lower_tail, log_p); + } + debugPrintf(" t <= 0 : log1p(-a)=%.15g, better l1ma=%.15g\n", RMath.log1p(-a), l1ma); + double xx = (l1ma + Math.log(qq) + logbeta) / qq; + if (xx <= 0.) { + xinbta = -RMath.expm1(xx); + u = DPQ.rlog1exp(xx); // = Math.log(xinbta) = Math.log(1 - + // Math.exp(...A...)) + } else { // xx > 0 ==> 1 - e^xx < 0 .. is nonsense + debugPrintf(" xx=%g > 0: xinbta:= 1-e^xx < 0\n", xx); + xinbta = 0; + u = Double.NEGATIVE_INFINITY; /// FIXME can do better? + } + } else { + t = s / t; + debugPrintf(" t > 0 or s < t < 0: new t = %g ( > 1 ?)\n", t); + if (t <= 1.) { // cannot use chisq, either + u = (la + Math.log(pp) + logbeta) / pp; + xinbta = Math.exp(u); + } else { // (1+x0)/(1-x0) = t, solved for x0 : + xinbta = 1. - 2. / (t + 1.); + u = RMath.log1p(-2. / (t + 1.)); + } + } + } + + // Problem: If initial u is completely wrong, we make a wrong decision here + if (swap_choose && + ((swap_tail && u >= -Math.exp(log_q_cut)) || // ==> "swap back" + (!swap_tail && u >= -Math.exp(4 * log_q_cut) && pp / qq < 1000.))) { // ==> + // "swap + // now" + // (much + // less + // easily) + // "revert swap" -- and use_log_x + swap_tail = !swap_tail; + debugPrintf(" u = %g (e^u = xinbta = %.16g) ==> ", u, xinbta); + if (swap_tail) { + a = DPQ.rdtciv(alpha, lower_tail, log_p); // needed ? + la = DPQ.rdtclog(alpha, lower_tail, log_p); + pp = q; + qq = p; + } else { + a = p_; + la = DPQ.rdtlog(alpha, lower_tail, log_p); + pp = p; + qq = q; + } + debugPrintf("\"%s\"; la = %g\n", + (swap_tail ? "swap now" : "swap back"), la); + // we could redo computations above, but this should be stable + u = DPQ.rlog1exp(u); + xinbta = Math.exp(u); + + /* + * Careful: "swap now" should not fail if 1) the above initial xinbta is + * "completely wrong" 2) The correction step can go outside (u_n > 0 ==> e^u > 1 is + * illegal) e.g., for qbeta(0.2066, 0.143891, 0.05) + */ + } + + if (!use_log_x) { + use_log_x = (u < log_q_cut); // (per default) <==> xinbta = e^u < 4.54e-5 + } + bad_u = !Double.isFinite(u); + bad_init = bad_u || xinbta > p_hi; + + debugPrintf(" -> u = %g, e^u = xinbta = %.16g, (Newton acu=%g%s)\n", + u, xinbta, acu, + (bad_u ? ", ** bad u **" : (use_log_x ? ", on u = Math.log(x) scale" : ""))); + + u_n = 1.; + tx = xinbta; // keeping "original initial x" (for now) + + if (bad_u || u < log_q_cut) { /* + * e.g. qbeta(0.21, .001, 0.05) try "left border" quickly, + * i.e., try at smallest positive number: + */ + w = pbetaRaw(DBL_very_MIN, pp, qq, true, log_p); + if (w > (log_p ? la : a)) { + debugPrintf(" quantile is left of smallest positive number; \"convergence\"\n"); + if (log_p || Math.abs(w - a) < Math.abs(0 - a)) { // DBL_very_MIN is better than + // 0 + tx = DBL_very_MIN; + u_n = DBL_log_v_MIN; // = Math.log(DBL_very_MIN) + } else { + tx = 0.; + u_n = Double.NEGATIVE_INFINITY; + } + use_log_x = log_p; + add_N_step = false; + finalStep(log_p, qb); + return; + } else { + debugPrintf(" pbeta(smallest pos.) = %g <= %g --> continuing\n", + w, (log_p ? la : a)); + if (u < DBL_log_v_MIN) { + u = DBL_log_v_MIN; // = Math.log(DBL_very_MIN) + xinbta = DBL_very_MIN; + } + } + } + + /* Sometimes the approximation is negative (and == 0 is also not "ok") */ + if (bad_init && !(use_log_x && tx > 0)) { + if (u == Double.NEGATIVE_INFINITY) { + debugPrintf(" u = -Inf;"); + u = M_LN2 * DBL_MIN_EXP; + xinbta = Double.MIN_VALUE; + } else { + debugPrintf(" bad_init: u=%g, xinbta=%g;", u, xinbta); + xinbta = (xinbta > 1.1) // i.e. "way off" + ? 0.5 // otherwise, keep the respective boundary: + : ((xinbta < p_lo) ? Math.exp(u) : p_hi); + if (bad_u) { + u = Math.log(xinbta); + } + // otherwise: not changing "potentially better" u than the above + } + debugPrintf(" -> (partly)new u=%g, xinbta=%g\n", u, xinbta); + } + + newton(n_N, log_p, qb); + // note: newton calls converged which calls finalStep + } + + private void newton(int n_N, boolean log_p, double[] qb) { + /* + * -------------------------------------------------------------------- + * + * Solve for x by a modified Newton-Raphson method, using pbeta_raw() + */ + r = 1 - pp; + t = 1 - qq; + double wprev = 0.; + double prev = 1.; + double adj = 1.; + + if (use_log_x) { // find Math.log(xinbta) -- work in u := Math.log(x) scale + // if (bad_init && tx > 0) { xinbta = tx; }// may have been better + for (int i_pb = 0; i_pb < 1000; i_pb++) { + // using log_p == true unconditionally here + // FIXME: if Math.exp(u) = xinbta underflows to 0, like different formula + // pbeta_Math.log(u, *) + y = pbetaRaw(xinbta, pp, qq, /* lower_tail = */ true, true); + + /* + * w := Newton step size for L(u) = log F(e^u) =!= 0; u := Math.log(x) = (L(.) - + * la) / L'(.); L'(u)= (F'(e^u) * e^u ) / F(e^u) = (L(.) - la)*F(.) / {F'(e^u) * + * e^u } = = (L(.) - la) * e^L(.) * e^{-log F'(e^u) - u} = ( y - la) * e^{ y - u + * -log F'(e^u)} and -log F'(x)= -log f(x) = + logbeta + (1-p) Math.log(x) + + * (1-q) Math.log(1-x) = logbeta + (1-p) u + (1-q) Math.log(1-e^u) + */ + w = (y == Double.NEGATIVE_INFINITY) // y = -Inf well possible: we are on + // log scale! + ? 0. : (y - la) * Math.exp(y - u + logbeta + r * u + t * DPQ.rlog1exp(u)); + if (!Double.isFinite(w)) { + break; + } + if (i_pb >= n_N && w * wprev <= 0.) { + prev = RMath.fmax2(Math.abs(adj), fpu); + } + debugPrintf("N(i=%2d): u=%#20.16g, pb(e^u)=%#12.6g, w=%#15.9g, %s prev=%11g,", + i_pb, u, y, w, (w * wprev <= 0.) ? "new" : "old", prev); + g = 1; + int i_inn; + for (i_inn = 0; i_inn < 1000; i_inn++) { + adj = g * w; + // take full Newton steps at the beginning; only then safe guard: + if (i_pb < n_N || Math.abs(adj) < prev) { + u_n = u - adj; // u_{n+1} = u_n - g*w + if (u_n <= 0.) { // <==> 0 < xinbta := e^u <= 1 + if (prev <= acu || Math.abs(w) <= acu) { + /* R_ifDEBUG_printf(" -adj=%g, %s <= acu ==> convergence\n", */ + /* -adj, (prev <= acu) ? "prev" : "|w|"); */ + debugPrintf(" it{in}=%d, -adj=%g, %s <= acu ==> convergence\n", + i_inn, -adj, (prev <= acu) ? "prev" : "|w|"); + converged(log_p, qb); + return; + } + // if (u_n != Double.NEGATIVE_INFINITY && u_n != 1) + break; + } + } + g /= 3; + } + // (cancellation in (u_n -u) => may differ from adj: + D = RMath.fmin2(Math.abs(adj), Math.abs(u_n - u)); + /* R_ifDEBUG_printf(" delta(u)=%g\n", u_n - u); */ + debugPrintf(" it{in}=%d, delta(u)=%9.3g, D/|.|=%.3g\n", + i_inn, u_n - u, D / Math.abs(u_n + u)); + if (D <= 4e-16 * Math.abs(u_n + u)) { + converged(log_p, qb); + return; + } + u = u_n; + xinbta = Math.exp(u); + wprev = w; + } // for(i ) + + } else { + for (int i_pb = 0; i_pb < 1000; i_pb++) { + y = pbetaRaw(xinbta, pp, qq, /* lower_tail = */ true, log_p); + // delta{y} : d_y = y - (log_p ? la : a); + + if (!Double.isFinite(y) && !(log_p && y == Double.NEGATIVE_INFINITY)) { // y = + // -Inf + // is ok if + // (log_p) + RMath.mlError(MLError.DOMAIN, ""); + qb[0] = qb[1] = ML_NAN; + return; + } + + /* + * w := Newton step size (F(.) - a) / F'(.) or, -- log: (lF - la) / (F' / F) = + * Math.exp(lF) * (lF - la) / F' + */ + w = log_p + ? (y - la) * Math.exp(y + logbeta + r * Math.log(xinbta) + t * Math.log1p(-xinbta)) + : (y - a) * Math.exp(logbeta + r * Math.log(xinbta) + t * Math.log1p(-xinbta)); + if (i_pb >= n_N && w * wprev <= 0.) + prev = RMath.fmax2(Math.abs(adj), fpu); + debugPrintf("N(i=%2d): x0=%#17.15g, pb(x0)=%#17.15g, w=%#17.15g, %s prev=%g,", + i_pb, xinbta, y, w, (w * wprev <= 0.) ? "new" : "old", prev); + g = 1; + int i_inn; + for (i_inn = 0; i_inn < 1000; i_inn++) { + adj = g * w; + // take full Newton steps at the beginning; only then safe guard: + if (i_pb < n_N || Math.abs(adj) < prev) { + tx = xinbta - adj; // x_{n+1} = x_n - g*w + if (0. <= tx && tx <= 1.) { + if (prev <= acu || Math.abs(w) <= acu) { + debugPrintf(" it{in}=%d, delta(x)=%g, %s <= acu ==> convergence\n", + i_inn, -adj, (prev <= acu) ? "prev" : "|w|"); + converged(log_p, qb); + return; + } + if (tx != 0. && tx != 1) { + break; + } + } + } + g /= 3; + } + debugPrintf(" it{in}=%d, delta(x)=%g\n", i_inn, tx - xinbta); + if (Math.abs(tx - xinbta) <= 4e-16 * (tx + xinbta)) { // "<=" : (.) == 0 + converged(log_p, qb); + return; + } + xinbta = tx; + if (tx == 0) { // "we have lost" + break; + } + wprev = w; + } + } + + /*-- NOT converged: Iteration count --*/ + warned = true; + RMath.mlError(MLError.PRECISION, "qbeta"); + + converged(log_p, qb); + } + + private void converged(boolean log_p, double[] qb) { + log_ = log_p || use_log_x; // only for printing + debugPrintf(" %s: Final delta(y) = %g%s\n", + warned ? "_NO_ convergence" : "converged", + y - (log_ ? la : a), (log_ ? " (log_)" : "")); + if ((log_ && y == Double.NEGATIVE_INFINITY) || (!log_ && y == 0)) { + // stuck at left, try if smallest positive number is "better" + w = pbetaRaw(DBL_very_MIN, pp, qq, true, log_); + if (log_ || Math.abs(w - a) <= Math.abs(y - a)) { + tx = DBL_very_MIN; + u_n = DBL_log_v_MIN; // = Math.log(DBL_very_MIN) + } + add_N_step = false; // not trying to do better anymore + } else if (!warned && (log_ ? Math.abs(y - la) > 3 : Math.abs(y - a) > 1e-4)) { + if (!(log_ && y == Double.NEGATIVE_INFINITY && + // e.g. qbeta(-1e-10, .2, .03, log=true) cannot get accurate ==> do + // NOT + // warn + pbetaRaw(DBL_1__eps, // = 1 - eps + pp, qq, true, true) > la + 2)) { + RMath.mlWarning(Message.QBETA_ACURACY_WARNING, (log_ ? ", log_" : ""), Math.abs(y - (log_ ? la : a))); + } + } + + finalStep(log_p, qb); + } + + /** + * Represents a block of code that is labelled "L_return" in the original source, should be + * followed by a return. + */ + private void finalStep(boolean log_p, double[] qb) { + if (give_log_q) { // ==> use_log_x , too + if (!use_log_x) { // (see if claim above is true) + RMath.mlWarning(Message.GENERIC, + "qbeta() L_return, u_n=%g; give_log_q=true but use_log_x=false -- please report!", + u_n); + } + + double rr = DPQ.rlog1exp(u_n); + swapTail(qb, swap_tail, u_n, rr); + } else { + if (use_log_x) { + if (add_N_step) { + /* + * add one last Newton step on original x scale, e.g., for qbeta(2^-98, + * 0.125, 2^-96) + */ + double tmpXinbta = Math.exp(u_n); + y = pbetaRaw(tmpXinbta, pp, qq, /* lower_tail = */ true, log_p); + w = log_p + ? (y - la) * Math.exp(y + logbeta + r * Math.log(tmpXinbta) + t * RMath.log1p(-tmpXinbta)) + : (y - a) * Math.exp(logbeta + r * Math.log(tmpXinbta) + t * RMath.log1p(-tmpXinbta)); + tx = tmpXinbta - w; + debugPrintf( + "Final Newton correction(non-log scale): xinbta=%.16g, y=%g, w=%g. => new tx=%.16g\n", + tmpXinbta, y, w, tx); + } else { + swapTail(qb, swap_tail, Math.exp(u_n), -RMath.expm1(u_n)); + return; + } + } + swapTail(qb, swap_tail, tx, 1 - tx); + } + } + + private static void swapTail(double[] qb, boolean swap_tail, double val0, double val1) { + if (swap_tail) { + qb[0] = val1; + qb[1] = val0; + } else { + qb[0] = val0; + qb[1] = val1; + } + } + + private static void returnQ0(double[] qb, boolean give_log_q) { + qb[0] = DPQ.rd0(give_log_q); + qb[1] = DPQ.rd1(give_log_q); + } + + private static void returnQ1(double[] qb, boolean give_log_q) { + qb[0] = DPQ.rd1(give_log_q); + qb[1] = DPQ.rd0(give_log_q); + } + + private static void returnQHalf(double[] qb, boolean give_log_q) { + qb[0] = DPQ.rdhalf(give_log_q); + qb[1] = DPQ.rdhalf(give_log_q); + } + } +} diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Qf.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Qf.java new file mode 100644 index 0000000000000000000000000000000000000000..18488ebd3a267a99aeab1e5b8e81f2bcfd9063b5 --- /dev/null +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Qf.java @@ -0,0 +1,60 @@ +/* + * This material is distributed under the GNU General Public License + * Version 2. You may review the terms of this license at + * http://www.gnu.org/licenses/gpl-2.0.html + * + * Copyright (C) 1998 Ross Ihaka + * Copyright (c) 2000--2015, The R Core Team + * Copyright (c) 2005, The R Foundation + * Copyright (c) 2016, Oracle and/or its affiliates + * + * All rights reserved. + */ +package com.oracle.truffle.r.library.stats; + +import com.oracle.truffle.r.library.stats.Chisq.QChisq; +import com.oracle.truffle.r.library.stats.DPQ.EarlyReturn; +import com.oracle.truffle.r.library.stats.StatsFunctions.Function3_2; + +public final class Qf implements Function3_2 { + private final QBeta qbeta = new QBeta(); + private final QChisq qchisq = new QChisq(); + + @Override + public double evaluate(double p, double df1, double df2, boolean lowerTail, boolean logP) { + + if (Double.isNaN(p) || Double.isNaN(df1) || Double.isNaN(df2)) { + return p + df1 + df2; + } + + if (df1 <= 0. || df2 <= 0.) { + return RMath.mlError(); + } + + try { + DPQ.rqp01boundaries(p, 0, Double.POSITIVE_INFINITY, lowerTail, logP); + } catch (EarlyReturn e) { + return e.result; + } + + /* + * fudge the extreme DF cases -- qbeta doesn't do this well. But we still need to fudge the + * infinite ones. + */ + + if (df1 <= df2 && df2 > 4e5) { + if (!Double.isFinite(df1)) { /* df1 == df2 == Inf : */ + return 1.; + } else { + return qchisq.evaluate(p, df1, lowerTail, logP) / df1; + } + } + if (df1 > 4e5) { /* and so df2 < df1 */ + return df2 / qchisq.evaluate(p, df2, !lowerTail, logP); + } + + // FIXME: (1/qb - 1) = (1 - qb)/qb; if we know qb ~= 1, should use other tail + p = (1. / qbeta.evaluate(p, df2 / 2, df1 / 2, !lowerTail, logP) - 1.) * (df2 / df1); + return RMath.mlValid(p) ? p : Double.NaN; + } +} diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RChisq.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RChisq.java deleted file mode 100644 index 975819f6bf3be065b8036f7c4c4aeb2b512db474..0000000000000000000000000000000000000000 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RChisq.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This material is distributed under the GNU General Public License - * Version 2. You may review the terms of this license at - * http://www.gnu.org/licenses/gpl-2.0.html - * - * Copyright (C) 1998 Ross Ihaka - * Copyright (c) 1998--2008, The R Core Team - * Copyright (c) 2016, 2016, Oracle and/or its affiliates - * - * All rights reserved. - */ -package com.oracle.truffle.r.library.stats; - -import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandFunction1_Double; -import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandomNumberProvider; - -public final class RChisq extends RandFunction1_Double { - public static double rchisq(double df, RandomNumberProvider rand) { - if (!Double.isFinite(df) || df < 0.0) { - return RMath.mlError(); - } - return new RGamma().execute(df / 2.0, 2.0, rand); - } - - @Override - public double execute(double a, RandomNumberProvider rand) { - return rchisq(a, rand); - } -} diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java index 49fc18d2d6df471eb0afffc46633af0776b25037..644dff67b50c3d46d7608bb10c5401f973a6d665 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java @@ -16,6 +16,7 @@ import static com.oracle.truffle.r.library.stats.LBeta.lbeta; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; /** @@ -26,13 +27,36 @@ import com.oracle.truffle.r.runtime.RRuntime; */ public class RMath { + public enum MLError { + DOMAIN, + RANGE, + NOCONV, + PRECISION, + UNDERFLOW + } + /** - * corresponds to macro {@code ML_ERR_return_NAN} in GnuR. + * Corresponds to macro {@code ML_ERR_return_NAN} in GnuR. */ public static double mlError() { + return mlError(MLError.DOMAIN, ""); + } + + /** + * Corresponds to macro {@code ML_ERR} in GnuR. TODO: raise corresponding warning + */ + public static double mlError(@SuppressWarnings("unused") MLError error, @SuppressWarnings("unused") String message) { return Double.NaN; } + public static void mlWarning(RError.Message message, Object... args) { + RError.warning(null, message, args); + } + + public static boolean mlValid(double d) { + return !Double.isNaN(d); + } + public static double lfastchoose(double n, double k) { return -Math.log(n + 1.) - lbeta(n - k + 1., k + 1.); } @@ -56,7 +80,7 @@ public class RMath { return ((y >= 0) ? TOMS708.fabs(x) : -TOMS708.fabs(x)); } - public static double fmod(double a, double b) { + private static double fmod(double a, double b) { double q = a / b; if (b != 0) { double tmp = a - Math.floor(q) * b; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNchisq.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNchisq.java index 3b17100cc5cad25ce2b30d84993069af020931fc..12dc037c2c18aae629e67fe502c97dfe86cb35e3 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNchisq.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNchisq.java @@ -30,7 +30,7 @@ public final class RNchisq extends RandFunction2_Double { } else { double r = RPois.rpois(lambda / 2., rand); if (r > 0.) { - r = RChisq.rchisq(2. * r, rand); + r = Chisq.RChisq.rchisq(2. * r, rand); } if (df > 0.) { r += rgamma.execute(df / 2., 2., rand); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rf.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rf.java index c753f1777fe6e31adb429f4ae2779b1d951bea3c..be70cde936be8c393b14a9743bdce13d68366585 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rf.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rf.java @@ -23,8 +23,8 @@ public final class Rf extends RandFunction2_Double { double v1; double v2; - v1 = Double.isFinite(n1) ? (RChisq.rchisq(n1, rand) / n1) : 1; - v2 = Double.isFinite(n2) ? (RChisq.rchisq(n2, rand) / n2) : 1; + v1 = Double.isFinite(n1) ? (Chisq.RChisq.rchisq(n1, rand) / n1) : 1; + v2 = Double.isFinite(n2) ? (Chisq.RChisq.rchisq(n2, rand) / n2) : 1; return v1 / v2; } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rt.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rt.java index 80c8ea59fc6e6b06560ceac696d508d192bb1d59..a319beed65cf78521fccb36b2b81070fbce797e3 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rt.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rt.java @@ -11,7 +11,7 @@ */ package com.oracle.truffle.r.library.stats; -import static com.oracle.truffle.r.library.stats.RChisq.rchisq; +import static com.oracle.truffle.r.library.stats.Chisq.RChisq.rchisq; import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandFunction1_Double; import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandomNumberProvider; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java index 0c2e5d5d50843b51d2f8dc82af8339fd088233b1..af77f17ef2cb353ab1e94c2eabf828b99a15bb7a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/CallAndExternalFunctions.java @@ -46,6 +46,7 @@ import com.oracle.truffle.r.library.stats.Cauchy.PCauchy; import com.oracle.truffle.r.library.stats.Cauchy.RCauchy; import com.oracle.truffle.r.library.stats.CdistNodeGen; import com.oracle.truffle.r.library.stats.Chisq; +import com.oracle.truffle.r.library.stats.Chisq.RChisq; import com.oracle.truffle.r.library.stats.CompleteCases; import com.oracle.truffle.r.library.stats.CovcorNodeGen; import com.oracle.truffle.r.library.stats.CutreeNodeGen; @@ -77,12 +78,13 @@ import com.oracle.truffle.r.library.stats.Pbinom; import com.oracle.truffle.r.library.stats.Pf; import com.oracle.truffle.r.library.stats.Pnorm; import com.oracle.truffle.r.library.stats.Pt; +import com.oracle.truffle.r.library.stats.QBeta; import com.oracle.truffle.r.library.stats.QPois; import com.oracle.truffle.r.library.stats.Qbinom; +import com.oracle.truffle.r.library.stats.Qf; import com.oracle.truffle.r.library.stats.Qnorm; import com.oracle.truffle.r.library.stats.Qt; import com.oracle.truffle.r.library.stats.RBeta; -import com.oracle.truffle.r.library.stats.RChisq; import com.oracle.truffle.r.library.stats.RGamma; import com.oracle.truffle.r.library.stats.RHyper; import com.oracle.truffle.r.library.stats.RMultinomNodeGen; @@ -151,7 +153,7 @@ import com.oracle.truffle.r.runtime.ffi.RFFIFactory; public class CallAndExternalFunctions { @TruffleBoundary - protected static Object encodeArgumentPairList(RArgsValuesAndNames args, String symbolName) { + private static Object encodeArgumentPairList(RArgsValuesAndNames args, String symbolName) { Object list = RNull.instance; for (int i = args.getLength() - 1; i >= 0; i--) { String name = args.getSignature().getName(i); @@ -161,8 +163,8 @@ public class CallAndExternalFunctions { return list; } - protected abstract static class CallRFFIAdapter extends LookupAdapter { - @Child protected CallRFFI.CallRFFINode callRFFINode = RFFIFactory.getRFFI().getCallRFFI().createCallRFFINode(); + abstract static class CallRFFIAdapter extends LookupAdapter { + @Child CallRFFI.CallRFFINode callRFFINode = RFFIFactory.getRFFI().getCallRFFI().createCallRFFINode(); } /** @@ -321,6 +323,8 @@ public class CallAndExternalFunctions { return StatsFunctionsFactory.Function3_2NodeGen.create(new Pbinom()); case "pbeta": return StatsFunctionsFactory.Function3_2NodeGen.create(new Pbeta()); + case "qbeta": + return StatsFunctionsFactory.Function3_2NodeGen.create(new QBeta()); case "dcauchy": return StatsFunctionsFactory.Function3_1NodeGen.create(new DCauchy()); case "pcauchy": @@ -329,12 +333,16 @@ public class CallAndExternalFunctions { return StatsFunctionsFactory.Function3_2NodeGen.create(new Cauchy.QCauchy()); case "pf": return StatsFunctionsFactory.Function3_2NodeGen.create(new Pf()); + case "qf": + return StatsFunctionsFactory.Function3_2NodeGen.create(new Qf()); case "df": return StatsFunctionsFactory.Function3_1NodeGen.create(new Df()); case "dgamma": return StatsFunctionsFactory.Function3_1NodeGen.create(new DGamma()); case "dchisq": return StatsFunctionsFactory.Function2_1NodeGen.create(new Chisq.DChisq()); + case "qchisq": + return StatsFunctionsFactory.Function2_2NodeGen.create(new Chisq.QChisq()); case "qgeom": return StatsFunctionsFactory.Function2_2NodeGen.create(new Geom.QGeom()); case "pchisq": diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java index 39504baf8e90020ba7d51c19460d27a600f91e3e..e61db9860abc7e1c0f104a9ab3636eca04da66f1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java @@ -527,6 +527,7 @@ public final class RError extends RuntimeException { NA_IN_PROB_VECTOR("NA in probability vector"), NEGATIVE_PROBABILITY("negative probability"), NO_POSITIVE_PROBABILITIES("no positive probabilities"), + QBETA_ACURACY_WARNING("qbeta(a, *) =: x0 with |pbeta(x0,*%s) - alpha| = %.5g is not accurate"), NON_POSITIVE_FILL("non-positive 'fill' argument will be ignored"), MUST_BE_ONE_BYTE("invalid %s: must be one byte"), INVALID_DECIMAL_SEP("invalid decimal separator"), diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 4db011572edfcacd82d7ffa5b4a39100807a8736..73b843b971b492e3558aa114de2c6588901f200f 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -111459,6 +111459,157 @@ Error: 'x' is NULL #.Call(stats:::C_cov, c('1','2','3','4','5'), 1:5, 4, FALSE) [1] 2.5 +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.1, 0, 0, lower.tail=F, log.p=F) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.1, 0, 0, lower.tail=T, log.p=F) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.5, 0, 0, lower.tail=F, log.p=F) +[1] 0.5 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.5, 0, 0, lower.tail=T, log.p=F) +[1] 0.5 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.7, 0, 0, lower.tail=F, log.p=F) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.7, 0, 0, lower.tail=T, log.p=F) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.7, 0, 1/0, lower.tail=F, log.p=F) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.7, 0, 1/0, lower.tail=T, log.p=F) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.7, 1/0, 0, lower.tail=F, log.p=F) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(0.7, 1/0, 0, lower.tail=T, log.p=F) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(0), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(0), -1, 3, lower.tail = T, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0), 0.1, 3, lower.tail=T, log.p=T) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(0.1), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(0.1), -1, 3, lower.tail = T, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.1), 0, 0, lower.tail=F, log.p=T) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.1), 0, 0, lower.tail=T, log.p=T) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.1), 0.1, 3, lower.tail=T, log.p=T) +[1] 2.366901e-11 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(0.5), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(0.5), -1, 3, lower.tail = T, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.5), 0, 0, lower.tail=F, log.p=T) +[1] 0.5 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.5), 0, 0, lower.tail=T, log.p=T) +[1] 0.5 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.5), 0.1, 3, lower.tail=T, log.p=T) +[1] 0.0002312399 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(0.7), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(0.7), -1, 3, lower.tail = T, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 0, 0, lower.tail=F, log.p=T) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 0, 0, lower.tail=T, log.p=T) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 0, 1/0, lower.tail=F, log.p=T) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 0, 1/0, lower.tail=T, log.p=T) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 0.1, 3, lower.tail=T, log.p=T) +[1] 0.006768603 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 1/0, 0, lower.tail=F, log.p=T) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(0.7), 1/0, 0, lower.tail=T, log.p=T) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(1), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(1), -1, 3, lower.tail = T, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(1), 0.1, 3, lower.tail=T, log.p=T) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(1-42e-80), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(1 - 4.2e-79), -1, 3, lower.tail = T, log.p = T) : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(1-42e-80), 0.1, 3, lower.tail=T, log.p=T) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta#Output.MayIgnoreWarningContext# +#qbeta(log(42e-80), -1, 3, lower.tail=T, log.p=T) +[1] NaN +Warning message: +In qbeta(log(4.2e-79), -1, 3, lower.tail = T, log.p = T) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestExternal_qbeta.testQBeta# +#qbeta(log(42e-80), 0.1, 3, lower.tail=T, log.p=T) +[1] 1.112537e-308 + ##com.oracle.truffle.r.test.library.stats.TestExternal_qgamma.testQgamma# #qgamma(0, 1) [1] 0 @@ -114922,6 +115073,104 @@ In pgeom(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) : NaNs produced Warning message: In pgeom(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : NaNs produced +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, 10, lower.tail=FALSE, log.p=FALSE) +[1] 0.9999546 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, 10, lower.tail=FALSE, log.p=TRUE) +[1] -4.540096e-05 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, 10, lower.tail=TRUE, log.p=FALSE) +[1] 4.539993e-05 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, 10, lower.tail=TRUE, log.p=TRUE) +[1] -10 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=FALSE, log.p=FALSE) +[1] 6.321361e-02 1.229924e-04 3.200000e-79 1.000000e+00 1.000000e+00 +[6] 0.000000e+00 NaN +Warning message: +In ppois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=FALSE, log.p=TRUE) +[1] -2.761236 -9.003388 -180.741072 0.000000 0.000000 -Inf +[7] NaN +Warning message: +In ppois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=TRUE, log.p=FALSE) +[1] 0.9367864 0.9998770 1.0000000 0.0000000 0.0000000 1.0000000 NaN +Warning message: +In ppois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=TRUE, log.p=TRUE) +[1] -6.530e-02 -1.230e-04 -3.200e-79 -8.833e+03 -7.900e+71 0.000e+00 NaN +Warning message: +In ppois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=FALSE, log.p=FALSE) + [1] NaN 0.0000000000 0.0951625820 0.0628569343 1.0000000000 + [6] NaN 0.0000000000 0.0001546531 1.0000000000 0.9502129316 +[11] NaN 0.0000000000 1.0000000000 0.5934303403 0.9502129316 +[16] NaN 1.0000000000 0.0951625820 0.5934303403 0.5768099189 +Warning message: +In ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = FALSE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=FALSE, log.p=TRUE) + [1] NaN -Inf -2.35216846 -2.76689402 0.00000000 NaN + [7] -Inf -8.77432621 0.00000000 -0.05106918 NaN -Inf +[13] 0.00000000 -0.52183544 -0.05106918 NaN 0.00000000 -2.35216846 +[19] -0.52183544 -0.55024250 +Warning message: +In ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = FALSE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=TRUE, log.p=FALSE) + [1] NaN 1.00000000 0.90483742 0.93714307 0.00000000 NaN + [7] 1.00000000 0.99984535 0.00000000 0.04978707 NaN 1.00000000 +[13] 0.00000000 0.40656966 0.04978707 NaN 0.00000000 0.90483742 +[19] 0.40656966 0.42319008 +Warning message: +In ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = TRUE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=TRUE, log.p=TRUE) + [1] NaN 0.000000000 -0.100000000 -0.064919324 -Inf + [6] NaN 0.000000000 -0.000154665 -Inf -3.000000000 +[11] NaN 0.000000000 -Inf -0.900000000 -3.000000000 +[16] NaN -Inf -0.100000000 -0.900000000 -0.859933837 +Warning message: +In ppois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = TRUE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) + [1] NA 1.0000000 NaN 1.0000000 0.0000000 NA 0.3678794 + [8] NaN 1.0000000 0.0000000 NA 0.9048374 NaN 1.0000000 +[15] 0.0000000 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); ppois(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) + [1] NA 1 NaN 0 NaN NA 1 NaN 0 NaN NA 1 NaN 0 NaN +Warning message: +In ppois(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# #set.seed(1); pt(0, 10, lower.tail=FALSE, log.p=FALSE) [1] 0.5 @@ -115019,6 +115268,92 @@ In pt(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) : NaNs produced Warning message: In pt(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : NaNs produced +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, 10, lower.tail=FALSE, log.p=FALSE) +[1] Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, 10, lower.tail=FALSE, log.p=TRUE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, 10, lower.tail=TRUE, log.p=FALSE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, 10, lower.tail=TRUE, log.p=TRUE) +[1] Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=FALSE, log.p=FALSE) +[1] Inf Inf Inf Inf Inf Inf Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=FALSE, log.p=TRUE) +[1] 0 0 0 0 0 0 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=TRUE, log.p=FALSE) +[1] 0 0 0 0 0 0 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=TRUE, log.p=TRUE) +[1] Inf Inf Inf Inf Inf Inf Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=FALSE, log.p=FALSE) + [1] NaN Inf 0.013564 NaN NaN Inf 0.000000 NaN + [9] NaN Inf NaN NaN NaN Inf 4.641628 NaN +[17] NaN Inf 1.468957 NaN +Warning message: +In qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = FALSE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=FALSE, log.p=TRUE) + [1] NaN 0.000000000 NaN NaN 3.158142952 0.000000000 + [7] NaN NaN 0.691572992 0.000000000 NaN NaN +[13] 0.000121286 0.000000000 NaN NaN 0.000000000 0.000000000 +[19] NaN NaN +Warning message: +In qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = FALSE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=TRUE, log.p=FALSE) + [1] NaN 0.000000e+00 1.225708e-14 NaN NaN + [6] 0.000000e+00 0.000000e+00 NaN NaN 0.000000e+00 +[11] NaN NaN NaN 0.000000e+00 1.005174e+00 +[16] NaN NaN 0.000000e+00 4.335644e-02 NaN +Warning message: +In qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = TRUE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=TRUE, log.p=TRUE) + [1] NaN Inf NaN NaN 1.721698e+00 + [6] Inf NaN NaN 1.756852e-01 Inf +[11] NaN NaN 2.409337e-09 Inf NaN +[16] NaN 0.000000e+00 Inf NaN NaN +Warning message: +In qchisq(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = TRUE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) + [1] NA 0 NaN NaN NaN NA 0 NaN NaN NaN NA 0 NaN NaN NaN +Warning message: +In qchisq(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qchisq(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) + [1] NA 0 NaN Inf 0 NA Inf NaN Inf Inf NA 0 NaN 0 NaN +Warning messages: +1: In qchisq(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : + value out of range in 'lgamma' +2: In qchisq(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : + NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# #set.seed(1); qexp(0, 10, lower.tail=FALSE, log.p=FALSE) [1] Inf @@ -115210,6 +115545,94 @@ In qgeom(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) : NaNs produced Warning message: In qgeom(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : NaNs produced +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, 10, lower.tail=FALSE, log.p=FALSE) +[1] Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, 10, lower.tail=FALSE, log.p=TRUE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, 10, lower.tail=TRUE, log.p=FALSE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, 10, lower.tail=TRUE, log.p=TRUE) +[1] Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=FALSE, log.p=FALSE) +[1] Inf Inf Inf Inf Inf 0 NaN +Warning message: +In qpois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=FALSE, log.p=TRUE) +[1] 0 0 0 0 0 0 NaN +Warning message: +In qpois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=TRUE, log.p=FALSE) +[1] 0 0 0 0 0 0 NaN +Warning message: +In qpois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), lower.tail=TRUE, log.p=TRUE) +[1] Inf Inf Inf Inf Inf 0 NaN +Warning message: +In qpois(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=FALSE, log.p=FALSE) + [1] NaN 0 0 NaN NaN NaN 0 NaN NaN Inf NaN 0 NaN Inf 4 NaN 0 Inf 2 +[20] NaN +Warning message: +In qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = FALSE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=FALSE, log.p=TRUE) + [1] NaN 0 NaN NaN 3 NaN 0 NaN 1 0 NaN 0 0 0 NaN NaN 0 0 NaN +[20] NaN +Warning message: +In qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = FALSE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=TRUE, log.p=FALSE) + [1] NaN 0 0 NaN NaN NaN 0 NaN NaN 0 NaN 0 NaN 0 2 NaN 0 0 0 +[20] NaN +Warning message: +In qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = TRUE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail=TRUE, log.p=TRUE) + [1] NaN 0 NaN NaN 2 NaN 0 NaN 0 Inf NaN 0 0 Inf NaN NaN 0 Inf NaN +[20] NaN +Warning message: +In qpois(c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4), lower.tail = TRUE, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) + [1] NA 0 NaN NaN 0 NA 0 NaN NaN NaN NA 0 NaN 0 NaN +Warning message: +In qpois(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) : NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# +#set.seed(1); qpois(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) + [1] NA 0 NaN NaN NaN NA 0 NaN NaN NaN NA 0 NaN NaN NaN +Warning message: +In qpois(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) : NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions22#Output.IgnoreWhitespace# #set.seed(1); qt(0, 10, lower.tail=FALSE, log.p=FALSE) [1] Inf @@ -117146,6 +117569,185 @@ Warning message: In punif(rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, : NaNs produced +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, 10, 10, lower.tail=FALSE, log.p=FALSE) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, 10, 10, lower.tail=FALSE, log.p=TRUE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, 10, 10, lower.tail=TRUE, log.p=FALSE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, 10, 10, lower.tail=TRUE, log.p=TRUE) +[1] 1 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=FALSE, log.p=FALSE) + [1] 1 1 1 1 1 1 NaN 1 1 1 1 1 1 NaN 1 1 1 1 1 +[20] 1 NaN 1 1 1 1 1 1 NaN 1 1 1 1 1 1 NaN +Warning message: +In qbeta(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=FALSE, log.p=TRUE) + [1] 0 0 0 0 0 0 NaN 0 0 0 0 0 0 NaN 0 0 0 0 0 +[20] 0 NaN 0 0 0 0 0 0 NaN 0 0 0 0 0 0 NaN +Warning message: +In qbeta(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=TRUE, log.p=FALSE) + [1] 0 0 0 0 0 0 NaN 0 0 0 0 0 0 NaN 0 0 0 0 0 +[20] 0 NaN 0 0 0 0 0 0 NaN 0 0 0 0 0 0 NaN +Warning message: +In qbeta(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=TRUE, log.p=TRUE) + [1] 1 1 1 1 1 1 NaN 1 1 1 1 1 1 NaN 1 1 1 1 1 +[20] 1 NaN 1 1 1 1 1 1 NaN 1 1 1 1 1 1 NaN +Warning message: +In qbeta(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=FALSE, log.p=FALSE) + [1] NaN 1.0000000 0.1073742 NaN NaN NaN NaN + [8] NaN NaN 1.0000000 NaN NaN NaN 1.0000000 + [15] 0.9283178 NaN NaN 1.0000000 NaN NaN NaN + [22] 1.0000000 NaN NaN NaN NaN 0.0000000 NaN + [29] NaN 1.0000000 NaN NaN NaN 1.0000000 NaN + [36] NaN NaN 1.0000000 0.7804089 NaN NaN 1.0000000 + [43] NaN NaN NaN NaN NaN NaN NaN + [50] 1.0000000 NaN NaN NaN 1.0000000 NaN NaN + [57] NaN 1.0000000 NaN NaN NaN 1.0000000 0.1073742 + [64] NaN NaN NaN NaN NaN NaN 1.0000000 + [71] NaN NaN NaN 1.0000000 0.9283178 NaN NaN + [78] 1.0000000 NaN NaN NaN 1.0000000 NaN NaN + [85] NaN NaN 0.0000000 NaN NaN 1.0000000 NaN + [92] NaN NaN 1.0000000 NaN NaN NaN 1.0000000 + [99] 0.7804089 NaN NaN 1.0000000 NaN NaN NaN +[106] NaN NaN NaN NaN 1.0000000 NaN NaN +[113] NaN 1.0000000 NaN NaN NaN 1.0000000 NaN +[120] NaN +Warning message: +In qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=FALSE, log.p=TRUE) + [1] NaN 0.00000000 NaN NaN NaN NaN + [7] NaN NaN 0.60071237 0.00000000 NaN NaN + [13] NaN 0.00000000 NaN NaN NaN 0.00000000 + [19] NaN NaN NaN 0.00000000 NaN NaN + [25] NaN NaN NaN NaN NaN 0.00000000 + [31] NaN NaN 0.01018589 0.00000000 NaN NaN + [37] NaN 0.00000000 NaN NaN NaN 0.00000000 + [43] NaN NaN 0.85822265 NaN NaN NaN + [49] NaN 0.00000000 NaN NaN NaN 0.00000000 + [55] NaN NaN 0.00000000 0.00000000 NaN NaN + [61] NaN 0.00000000 NaN NaN NaN NaN + [67] NaN NaN 0.60071237 0.00000000 NaN NaN + [73] NaN 0.00000000 NaN NaN NaN 0.00000000 + [79] NaN NaN NaN 0.00000000 NaN NaN + [85] NaN NaN NaN NaN NaN 0.00000000 + [91] NaN NaN 0.01018589 0.00000000 NaN NaN + [97] NaN 0.00000000 NaN NaN NaN 0.00000000 +[103] NaN NaN 0.85822265 NaN NaN NaN +[109] NaN 0.00000000 NaN NaN NaN 0.00000000 +[115] NaN NaN 0.00000000 0.00000000 NaN NaN +Warning message: +In qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=TRUE, log.p=FALSE) + [1] NaN 0.0000000000 0.0000001024 NaN NaN + [6] NaN NaN NaN NaN 0.0000000000 + [11] NaN NaN NaN 0.0000000000 0.5848035476 + [16] NaN NaN 0.0000000000 NaN NaN + [21] NaN 0.0000000000 NaN NaN NaN + [26] NaN 0.0000000000 NaN NaN 0.0000000000 + [31] NaN NaN NaN 0.0000000000 NaN + [36] NaN NaN 0.0000000000 0.1672502062 NaN + [41] NaN 0.0000000000 NaN NaN NaN + [46] NaN NaN NaN NaN 0.0000000000 + [51] NaN NaN NaN 0.0000000000 NaN + [56] NaN NaN 0.0000000000 NaN NaN + [61] NaN 0.0000000000 0.0000001024 NaN NaN + [66] NaN NaN NaN NaN 0.0000000000 + [71] NaN NaN NaN 0.0000000000 0.5848035476 + [76] NaN NaN 0.0000000000 NaN NaN + [81] NaN 0.0000000000 NaN NaN NaN + [86] NaN 0.0000000000 NaN NaN 0.0000000000 + [91] NaN NaN NaN 0.0000000000 NaN + [96] NaN NaN 0.0000000000 0.1672502062 NaN +[101] NaN 0.0000000000 NaN NaN NaN +[106] NaN NaN NaN NaN 0.0000000000 +[111] NaN NaN NaN 0.0000000000 NaN +[116] NaN NaN 0.0000000000 NaN NaN +Warning message: +In qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=TRUE, log.p=TRUE) + [1] NaN 1.000000e+00 NaN NaN NaN + [6] NaN NaN NaN 3.291930e-01 1.000000e+00 + [11] NaN NaN NaN 1.000000e+00 NaN + [16] NaN NaN 1.000000e+00 NaN NaN + [21] NaN 1.000000e+00 NaN NaN NaN + [26] NaN NaN NaN NaN 1.000000e+00 + [31] NaN NaN 4.539993e-05 1.000000e+00 NaN + [36] NaN NaN 1.000000e+00 NaN NaN + [41] NaN 1.000000e+00 NaN NaN 7.165313e-01 + [46] NaN NaN NaN NaN 1.000000e+00 + [51] NaN NaN NaN 1.000000e+00 NaN + [56] NaN 0.000000e+00 1.000000e+00 NaN NaN + [61] NaN 1.000000e+00 NaN NaN NaN + [66] NaN NaN NaN 3.291930e-01 1.000000e+00 + [71] NaN NaN NaN 1.000000e+00 NaN + [76] NaN NaN 1.000000e+00 NaN NaN + [81] NaN 1.000000e+00 NaN NaN NaN + [86] NaN NaN NaN NaN 1.000000e+00 + [91] NaN NaN 4.539993e-05 1.000000e+00 NaN + [96] NaN NaN 1.000000e+00 NaN NaN +[101] NaN 1.000000e+00 NaN NaN 7.165313e-01 +[106] NaN NaN NaN NaN 1.000000e+00 +[111] NaN NaN NaN 1.000000e+00 NaN +[116] NaN 0.000000e+00 1.000000e+00 NaN NaN +Warning message: +In qbeta(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5)) + [1] NA 0 NaN NaN NaN NA 0 NaN NaN NaN NA 0 NaN NaN NaN +Warning message: +In qbeta(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5), rep(c(1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) + [1] NA 0 NaN 1 NaN NA 1 NaN 1 NaN NA 0 NaN 0 NaN +Warning message: +In qbeta(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0), rep(c(1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qbeta(rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) + [1] NA 0 NaN 1 NaN NA 1 NaN 0 NaN NA 1 NaN 0 NaN +Warning message: +In qbeta(rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, : + NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# #set.seed(1); qbinom(0, 10, 10, lower.tail=FALSE, log.p=FALSE) [1] NaN @@ -117446,6 +118048,190 @@ Warning message: In qcauchy(rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5), c(NA, 0, : NaNs produced +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, 10, 10, lower.tail=FALSE, log.p=FALSE) +[1] Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, 10, 10, lower.tail=FALSE, log.p=TRUE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, 10, 10, lower.tail=TRUE, log.p=FALSE) +[1] 0 + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, 10, 10, lower.tail=TRUE, log.p=TRUE) +[1] Inf + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=FALSE, log.p=FALSE) + [1] Inf Inf Inf Inf Inf NaN NaN Inf Inf Inf Inf Inf NaN NaN Inf Inf Inf Inf Inf +[20] NaN NaN Inf Inf Inf Inf Inf NaN NaN Inf Inf Inf Inf Inf NaN NaN +Warning message: +In qf(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), rep(c(0.0653, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=FALSE, log.p=TRUE) + [1] 0 0 0 0 0 NaN NaN 0 0 0 0 0 NaN NaN 0 0 0 0 0 +[20] NaN NaN 0 0 0 0 0 NaN NaN 0 0 0 0 0 NaN NaN +Warning message: +In qf(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), rep(c(0.0653, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=TRUE, log.p=FALSE) + [1] 0 0 0 0 0 NaN NaN 0 0 0 0 0 NaN NaN 0 0 0 0 0 +[20] NaN NaN 0 0 0 0 0 NaN NaN 0 0 0 0 0 NaN NaN +Warning message: +In qf(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), rep(c(0.0653, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(0, c(0.0653, 0.000123, 32e-80, 8833, 79e70, 0, -1), rep(c(0.0653, 0.000123, 32e-80, 8833, 79e70), 7), lower.tail=TRUE, log.p=TRUE) + [1] Inf Inf Inf Inf Inf NaN NaN Inf Inf Inf Inf Inf NaN NaN Inf Inf Inf Inf Inf +[20] NaN NaN Inf Inf Inf Inf Inf NaN NaN Inf Inf Inf Inf Inf NaN NaN +Warning message: +In qf(0, c(0.0653, 0.000123, 3.2e-79, 8833, 7.9e+71, 0, -1), rep(c(0.0653, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=FALSE, log.p=FALSE) + [1] NaN NaN 0.4368535 NaN NaN NaN + [7] NaN NaN NaN Inf NaN NaN + [13] NaN NaN 13.0639281 NaN NaN Inf + [19] NaN NaN NaN NaN NaN NaN + [25] NaN NaN NaN NaN NaN Inf + [31] NaN NaN NaN Inf NaN NaN + [37] NaN NaN 9.0192419 NaN NaN NaN + [43] NaN NaN NaN NaN NaN NaN + [49] NaN NaN NaN NaN NaN Inf + [55] NaN NaN NaN Inf NaN NaN + [61] NaN NaN 0.4368535 NaN NaN NaN + [67] NaN NaN NaN Inf NaN NaN + [73] NaN NaN 13.0639281 NaN NaN Inf + [79] NaN NaN NaN NaN NaN NaN + [85] NaN NaN NaN NaN NaN Inf + [91] NaN NaN NaN Inf NaN NaN + [97] NaN NaN 9.0192419 NaN NaN NaN +[103] NaN NaN NaN NaN NaN NaN +[109] NaN NaN NaN NaN NaN Inf +[115] NaN NaN NaN Inf NaN NaN +Warning message: +In qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=FALSE, log.p=TRUE) + [1] NaN NaN NaN NaN NaN NaN + [7] NaN NaN 2.19885391 0.00000000 NaN NaN + [13] NaN NaN NaN NaN NaN 0.00000000 + [19] NaN NaN NaN NaN NaN NaN + [25] NaN NaN NaN NaN NaN 0.00000000 + [31] NaN NaN 0.00384456 0.00000000 NaN NaN + [37] NaN NaN NaN NaN NaN NaN + [43] NaN NaN 3.54447244 NaN NaN NaN + [49] NaN NaN NaN NaN NaN 0.00000000 + [55] NaN NaN NaN 0.00000000 NaN NaN + [61] NaN NaN NaN NaN NaN NaN + [67] NaN NaN 2.19885391 0.00000000 NaN NaN + [73] NaN NaN NaN NaN NaN 0.00000000 + [79] NaN NaN NaN NaN NaN NaN + [85] NaN NaN NaN NaN NaN 0.00000000 + [91] NaN NaN 0.00384456 0.00000000 NaN NaN + [97] NaN NaN NaN NaN NaN NaN +[103] NaN NaN 3.54447244 NaN NaN NaN +[109] NaN NaN NaN NaN NaN 0.00000000 +[115] NaN NaN NaN 0.00000000 NaN NaN +Warning message: +In qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=TRUE, log.p=FALSE) + [1] NaN NaN 3.885781e-13 NaN NaN + [6] NaN NaN NaN NaN 0.000000e+00 + [11] NaN NaN NaN NaN 3.728274e-01 + [16] NaN NaN 0.000000e+00 NaN NaN + [21] NaN NaN NaN NaN NaN + [26] NaN NaN NaN NaN 0.000000e+00 + [31] NaN NaN NaN 0.000000e+00 NaN + [36] NaN NaN NaN 8.286649e-02 NaN + [41] NaN NaN NaN NaN NaN + [46] NaN NaN NaN NaN NaN + [51] NaN NaN NaN 0.000000e+00 NaN + [56] NaN NaN 0.000000e+00 NaN NaN + [61] NaN NaN 3.885781e-13 NaN NaN + [66] NaN NaN NaN NaN 0.000000e+00 + [71] NaN NaN NaN NaN 3.728274e-01 + [76] NaN NaN 0.000000e+00 NaN NaN + [81] NaN NaN NaN NaN NaN + [86] NaN NaN NaN NaN 0.000000e+00 + [91] NaN NaN NaN 0.000000e+00 NaN + [96] NaN NaN NaN 8.286649e-02 NaN +[101] NaN NaN NaN NaN NaN +[106] NaN NaN NaN NaN NaN +[111] NaN NaN NaN 0.000000e+00 NaN +[116] NaN NaN 0.000000e+00 NaN NaN +Warning message: +In qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20), lower.tail=TRUE, log.p=TRUE) + [1] NaN NaN NaN NaN NaN + [6] NaN NaN NaN 3.712400e-01 Inf + [11] NaN NaN NaN NaN NaN + [16] NaN NaN Inf NaN NaN + [21] NaN NaN NaN NaN NaN + [26] NaN NaN NaN NaN Inf + [31] NaN NaN 7.636093e-08 Inf NaN + [36] NaN NaN NaN NaN NaN + [41] NaN NaN NaN NaN 8.941077e-01 + [46] NaN NaN NaN NaN NaN + [51] NaN NaN NaN Inf NaN + [56] NaN NaN Inf NaN NaN + [61] NaN NaN NaN NaN NaN + [66] NaN NaN NaN 3.712400e-01 Inf + [71] NaN NaN NaN NaN NaN + [76] NaN NaN Inf NaN NaN + [81] NaN NaN NaN NaN NaN + [86] NaN NaN NaN NaN Inf + [91] NaN NaN 7.636093e-08 Inf NaN + [96] NaN NaN NaN NaN NaN +[101] NaN NaN NaN NaN 8.941077e-01 +[106] NaN NaN NaN NaN NaN +[111] NaN NaN NaN Inf NaN +[116] NaN NaN Inf NaN NaN +Warning message: +In qf(c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5)) + [1] NA NaN NaN NaN NaN NA 0 NaN NaN NaN NA 0 NaN NaN NaN +Warning message: +In qf(c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5), rep(c(1, 0, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, 0.1), 5)) + [1] NA NaN NaN Inf NaN NA NaN NaN + [9] 0.655161 NaN NA NaN NaN NaN NaN +Warning message: +In qf(rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0), rep(c(1, 0, : + NaNs produced + +##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# +#set.seed(1); qf(rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)) + [1] NA NaN NaN Inf NaN + [6] NA NaN NaN 1.168926e-19 NaN +[11] NA NaN NaN NaN NaN +Warning message: +In qf(rep(c(1, 0, 0.1), 5), rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, : + NaNs produced + ##com.oracle.truffle.r.test.library.stats.TestStatFunctions.testFunctions32#Output.MayIgnoreWarningContext# #set.seed(1); qlnorm(0, 10, 10, lower.tail=FALSE, log.p=FALSE) [1] Inf diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_qbeta.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_qbeta.java new file mode 100644 index 0000000000000000000000000000000000000000..742c7170856fede28c45fb7a453b5594720982a1 --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_qbeta.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.truffle.r.test.library.stats; + +import static com.oracle.truffle.r.test.library.stats.TestStatFunctions.PROBABILITIES; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +/** + * Additional tests on the top of {@link TestStatFunctions}. + */ +public class TestExternal_qbeta extends TestBase { + private static final String[] BOOL_VALUES = new String[]{"T", "F"}; + + @Test + public void testQBeta() { + // check if in qbeta_raw with comment "p==0, q==0, p = Inf, q = Inf <==> treat as one- or + // two-point mass" + assertEval(template("qbeta(0.7, 0, 1/0, lower.tail=%0, log.p=F)", BOOL_VALUES)); + assertEval(template("qbeta(log(0.7), 0, 1/0, lower.tail=%0, log.p=T)", BOOL_VALUES)); + assertEval(template("qbeta(0.7, 1/0, 0, lower.tail=%0, log.p=F)", BOOL_VALUES)); + assertEval(template("qbeta(log(0.7), 1/0, 0, lower.tail=%0, log.p=T)", BOOL_VALUES)); + assertEval(template("qbeta(%0, 0, 0, lower.tail=%1, log.p=F)", new String[]{"0.1", "0.5", "0.7"}, BOOL_VALUES)); + assertEval(template("qbeta(log(%0), 0, 0, lower.tail=%1, log.p=T)", new String[]{"0.1", "0.5", "0.7"}, BOOL_VALUES)); + // checks swap_tail = (p_ > 0.5) where for lower.tail = log.p = TRUE is p_ = exp(p) + // exp(0.1) = 1.10.... + assertEval(template("qbeta(log(%0), 0.1, 3, lower.tail=T, log.p=T)", PROBABILITIES)); + // exp(-1) = 0.36... + assertEval(Output.MayIgnoreWarningContext, template("qbeta(log(%0), -1, 3, lower.tail=T, log.p=T)", PROBABILITIES)); + } +} diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestStatFunctions.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestStatFunctions.java index 1e355ca8a4f71cb92686297ed4655a3691e17e7c..c51783a3d07446236e11bddd69ca31c5544d4f74 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestStatFunctions.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestStatFunctions.java @@ -30,6 +30,8 @@ import com.oracle.truffle.r.test.TestBase; * Common tests for functions implemented using {@code StatsFunctions} infrastructure. */ public class TestStatFunctions extends TestBase { + public static final String[] PROBABILITIES = new String[]{"0", "42e-80", "0.1", "0.5", "0.7", "1-42e-80", "1"}; + private static final String[] FUNCTION3_1_NAMES = {"dgamma", "dbeta", "dcauchy", "dlnorm", "dlogis", "dunif"}; private static final String[] FUNCTION3_1_PARAMS = { "10, 10, 10, log=TRUE", @@ -61,7 +63,7 @@ public class TestStatFunctions extends TestBase { assertEval(Output.IgnoreWhitespace, template("set.seed(1); %0(%1)", FUNCTION2_1_NAMES, FUNCTION2_1_PARAMS)); } - private static final String[] FUNCTION2_2_NAMES = {"pchisq", "pexp", "qexp", "qgeom", "pgeom", "qt", "pt", "qpois", "ppois"}; + private static final String[] FUNCTION2_2_NAMES = {"pchisq", "pexp", "qexp", "qgeom", "pgeom", "qt", "pt", "qpois", "ppois", "qchisq"}; private static final String[] FUNCTION2_2_PARAMS = { "0, 10", "c(-1, 0, 0.2, 2), rep(c(-1, 0, 0.1, 0.9, 3), 4)", @@ -80,7 +82,8 @@ public class TestStatFunctions extends TestBase { assertEval(Output.IgnoreWhitespace, template("set.seed(1); %0(%1)", FUNCTION2_2_NAMES, new String[]{"rep(c(1, 0, 0.1), 5), c(NA, 0, NaN, 1/0, -1/0)"})); } - private static final String[] FUNCTION3_2_NAMES = {"pbeta", "pcauchy", "qcauchy", "qlnorm", "plnorm", "qbinom", "pnorm", "qnorm", "qlogis", "pf", "pbinom", "plogis", "punif", "qunif"}; + private static final String[] FUNCTION3_2_NAMES = {"pbeta", "pcauchy", "qcauchy", "qlnorm", "plnorm", "qbinom", "pnorm", "qnorm", "qlogis", "pf", "pbinom", "plogis", "punif", "qunif", "qbeta", + "qf"}; private static final String[] FUNCTION3_2_PARAMS = { "0, 10, 10", "c(-1, 0, 0.2, 2), c(-1, 0, 0.1, 0.9, 3), rep(c(-1, 0, 1, 0.1, -0.1, 0.0001), 20)", diff --git a/mx.fastr/copyrights/overrides b/mx.fastr/copyrights/overrides index 1ad8ed22861ee3cd858a2dd2877f43738074d945..e97b3e340fd5e5195744be34e14dc31c229adc27 100644 --- a/mx.fastr/copyrights/overrides +++ b/mx.fastr/copyrights/overrides @@ -52,6 +52,10 @@ com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/LBeta.java,g com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pbinom.java,gnu_r_ihaka.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pf.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Pnorm.java,gnu_r_ihaka.copyright +com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/PPois.java,gnu_r_ihaka_core.copyright +com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QPois.java,gnu_r_ihaka_core.copyright +com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QBeta.java,gnu_r_scan.copyright +com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Qf.java,gnu_r_ihaka.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Qbinom.java,gnu_r_ihaka.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Qnorm.java,gnu_r_ihaka.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Random2.java,gnu_r.copyright @@ -73,7 +77,6 @@ com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RGamma.java, com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNbinomMu.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Logis.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rf.java,gnu_r_ihaka_core.copyright -com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RChisq.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Exp.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Geom.java,gnu_r_ihaka_core.copyright com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Dt.java,gnu_r.core.copyright