Introduction

The density function of the Beta distribution:

$$ f(x; \alpha, \beta) = \frac{1}{\mathcal{B}(\alpha,\beta)} x^{\alpha - 1} (1-x)^{\beta-1} $$

where $\mathcal{B}(\alpha,\beta)$ is the beta function.

Parameters:

  • a_par is $\alpha$
  • b_par is $\beta$

Density


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> dbeta(const Ta x, const Tb a_par, const Tb b_par, const bool log_form = false);

Computes the density function.


Examples:

 
// parameters
double alpha = 3.0;
double beta  = 2.0;

// standard input
double dens_val = stats::dbeta(0.5,alpha,beta);
double log_dens_val = stats::dbeta(0.5,alpha,beta,true);

// Armadillo input
arma::mat X(10,1);
X.fill(0.5);

arma::mat dens_vals_mat = stats::dbeta(X,alpha,beta);
arma::mat log_dens_vals_mat = stats::dbeta(X,alpha,beta,true);

Probability


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> pbeta(const Ta x, const Tb a_par, const Tb b_par, const bool log_form = false);

Computes the cumulative distribution function (CDF).


Examples:

// parameters
double alpha = 3.0;
double beta  = 2.0;

// standard input
double prob_val = stats::pbeta(0.5,alpha,beta);
double log_prob_val = stats::pbeta(0.5,alpha,beta,true);

// Armadillo input
arma::mat X(10,1);
X.fill(0.5);

arma::mat prob_vals_mat = stats::pbeta(X,alpha,beta);
arma::mat log_prob_vals_mat = stats::pbeta(X,alpha,beta,true);

Quantile


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
Ta qbeta(const Ta p, const Tb a_par, const Tb b_par);

Computes the quantile function.


Examples:

 
// parameters
double alpha = 3.0;
double beta  = 2.0;

// standard input
double quant_val = stats::qbeta(0.7,alpha,beta);

// Armadillo input
arma::mat X(10,1);
X.fill(0.7);

arma::mat quant_vals_mat = stats::qbeta(X,alpha,beta);

Random Sampling


Definition:

 
// random engine seeding
template<typename T>
statslib_inline
return_t<T> rbeta(const T a_par, const T b_par, rand_engine_t& engine);

// seeding values
template<typename T>
statslib_inline
return_t<T> rbeta(const T a_par, const T b_par, uint_t seed_val = std::random_device{}());

// matrix output
template<typename mT, typename eT>
statslib_inline
mT rbeta(const uint_t n, const uint_t k, const eT a_par, const eT b_par);

Generates pseudo-random draws.


Examples:

// parameters
double alpha = 3.0;
double beta  = 2.0;

// standard input
double rand_val = stats::rbeta(alpha,beta);

// Armadillo output: 10 x 1 matrix
arma::mat rand_mat = stats::rbeta<arma::mat>(10,1,alpha,beta);