The density function of the Gamma distribution:
$$ f(x; k, \theta) = \dfrac{x^{k-1}\exp(-x/\theta)}{\theta^k \Gamma(k)} \times \mathbf{1}[ x > 0 ] $$Parameters:
shape_par
is $k$scale_par
is $\theta$Definition:
template<typename Ta, typename Tb> statslib_constexpr return_t<Ta> dgamma(const Ta x, const Tb shape_par, const Tb scale_par, const bool log_form = false);
Computes the density function.
Examples:
// parameters double shape = 5.0; double scale = 4.0; // standard input double dens_val = stats::dgamma(0.5,shape,scale); double log_dens_val = stats::dgamma(0.5,shape,scale,true); // Armadillo input arma::mat X(10,1); X.fill(0.5); arma::mat dens_vals_mat = stats::dgamma(X,shape,scale); arma::mat log_dens_vals_mat = stats::dgamma(X,shape,scale,true);
Definition:
template<typename Ta, typename Tb> statslib_constexpr return_t<Ta> pgamma(const Ta x, const Tb shape_par, const Tb scale_par, const bool log_form = false);
Computes the cumulative distribution function (CDF).
Examples:
// parameters double shape = 5.0; double scale = 4.0; // standard input double prob_val = stats::pgamma(0.5,shape,scale); double log_prob_val = stats::pgamma(0.5,shape,scale,true); // Armadillo input arma::mat X(10,1); X.fill(0.5); arma::mat prob_vals_mat = stats::pgamma(X,shape,scale); arma::mat log_prob_vals_mat = stats::pgamma(X,shape,scale,true);
Definition:
template<typename Ta, typename Tb> statslib_constexpr Ta qgamma(const Ta p, const Tb shape_par, const Tb scale_par);
Computes the quantile function.
Examples:
// parameters double shape = 5.0; double scale = 4.0; // standard input double quant_val = stats::qgamma(0.7,shape,scale); // Armadillo input arma::mat X(10,1); X.fill(0.7); arma::mat quant_vals_mat = stats::qgamma(X,shape,scale);
Definition:
// random engine seeding template<typename T> statslib_inline return_t<T> rgamma(const T shape_par, const T scale_par, rand_engine_t& engine); // seeding values template<typename T> statslib_inline return_t<T> rgamma(const T shape_par, const T scale_par, uint_t seed_val = std::random_device{}()); // matrix output template<typename mT, typename eT> statslib_inline mT rgamma(const uint_t n, const uint_t k, const eT shape_par, const eT scale_par);
Generates pseudo-random draws.
Examples:
// parameters double shape = 5.0; double scale = 4.0; // standard input double rand_val = stats::rgamma(shape,scale); // Armadillo output: 10 x 1 matrix arma::mat rand_mat = stats::rgamma<arma::mat>(10,1,shape,scale);