Qu

binomial

Builtin index · Statistics & ML

result = binomial(n_trials, p, [rows], [cols], [seed=])

Input: n_trials, p, rows, cols, seed · Output: result

What it is

Exact binomial draws. n_trials (a positive integer) is how many trials each draw counts successes over; p (a number in [0, 1]) is the success probability of one trial; rows and cols (numbers, optional) give the shape of the draw, one number for a vector and two for a matrix; seed= (number, optional) makes the draw repeatable.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = binomial(n_trials, p, [rows], [cols], [seed=])
n_trials —n_trials (a positive integer) is how many trials each draw counts successes over.
p numberp (a number in [0, 1]) is the success probability of one trial.
rows number, vector, or matrix, optionalrows and cols (numbers, optional) give the shape of the draw, one number for a vector and two for a matrix.
cols number, vector, or matrix, optionalrows and cols (numbers, optional) give the shape of the draw, one number for a vector and two for a matrix.
seed number, optionalseed= (number, optional) makes the draw repeatable.
result number, vector, or matrix
Returns a number, vector, or (rows, cols) matrix of non-negative integers.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

u = uniform(10, 20, 5)          # 5 draws, continuous uniform on [10, 20)

g = normal(5, 2, 1000, seed=1)  # 1000 draws, mean 5, std 2 — randn is mu=0/sigma=1

d = randi(1, 6, 10)             # 10 dice rolls, inclusive both ends

k = poisson(4, 500)             # 500 draws from Poisson(lambda=4)

t = exponential(2, 500)         # 500 draws, rate=2 (mean = 1/rate = 0.5)

b = binomial(20, 0.3, 500)      # 500 draws, 20 trials at p=0.3 each

from numerics-dsp

How it works

binomial(n_trials, p, ...) — see Rng::binomial's doc comment for the complexity caveat.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.