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