Binomial functions in the Stochastic DuckDB extension
Function category
Binomial
25 functionsBinomial — number of successes in n independent Bernoulli trials at success probability prob.
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x).
SELECT dist_binomial_cdf(10, 0.5, 5);
Output
| dist_binomial_cdf(10, 0.5, 5) |
|---|
| 0.623046875 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the complementary cumulative distribution function (survival function) of the binomial distribution, P(X > x).
SELECT dist_binomial_cdf_complement(10, 0.5, 5);
Output
| dist_binomial_cdf_complement(10, 0.5, 5) |
|---|
| 0.376953125 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the cumulative hazard function of the binomial distribution at x.
SELECT dist_binomial_chf(10, 0.5, 5);
Output
| dist_binomial_chf(10, 0.5, 5) |
|---|
| 0.9756344361346222 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Description
Fits a binomial distribution to x by maximum likelihood. Returns a STRUCT with the fitted parameters (prob) followed by the log_likelihood, aic and bic of the fit, or NULL when there are too few or only identical values. trials is the known number of trials and must be the same for every row of a group.
SELECT round(dist_binomial_fit(defects, 20).prob, 6) AS prob
FROM (VALUES (3), (5), (2), (4), (1), (3)) t(defects);
Output
| prob |
|---|
| 0.15 |
Related functions
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the hazard function of the binomial distribution at x.
SELECT dist_binomial_hazard(10, 0.5, 5);
Output
| dist_binomial_hazard(10, 0.5, 5) |
|---|
| 0.652849740932643 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the kurtosis of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_kurtosis(10, 0.5);
Output
| dist_binomial_kurtosis(10, 0.5) |
|---|
| 2.8 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the excess kurtosis of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_kurtosis_excess(10, 0.5);
Output
| dist_binomial_kurtosis_excess(10, 0.5) |
|---|
| -0.2 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the natural logarithm of the cumulative distribution function (CDF) of the binomial distribution.
SELECT dist_binomial_log_cdf(10, 0.5, 5);
Output
| dist_binomial_log_cdf(10, 0.5, 5) |
|---|
| -0.4731335222546632 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the natural logarithm of the survival function of the binomial distribution, log P(X > x).
SELECT dist_binomial_log_cdf_complement(10, 0.5, 5);
Output
| dist_binomial_log_cdf_complement(10, 0.5, 5) |
|---|
| -0.9756344361346222 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the natural logarithm of the probability mass function (PMF) of the binomial distribution at x. Useful for numerical stability when dealing with very small probabilities.
SELECT dist_binomial_log_pdf(10, 0.5, 5);
Output
| dist_binomial_log_pdf(10, 0.5, 5) |
|---|
| -1.402042718088029 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the natural logarithm of the probability mass function (PMF) of the binomial distribution at x.
SELECT dist_binomial_log_pmf(10, 0.5, 5);
Output
| dist_binomial_log_pmf(10, 0.5, 5) |
|---|
| -1.402042718088029 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
- dist_binomial_mean() — Returns the mean of the binomial distribution
- dist_binomial_stddev() — Returns the standard deviation of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the mean of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_mean(10, 0.5);
Output
| dist_binomial_mean(10, 0.5) |
|---|
| 5.0 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
- dist_binomial_stddev() — Returns the standard deviation of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the median of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_median(10, 0.5);
Output
| dist_binomial_median(10, 0.5) |
|---|
| 5.0 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the mode (most likely value) of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_mode(10, 0.5);
Output
| dist_binomial_mode(10, 0.5) |
|---|
| 5.0 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the probability mass function (PMF) of the binomial distribution at x.
SELECT dist_binomial_pdf(10, 0.5, 5);
Output
| dist_binomial_pdf(10, 0.5, 5) |
|---|
| 0.2460937500000002 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the probability mass function (PMF) of the binomial distribution at x, P(X = x).
SELECT dist_binomial_pmf(10, 0.5, 3) AS prob_exactly_3;
Output
| prob_exactly_3 |
|---|
| 0.11718750000000004 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
- dist_binomial_mean() — Returns the mean of the binomial distribution
- dist_binomial_stddev() — Returns the standard deviation of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
p
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the quantile function (inverse CDF) of the binomial distribution. Returns the smallest x such that P(X <= x) >= p.
SELECT dist_binomial_quantile(10, 0.5, 0.95);
Output
| dist_binomial_quantile(10, 0.5, 0.95) |
|---|
| 8 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
p
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Computes the complementary quantile function of the binomial distribution. Returns x such that P(X > x) = p, useful for upper tail quantiles.
SELECT dist_binomial_quantile_complement(10, 0.5, 0.95);
Output
| dist_binomial_quantile_complement(10, 0.5, 0.95) |
|---|
| 2 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the range of the binomial distribution as [min, max].
SELECT dist_binomial_range(10, 0.5);
Output
| dist_binomial_range(10, 0.5) |
|---|
| [0.0, 10.0] |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Generates a random sample from the binomial distribution with the specified parameters.
SELECT dist_binomial_sample(10, 0.5);
Output
| dist_binomial_sample(10, 0.5) |
|---|
| 2 |
Related functions
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Argument
n
|
Type
BIGINT
|
Mode Positional | Description |
Description
Generates a list of n random samples from the binomial distribution with the specified parameters.
SELECT dist_binomial_samples(10, 0.5, 5);
Output
| dist_binomial_samples(10, 0.5, 5) |
|---|
| [2, 7, 6, 4, 6] |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
- dist_binomial_mean() — Returns the mean of the binomial distribution
- dist_binomial_stddev() — Returns the standard deviation of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the skewness of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_skewness(10, 0.5);
Output
| dist_binomial_skewness(10, 0.5) |
|---|
| 0.0 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the standard deviation of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_stddev(10, 0.5);
Output
| dist_binomial_stddev(10, 0.5) |
|---|
| 1.5811388300841898 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
- dist_binomial_mean() — Returns the mean of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the support of the binomial distribution as [min, max].
SELECT dist_binomial_support(10, 0.5);
Output
| dist_binomial_support(10, 0.5) |
|---|
| [0.0, 10.0] |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
trials
|
Type
BIGINT
|
Mode Positional | Description |
Argument
prob
|
Type
DOUBLE
|
Mode Positional | Description |
Description
Returns the variance of the binomial distribution. Returns NULL when it is undefined for the given parameters.
SELECT dist_binomial_variance(10, 0.5);
Output
| dist_binomial_variance(10, 0.5) |
|---|
| 2.5 |
Related functions
- dist_binomial_sample() — Generates a random sample from the binomial distribution with the specified parameters
- dist_binomial_pdf() — Computes the probability mass function (PMF) of the binomial distribution at x
- dist_binomial_cdf() — Computes the cumulative distribution function (CDF) of the binomial distribution, P(X <= x)
- dist_binomial_quantile() — Computes the quantile function (inverse CDF) of the binomial distribution