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

    Function rmultinom

    • Random vectors from the multinomial distribution. Equivalent to R's rmultinom().

      Unlike R, which returns a K x n matrix with one draw per column, this returns n rows with one draw per row (the transpose of R's result). The random stream is the same as R's.

      Parameters

      • n: number

        Number of values to generate (fractions are truncated, as in R).

      • size: number

        Number of objects distributed into the K categories in each draw (fractions are truncated, as in R).

      • prob: readonly number[]

        Category weights of length K. They need not sum to 1 (they are divided by their sum).

      Returns number[][]

      An array of n arrays, each of length K and summing to the truncated size.

      RangeError if the truncated size is negative or 2^31 or more, or prob has a negative or non-finite value, or no positive value.

      setSeed(1);
      rmultinom(2, 5, [0.2, 0.3, 0.5]); // [[0, 1, 4], [1, 3, 1]]