comyx.stats.common#

Module Summary#

Functions#

gamma_add_params(, b, return_type, NDArrayFloat])

Computes the parameters of the sum of two independent Gamma random variables.

gamma_div_gamma_dist(→ RVDistribution)

Computes the parameters of the ratio of two independent Gamma random variables.

gamma_plus_one_params(, return_type, NDArrayFloat])

Computes the parameters of the sum of a Gamma random variable and one.

Reference#

comyx.stats.common.gamma_add_params(mu_a_1: NDArrayFloat, mu_a_2: NDArrayFloat, mu_b_1: NDArrayFloat, mu_b_2: NDArrayFloat, a: NDArrayFloat = np.array([1.0]), b: NDArrayFloat = np.array([1.0]), return_type: str = 'params') Tuple[NDArrayFloat, NDArrayFloat][source]#

Computes the parameters of the sum of two independent Gamma random variables.

The first distribution is optionally weighted by a, and the second by b.

\[z = a h + b g\]

, where \(h \sim \Gamma(k_a, \theta_a)\) and \(g \sim \Gamma(k_b, \theta_b)\). Also,

\[k_n = \frac{\mu_{n,1}^{(2)}}{\mu_{n,2} - \mu_{n,1}^{(2)}}\]
\[\theta_n = \frac{\mu_{n,2} - \mu_{n,1}^{(2)}}{\mu_{n,1}}\]

, where \(n \in \{a, b\}\).

The resulting distribution is a Gamma distribution, expressed as:

\[z \sim \Gamma(k_z, \theta_z)\]
Parameters:
  • mu_a_1 – First moment of the first Gamma distribution \(h\).

  • mu_a_2 – Second moment of the first Gamma distribution \(h\).

  • mu_b_1 – First moment of the second Gamma distribution \(g\).

  • mu_b_2 – Second moment of the second Gamma distribution \(g\).

  • a – Shape parameter of the first Gamma distribution \(h\).

  • b – Shape parameter of the second Gamma distribution \(g\).

  • return_type – Return type of the function. Must be either “params” or “moments”.

Returns:

Desired parameters of the sum of a Gamma random variable and one. If return_type is “params”, returns the shape and scale parameters of the sum of two independent Gamma random variables. If return_type is “moments”, returns the first two moments of the sum of two independent Gamma random variables.

comyx.stats.common.gamma_div_gamma_dist(k_a: NDArrayFloat, k_b: NDArrayFloat, theta_a: NDArrayFloat, theta_b: NDArrayFloat) RVDistribution[source]#

Computes the parameters of the ratio of two independent Gamma random variables.

\[z = \frac{h}{g}\]

, where \(h \sim \Gamma(k_a, \theta_a)\) and \(g \sim \Gamma(k_b, \theta_b)\). The resulting distribution is a Beta prime distribution, expressed as:

\[z \sim \beta'(k_a, k_b, \theta_a / \theta_b)\]
Parameters:
  • k_a – Shape parameter of the first Gamma distribution \(h\).

  • k_b – Shape parameter of the second Gamma distribution \(g\).

  • theta_a – Scale parameter of the first Gamma distribution \(h\).

  • theta_b – Scale parameter of the second Gamma distribution \(g\).

Returns:

A beta prime distribution with shape parameters k_a and k_b, and scale parameter theta_a / theta_b.

comyx.stats.common.gamma_plus_one_params(mu_a_1: NDArrayFloat, mu_a_2: NDArrayFloat, a: NDArrayFloat = np.array([1.0]), return_type: str = 'params') Tuple[NDArrayFloat, NDArrayFloat][source]#

Computes the parameters of the sum of a Gamma random variable and one.

\[z = h + 1\]

, where \(h \sim \Gamma(k_a, \theta_a)\). Also,

\[k_a = \frac{\mu_{a,1}^{(2)}}{\mu_{a,2} - \mu_{a,1}^{(2)}}\]
\[\theta_a = \frac{\mu_{a,2} - \mu_{a,1}^{(2)}}{\mu_{a,1}}\]
Parameters:
  • mu_a_1 – First moment of the Gamma distribution.

  • mu_a_2 – Second moment of the Gamma distribution.

  • return_type – Return type of the function. Must be either “params” or “moments”.

Returns:

Desired parameters of the sum of a Gamma random variable and one. If return_type is “params”, returns the shape and scale parameters of the sum of a Gamma random variable and one. If return_type is “moments”, returns the first two moments of the sum of a Gamma random variable and one.