Introduction

The density function of the Weibull distribution:

$$ f(x; k, \theta) = \frac{k}{\theta} \left( \frac{x}{\theta} \right)^{k-1} \exp \left( - \left( \frac{x}{\theta} \right)^k \right) \times \mathbf{1}[ x \geq 0 ] $$

Parameters:

  • shape_par is $k$
  • scale_par is $\theta$

Density


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> dweibull(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::dweibull(0.5,shape,scale);
double log_dens_val = stats::dweibull(0.5,shape,scale,true);

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

arma::mat dens_vals_mat = stats::dweibull(X,shape,scale);
arma::mat log_dens_vals_mat = stats::dweibull(X,shape,scale,true);

Probability


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
return_t<Ta> pweibull(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::pweibull(0.5,shape,scale);
double log_prob_val = stats::pweibull(0.5,shape,scale,true);

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

arma::mat prob_vals_mat = stats::pweibull(X,shape,scale);
arma::mat log_prob_vals_mat = stats::pweibull(X,shape,scale,true);

Quantile


Definition:

 
template<typename Ta, typename Tb>
statslib_constexpr
Ta qweibull(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::qweibull(0.7,shape,scale);

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

arma::mat quant_vals_mat = stats::qweibull(X,shape,scale);

Random Sampling


Definition:

 
// random engine seeding
template<typename T>
statslib_inline
return_t<T> rweibull(const T shape_par, const T scale_par, rand_engine_t& engine);

// seeding values
template<typename T>
statslib_inline
return_t<T> rweibull(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 rweibull(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::rweibull(shape,scale);

// Armadillo output: 10 x 1 matrix
arma::mat rand_mat = stats::rweibull<arma::mat>(10,1,shape,scale);