.. :html_theme.sidebar_secondary.remove:

:orphan:

:py:mod:`comyx.stats.common`
============================

.. py:module:: comyx.stats.common


Module Summary
---------------


Functions
~~~~~~~~~

.. autoapisummary::

   comyx.stats.common.gamma_add_params
   comyx.stats.common.gamma_div_gamma_dist
   comyx.stats.common.gamma_plus_one_params




Reference
---------

.. py:function:: 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]

   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.

   .. math::
       z = a h + b g

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

   .. math::
       k_n = \frac{\mu_{n,1}^{(2)}}{\mu_{n,2} - \mu_{n,1}^{(2)}}

   .. math::
       \theta_n = \frac{\mu_{n,2} - \mu_{n,1}^{(2)}}{\mu_{n,1}}

   , where :math:`n \in \{a, b\}`.

   The resulting distribution is a Gamma distribution, expressed as:

   .. math::
       z \sim \Gamma(k_z, \theta_z)

   :param mu_a_1: First moment of the first Gamma distribution :math:`h`.
   :param mu_a_2: Second moment of the first Gamma distribution :math:`h`.
   :param mu_b_1: First moment of the second Gamma distribution :math:`g`.
   :param mu_b_2: Second moment of the second Gamma distribution :math:`g`.
   :param a: Shape parameter of the first Gamma distribution :math:`h`.
   :param b: Shape parameter of the second Gamma distribution :math:`g`.
   :param 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.


.. py:function:: gamma_div_gamma_dist(k_a: NDArrayFloat, k_b: NDArrayFloat, theta_a: NDArrayFloat, theta_b: NDArrayFloat) -> RVDistribution

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

   .. math::
       z = \frac{h}{g}

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

   .. math::
       z \sim \beta'(k_a, k_b, \theta_a / \theta_b)

   :param k_a: Shape parameter of the first Gamma distribution :math:`h`.
   :param k_b: Shape parameter of the second Gamma distribution :math:`g`.
   :param theta_a: Scale parameter of the first Gamma distribution :math:`h`.
   :param theta_b: Scale parameter of the second Gamma distribution :math:`g`.

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


.. py:function:: 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]

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

   .. math::
       z = h + 1

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

   .. math::
       k_a = \frac{\mu_{a,1}^{(2)}}{\mu_{a,2} - \mu_{a,1}^{(2)}}

   .. math::
       \theta_a = \frac{\mu_{a,2} - \mu_{a,1}^{(2)}}{\mu_{a,1}}

   :param mu_a_1: First moment of the Gamma distribution.
   :param mu_a_2: Second moment of the Gamma distribution.
   :param 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.


