rStats.js v1.3.0
    Preparing search index...

    Function choose

    • Binomial coefficient. Equivalent to R's choose(). Takes single numbers.

      n may be any real number. k is rounded to the nearest integer (as R does, which also warns when k is not close to an integer); choose(n, k) is 0 for k < 0 and 1 for k = 0. For integer n the result is an integer (exact up to 2^53).

      Edge cases where R differs from the mathematical value, followed by default (rCompatible: false returns the mathematical value instead):

      • n within 1e-9 max(1, |n|) of an integer is treated as that integer, so choose(1e-10, 2) is 0 (mathematically -5e-11); for n < 0 and k >= 30 the tolerance is relative to k - 1 - n;
      • choose(n, Infinity) is 0 for n >= 0 (otherwise NaN);
      • choose(±Infinity, k) is NaN for k >= 30 (±Infinity below).

      Parameters

      • n: number

        Number of items (any real number).

      • k: number

        Number chosen (rounded to an integer).

      • Optionaloptions: RCompatibleOptions

        rCompatible (default true).

      Returns number

      The binomial coefficient.

      choose(5, 2);    // 10
      choose(0.5, 3); // 0.0625
      choose(-2, 3); // -4