The density function of the Binomial distribution:
$$ f(x; n, p) = \binom{n}{x} p^x (1-p)^{n-x} $$Parameters:
n_trials_par
is $n$prob_par
is $p$Definition:
template<typename T> statslib_constexpr T dbinom(const uint_t x, const uint_t n_trials_par, const T prob_par, const bool log_form = false);
Computes the density function.
Examples:
// parameters double prob_par = 0.6; unsigned int n_trials = 4; // standard input double dens_val = stats::dbinom(2,n_trials,prob_par); double log_dens_val = stats::dbinom(2,n_trials,prob_par,true); // Armadillo input arma::mat X(10,1); X.fill(1); arma::mat dens_vals_mat = stats::dbinom(X,n_trials,prob_par); arma::mat log_dens_vals_mat = stats::dbinom(X,n_trials,prob_par,true);
Definition:
template<typename T> statslib_constexpr T pbinom(const uint_t x, const uint_t n_trials_par, const T prob_par, const bool log_form = false);
Computes the cumulative distribution function (CDF).
Examples:
// parameters double prob_par = 0.6; unsigned int n_trials = 4; // standard input double prob_val = stats::pbinom(2,n_trials,prob_par); double log_prob_val = stats::pnorm(2,n_trials,prob_par,true); // Armadillo input arma::mat X(10,1); X.fill(2); arma::mat prob_vals_mat = stats::pbinom(X,n_trials,prob_par); arma::mat log_prob_vals_mat = stats::pbinom(X,n_trials,prob_par,true);
Definition:
template<typename Ta, typename Tb = uint_t> statslib_constexpr Tb qbinom(const Ta p, const uint_t n_trials_par, const Ta prob_par);
Computes the quantile function.
Examples:
// parameters double prob_par = 0.6; unsigned int n_trials = 4; // standard input int quant_val = stats::qbinom(0.7,n_trials,prob_par); // Armadillo input arma::mat X(10,1); X.fill(0.7); arma::mat quant_vals_mat = stats::qbinom(X,n_trials,prob_par);
Definition:
// random engine seeding template<typename T> statslib_inline uint_t rbinom(const uint_t n_trials_par, const T prob_par, rand_engine_t& engine); // seeding values template<typename T> sstatslib_inline uint_t rbinom(const uint_t n_trials_par, const T prob_par, uint_t seed_val = std::random_device{}()); // matrix output template<typename mT, typename eT> statslib_inline mT rbinom(const uint_t n, const uint_t k, const uint_t n_trials_par, const eT prob_par);
Generates pseudo-random draws.
Examples:
// parameters double prob_par = 0.6; unsigned int n_trials = 4; // standard input int rand_val = stats::rbinom(n_trials,prob_par); // Armadillo output: 10 x 1 matrix arma::mat rand_mat = stats::rbinom<arma::mat>(10,1,n_trials,prob_par);