
    M/Ph~                     D   d Z ddlZddlZddlZ ej        e          j        Z	d Z
 G d d          Z G d de          Z G d d	e          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d  d!e          Z G d" d#e          Z G d$ d%e          Z G d& d'e          Z G d( d)e          Z G d* d+e          Z G d, d-e          Z G d. d/e          Z  G d0 d1e          Z! G d2 d3e          Z" G d4 d5e          Z# G d6 d7e          Z$ G d8 d9e          Z%dS ):zB
Defines the link functions to be used with GLM and GEE families.
    Nc           	      N    t          j        d|  d| d|  dt                     d S )NzThe z link alias is deprecated. Use z instead. The z5 link alias will be removed after the 0.15.0 release.)warningswarnFutureWarning)oldnews     a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/genmod/families/links.py_link_deprecation_warningr
      sY    M	@s 	@ 	@3 	@ 	@c 	@ 	@ 	@        c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	Linkz
    A generic link function for one-parameter exponential family.

    `Link` does nothing, but lays out the methods expected of any subclass.
    c                     t           S )a  
        Return the value of the link function.  This is just a placeholder.

        Parameters
        ----------
        p : array_like
            Probabilities

        Returns
        -------
        g(p) : array_like
            The value of the link function g(p) = z
        NotImplementedErrorselfps     r	   __call__zLink.__call__   s
     #"r   c                     t           S )a~  
        Inverse of the link function.  Just a placeholder.

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor of the transformed variable
            in the IRLS algorithm for GLM.

        Returns
        -------
        g^(-1)(z) : ndarray
            The value of the inverse of the link function g^(-1)(z) = p
        r   r   zs     r	   inversezLink.inverse,   s
     #"r   c                     t           S )a  
        Derivative of the link function g'(p).  Just a placeholder.

        Parameters
        ----------
        p : array_like

        Returns
        -------
        g'(p) : ndarray
            The value of the derivative of the link function g'(p)
        r   r   s     r	   derivz
Link.deriv=   s
     #"r   c                 0    ddl m}  ||| j                  S )zmSecond derivative of the link function g''(p)

        implemented through numerical differentiation
        r   )_approx_fprime_cs_scalar)statsmodels.tools.numdiffr   r   )r   r   r   s      r	   deriv2zLink.deriv2L   s,    
 	GFFFFF''4:666r   c                 X    d|                      |                     |                    z  S )a  
        Derivative of the inverse link function g^(-1)(z).

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor for a GLM or GEE model.

        Returns
        -------
        g'^(-1)(z) : ndarray
            The value of the derivative of the inverse of the link function

        Notes
        -----
        This reference implementation gives the correct result but is
        inefficient, so it can be overridden in subclasses.
           )r   r   r   s     r	   inverse_derivzLink.inverse_derivT   s%    & 4::dll1oo....r   c                     |                      |          }|                     |           |                     |          dz  z  S )a  
        Second derivative of the inverse link function g^(-1)(z).

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor for a GLM or GEE model.

        Returns
        -------
        g'^(-1)(z) : ndarray
            The value of the second derivative of the inverse of the link
            function

        Notes
        -----
        This reference implementation gives the correct result but is
        inefficient, so it can be overridden in subclasses.
           )r   r   r   )r   r   izs      r	   inverse_deriv2zLink.inverse_deriv2i   s:    ( \\!__B$**R..A"555r   N
__name__
__module____qualname____doc__r   r   r   r   r!   r%    r   r	   r   r      sx         # # # # # #"# # #7 7 7/ / /*6 6 6 6 6r   r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	Logitz
    The logit transform

    Notes
    -----
    call and derivative use a private method _clean to make trim p by
    machine epsilon so that p is in (0,1)

    Alias of Logit:
    logit = Logit()
    c                 H    t          j        |t          dt          z
            S )z
        Clip logistic values to range (eps, 1-eps)

        Parameters
        ----------
        p : array_like
            Probabilities

        Returns
        -------
        pclip : ndarray
            Clipped probabilities
              ?npclip	FLOAT_EPSr   s     r	   _cleanzLogit._clean   s     wq)R)^444r   c                 `    |                      |          }t          j        |d|z
  z            S )a  
        The logit transform

        Parameters
        ----------
        p : array_like
            Probabilities

        Returns
        -------
        z : ndarray
            Logit transform of `p`

        Notes
        -----
        g(p) = log(p / (1 - p))
        r/   r4   r1   logr   s     r	   r   zLogit.__call__   s+    $ KKNNva26l###r   c                 d    t          j        |          }t          j        |           }dd|z   z  S )a4  
        Inverse of the logit transform

        Parameters
        ----------
        z : array_like
            The value of the logit transform at `p`

        Returns
        -------
        p : ndarray
            Probabilities

        Notes
        -----
        g^(-1)(z) = exp(z)/(1+exp(z))
        r/   )r1   asarrayexpr   r   ts      r	   r   zLogit.inverse   s.    $ JqMMFA2JJR!V}r   c                 B    |                      |          }d|d|z
  z  z  S )au  
        Derivative of the logit transform

        Parameters
        ----------
        p : array_like
            Probabilities

        Returns
        -------
        g'(p) : ndarray
            Value of the derivative of logit transform at `p`

        Notes
        -----
        g'(p) = 1 / (p * (1 - p))

        Alias for `Logit`:
        logit = Logit()
        r/   r    r4   r   s     r	   r   zLogit.deriv   s&    * KKNNQ!a%[!!r   c                 @    t          j        |          }|d|z   dz  z  S )aS  
        Derivative of the inverse of the logit transform

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor for a GLM or GEE model.

        Returns
        -------
        g'^(-1)(z) : ndarray
            The value of the derivative of the inverse of the logit function
        r       r1   r:   r;   s      r	   r!   zLogit.inverse_deriv   s$     F1IIAEa<r   c                 .    |d|z
  z  }d|z  dz
  |dz  z  S )a  
        Second derivative of the logit function.

        Parameters
        ----------
        p : array_like
            probabilities

        Returns
        -------
        g''(z) : ndarray
            The value of the second derivative of the logit function
        r    r@   r+   )r   r   vs      r	   r   zLogit.deriv2   s(     QKA	Q!V##r   N)
r'   r(   r)   r*   r4   r   r   r   r!   r   r+   r   r	   r-   r-      sx        
 
5 5 5 $ $ $*  ," " "0     "$ $ $ $ $r   r-   c                   >    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
S )Powera#  
    The power transform

    Parameters
    ----------
    power : float
        The exponent of the power transform

    Notes
    -----
    Aliases of Power:
    Inverse = Power(power=-1)
    Sqrt = Power(power=.5)
    InverseSquared = Power(power=-2.)
    Identity = Power(power=1.)
    r/   c                     || _         d S Npower)r   rI   s     r	   __init__zPower.__init__      


r   c                 P    | j         dk    r|S t          j         || j                   S )a  
        Power transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        z : array_like
            Power transform of x

        Notes
        -----
        g(p) = x**self.power
        r    rI   r1   r   s     r	   r   zPower.__call__  s(    $ :??H8Atz***r   c                 V    | j         dk    r|S t          j         |d| j         z            S )aP  
        Inverse of the power transform link function

        Parameters
        ----------
        `z` : array_like
            Value of the transformed mean parameters at `p`

        Returns
        -------
        `p` : ndarray
            Mean parameters

        Notes
        -----
        g^(-1)(z`) = `z`**(1/`power`)
        r    r/   rM   r   s     r	   r   zPower.inverse0  s,    $ :??H8ArDJ///r   c                     | j         dk    rt          j        |          S | j         t          j         || j         dz
            z  S )aC  
        Derivative of the power transform

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g'(p) : ndarray
            Derivative of power transform of `p`

        Notes
        -----
        g'(`p`) = `power` * `p`**(`power` - 1)
        r    rI   r1   	ones_liker   s     r	   r   zPower.derivG  s<    $ :??<??":DJN ; ;;;r   c                     | j         dk    rt          j        |          S | j         | j         dz
  z  t          j         || j         dz
            z  S )ag  
        Second derivative of the power transform

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g''(p) : ndarray
            Second derivative of the power transform of `p`

        Notes
        -----
        g''(`p`) = `power` * (`power` - 1) * `p`**(`power` - 2)
        r    r@   rI   r1   
zeros_liker   s     r	   r   zPower.deriv2^  sI    $ :??=###:a028AtzA~3N3NNNr   c                     | j         dk    rt          j        |          S t          j         |d| j         z
  | j         z            | j         z  S )ae  
        Derivative of the inverse of the power transform

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor for a GLM or GEE model.

        Returns
        -------
        g^(-1)'(z) : ndarray
            The value of the derivative of the inverse of the power transform
        function
        r    rP   r   s     r	   r!   zPower.inverse_derivu  sC     :??<??"8ADJ$*<==
JJr   c                     | j         dk    rt          j        |          S d| j         z
  t          j         |dd| j         z  z
  | j         z            z  | j         dz  z  S )al  
        Second derivative of the inverse of the power transform

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor for a GLM or GEE model.

        Returns
        -------
        g^(-1)'(z) : ndarray
            The value of the derivative of the inverse of the power transform
        function
        r    r@   rS   r   s     r	   r%   zPower.inverse_deriv2  sc     :??=###^HQQtz\!14: =>>?AEQO Pr   Nr/   )r'   r(   r)   r*   rJ   r   r   r   r   r!   r%   r+   r   r	   rE   rE     s         "   + + +.0 0 0.< < <.O O O.K K K(P P P P Pr   rE   c                   "     e Zd ZdZ fdZ xZS )InversePowerz{
    The inverse transform

    Notes
    -----
    g(p) = 1/p

    Alias of statsmodels.family.links.Power(power=-1.)
    c                 L    t                                          d           d S )N      rH   superrJ   r   	__class__s    r	   rJ   zInversePower.__init__  $    s#####r   r'   r(   r)   r*   rJ   __classcell__r_   s   @r	   rY   rY     B         $ $ $ $ $ $ $ $ $r   rY   c                   "     e Zd ZdZ fdZ xZS )Sqrtz
    The square-root transform

    Notes
    -----
    g(`p`) = sqrt(`p`)

    Alias of statsmodels.family.links.Power(power=.5)
    c                 L    t                                          d           d S )N      ?rH   r\   r^   s    r	   rJ   zSqrt.__init__  $    r"""""r   ra   rc   s   @r	   rf   rf     B         # # # # # # # # #r   rf   c                   "     e Zd ZdZ fdZ xZS )InverseSquaredz
    The inverse squared transform

    Notes
    -----
    g(`p`) = 1/(`p`\*\*2)

    Alias of statsmodels.family.links.Power(power=2.)
    c                 L    t                                          d           d S )Ng       rH   r\   r^   s    r	   rJ   zInverseSquared.__init__  r`   r   ra   rc   s   @r	   rl   rl     rd   r   rl   c                   "     e Zd ZdZ fdZ xZS )Identityz}
    The identity transform

    Notes
    -----
    g(`p`) = `p`

    Alias of statsmodels.family.links.Power(power=1.)
    c                 L    t                                          d           d S )Nr/   rH   r\   r^   s    r	   rJ   zIdentity.__init__  ri   r   ra   rc   s   @r	   ro   ro     rj   r   ro   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	Logz
    The log transform

    Notes
    -----
    call and derivative call a private method _clean to trim the data by
    machine epsilon so that p is in (0,1). log is an alias of Log.
    c                 L    t          j        |t          t           j                  S rG   r1   r2   r3   infr   xs     r	   r4   z
Log._clean      wq)RV,,,r   c                 T    |                      |          }t          j        |          S )a  
        Log transform link function

        Parameters
        ----------
        x : array_like
            Mean parameters

        Returns
        -------
        z : ndarray
            log(x)

        Notes
        -----
        g(p) = log(p)
        r6   r   r   extrarw   s       r	   r   zLog.__call__  s!    $ KKNNvayyr   c                 *    t          j        |          S )aZ  
        Inverse of log transform link function

        Parameters
        ----------
        z : ndarray
            The inverse of the link function at `p`

        Returns
        -------
        p : ndarray
            The mean probabilities given the value of the inverse `z`

        Notes
        -----
        g^{-1}(z) = exp(z)
        rA   r   s     r	   r   zLog.inverse  s    $ vayyr   c                 6    |                      |          }d|z  S )a,  
        Derivative of log transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g'(p) : ndarray
            derivative of log transform of x

        Notes
        -----
        g'(x) = 1/x
        r/   r>   r   s     r	   r   z	Log.deriv  s    $ KKNNAvr   c                 <    |                      |          }d|dz  z  S )aC  
        Second derivative of the log transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g''(p) : ndarray
            Second derivative of log transform of x

        Notes
        -----
        g''(x) = -1/x^2
        r[   r@   r>   r   s     r	   r   z
Log.deriv2&  s!    $ KKNNQ!V|r   c                 *    t          j        |          S )al  
        Derivative of the inverse of the log transform link function

        Parameters
        ----------
        z : ndarray
            The inverse of the link function at `p`

        Returns
        -------
        g^(-1)'(z) : ndarray
            The value of the derivative of the inverse of the log function,
            the exponential function
        rA   r   s     r	   r!   zLog.inverse_deriv;  s     vayyr   N)
r'   r(   r)   r*   r4   r   r   r   r   r!   r+   r   r	   rr   rr     sx         - - -  *  (  *  *    r   rr   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
LogCz
    The log-complement transform

    Notes
    -----
    call and derivative call a private method _clean to trim the data by
    machine epsilon so that p is in (0,1). logc is an alias of LogC.
    c                 H    t          j        |t          dt          z
            S )Nr/   r0   rv   s     r	   r4   zLogC._cleanW  s    wq)R)^444r   c                 Z    |                      |          }t          j        d|z
            S )a  
        Log-complement transform link function

        Parameters
        ----------
        x : array_like
            Mean parameters

        Returns
        -------
        z : ndarray
            log(1 - x)

        Notes
        -----
        g(p) = log(1-p)
        r    r6   rz   s       r	   r   zLogC.__call__Z  s%    $ KKNNva!e}}r   c                 0    dt          j        |          z
  S )ai  
        Inverse of log-complement transform link function

        Parameters
        ----------
        z : ndarray
            The inverse of the link function at `p`

        Returns
        -------
        p : ndarray
            The mean probabilities given the value of the inverse `z`

        Notes
        -----
        g^{-1}(z) = 1 - exp(z)
        r    rA   r   s     r	   r   zLogC.inverseo  s    $ 26!99}r   c                 <    |                      |          }dd|z
  z  S )aI  
        Derivative of log-complement transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g'(p) : ndarray
            derivative of log-complement transform of x

        Notes
        -----
        g'(x) = -1/(1 - x)
        r[   r/   r>   r   s     r	   r   z
LogC.deriv  s!    $ KKNNb1f~r   c                 h    |                      |          }dt          j        dd|z
  z  d          z  S )ab  
        Second derivative of the log-complement transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g''(p) : ndarray
            Second derivative of log-complement transform of x

        Notes
        -----
        g''(x) = -(-1/(1 - x))^2
        r[   r/   r@   )r4   r1   rI   r   s     r	   r   zLogC.deriv2  s2    $ KKNNBHSBF^Q////r   c                 ,    t          j        |           S )aq  
        Derivative of the inverse of the log-complement transform link
        function

        Parameters
        ----------
        z : ndarray
            The inverse of the link function at `p`

        Returns
        -------
        g^(-1)'(z) : ndarray
            The value of the derivative of the inverse of the log-complement
            function.
        rA   r   s     r	   r!   zLogC.inverse_deriv  s      q		zr   c                 ,    t          j        |           S )af  
        Second derivative of the inverse link function g^(-1)(z).

        Parameters
        ----------
        z : array_like
            The inverse of the link function at `p`

        Returns
        -------
        g^(-1)''(z) : ndarray
            The value of the second derivative of the inverse of the
            log-complement function.
        rA   r   s     r	   r%   zLogC.inverse_deriv2  s     q		zr   N)r'   r(   r)   r*   r4   r   r   r   r   r!   r%   r+   r   r	   r   r   M  s         5 5 5  *  (  *0 0 0*  $    r   r   c                   Z    e Zd ZdZej        j        fdZd Zd Z	d Z
d Zd Zd Zd	 Zd
S )CDFLinka?  
    The use the CDF of a scipy.stats distribution

    CDFLink is a subclass of logit in order to use its _clean method
    for the link and its derivative.

    Parameters
    ----------
    dbn : scipy.stats distribution
        Default is dbn=scipy.stats.norm

    Notes
    -----
    The CDF link is untested.
    c                     || _         d S rG   dbn)r   r   s     r	   rJ   zCDFLink.__init__  s    r   c                 `    |                      |          }| j                            |          S )a  
        CDF link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        z : ndarray
            (ppf) inverse of CDF transform of p

        Notes
        -----
        g(`p`) = `dbn`.ppf(`p`)
        )r4   r   ppfr   s     r	   r   zCDFLink.__call__  s%    $ KKNNx||Ar   c                 6    | j                             |          S )ap  
        The inverse of the CDF link

        Parameters
        ----------
        z : array_like
            The value of the inverse of the link function at `p`

        Returns
        -------
        p : ndarray
            Mean probabilities.  The value of the inverse of CDF link of `z`

        Notes
        -----
        g^(-1)(`z`) = `dbn`.cdf(`z`)
        )r   cdfr   s     r	   r   zCDFLink.inverse  s    $ x||Ar   c                     |                      |          }d| j                            | j                            |                    z  S )a;  
        Derivative of CDF link

        Parameters
        ----------
        p : array_like
            mean parameters

        Returns
        -------
        g'(p) : ndarray
            The derivative of CDF transform at `p`

        Notes
        -----
        g'(`p`) = 1./ `dbn`.pdf(`dbn`.ppf(`p`))
        r/   )r4   r   pdfr   r   s     r	   r   zCDFLink.deriv  s8    $ KKNNDHLLa1111r   c                     |                      |          }| j                            |          }|                     |           | j                            |          dz  z  S )v
        Second derivative of the link function g''(p)

        implemented through numerical differentiation
        r#   )r4   r   r   r%   r   r   r   linpreds      r	   r   zCDFLink.deriv2$  sS     KKNN(,,q//$$W---W0E0E0JJJr   c                 \    ddl m} t          j        |          } ||| j        d          S )r   r   _approx_fprime_scalarTcentered)r   r   r1   
atleast_1dr   )r   r   r   s      r	   deriv2_numdiffzCDFLink.deriv2_numdiff.  s@     	DCCCCCM!$$Q
TBBBBr   c                 6    | j                             |          S )ac  
        Derivative of the inverse link function

        Parameters
        ----------
        z : ndarray
            The inverse of the link function at `p`

        Returns
        -------
        g^(-1)'(z) : ndarray
            The value of the derivative of the inverse of the logit function.
            This is just the pdf in a CDFLink,
        r   r   r   s     r	   r!   zCDFLink.inverse_deriv9  s     x||Ar   c                 \    ddl m} t          j        |          } ||| j        d          S )a  
        Second derivative of the inverse link function g^(-1)(z).

        Parameters
        ----------
        z : array_like
            `z` is usually the linear predictor for a GLM or GEE model.

        Returns
        -------
        g^(-1)''(z) : ndarray
            The value of the second derivative of the inverse of the link
            function

        Notes
        -----
        This method should be overwritten by subclasses.

        The inherited method is implemented through numerical differentiation.
        r   r   Tr   )r   r   r1   r   r!   )r   r   r   s      r	   r%   zCDFLink.inverse_deriv2J  sC    * 	DCCCCCM! %$Q(:TJJJJr   N)r'   r(   r)   r*   scipystatsnormrJ   r   r   r   r   r   r!   r%   r+   r   r	   r   r     s           !;+      *  (2 2 2*K K K	C 	C 	C  "K K K K Kr   r   c                       e Zd ZdZd Zd ZdS )Probitz
    The probit (standard normal CDF) transform

    Notes
    -----
    g(p) = scipy.stats.norm.ppf(p)

    probit is an alias of CDFLink.
    c                 >    | | j                             |          z  S )zy
        Second derivative of the inverse link function

        This is the derivative of the pdf in a CDFLink

        r   r   s     r	   r%   zProbit.inverse_deriv2q  s     sTX\\!__$$r   c                     |                      |          }| j                            |          }|| j                            |          dz  z  S )z@
        Second derivative of the link function g''(p)

        r@   )r4   r   r   r   r   s      r	   r   zProbit.deriv2z  sB    
 KKNN(,,q//g..!333r   N)r'   r(   r)   r*   r%   r   r+   r   r	   r   r   f  s<         % % %4 4 4 4 4r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )Cauchyz
    The Cauchy (standard Cauchy CDF) transform

    Notes
    -----
    g(p) = scipy.stats.cauchy.ppf(p)

    cauchy is an alias of CDFLink with dbn=scipy.stats.cauchy
    c                 j    t                                          t          j        j                   d S )Nr   )r]   rJ   r   r   cauchyr^   s    r	   rJ   zCauchy.__init__  s)    U[/00000r   c                     |                      |          }t          j        |dz
  z  }dt          j        dz  z  t          j        |          z  t          j        |          dz  z  }|S )a  
        Second derivative of the Cauchy link function.

        Parameters
        ----------
        p : array_like
            Probabilities

        Returns
        -------
        g''(p) : ndarray
            Value of the second derivative of Cauchy link function at `p`
        rh   r@   r#   )r4   r1   pisincos)r   r   ad2s       r	   r   zCauchy.deriv2  sU     KKNNEQW!^bfQii'"&))q.8	r   c                 >    d|z  t           j        |dz  dz   dz  z  z  S )Nr@   r    )r1   r   r   s     r	   r%   zCauchy.inverse_deriv2  s%    Qw"%16A:!"3344r   )r'   r(   r)   r*   rJ   r   r%   rb   rc   s   @r	   r   r     s`         1 1 1 1 1  &5 5 5 5 5 5 5r   r   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )CLogLogz
    The complementary log-log transform

    CLogLog inherits from Logit in order to have access to its _clean method
    for the link and its derivative.

    Notes
    -----
    CLogLog is untested.
    c                     |                      |          }t          j        t          j        d|z
                       S )a#  
        C-Log-Log transform link function

        Parameters
        ----------
        p : ndarray
            Mean parameters

        Returns
        -------
        z : ndarray
            The CLogLog transform of `p`

        Notes
        -----
        g(p) = log(-log(1-p))
        r    r6   r   s     r	   r   zCLogLog.__call__  s1    $ KKNNvrva!e}}n%%%r   c                 V    dt          j        t          j        |                     z
  S )a[  
        Inverse of C-Log-Log transform link function


        Parameters
        ----------
        z : array_like
            The value of the inverse of the CLogLog link function at `p`

        Returns
        -------
        p : ndarray
            Mean parameters

        Notes
        -----
        g^(-1)(`z`) = 1-exp(-exp(`z`))
        r    rA   r   s     r	   r   zCLogLog.inverse  s#    & 2626!99*%%%%r   c                 l    |                      |          }d|dz
  t          j        d|z
            z  z  S )aZ  
        Derivative of C-Log-Log transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g'(p) : ndarray
            The derivative of the CLogLog transform link function

        Notes
        -----
        g'(p) = - 1 / ((p-1)*log(1-p))
        r/   r    r6   r   s     r	   r   zCLogLog.deriv  s3    $ KKNNa!eq1u.//r   c                     |                      |          }t          j        d|z
            }dd|z
  dz  |z  z  }|dd|z  z   z  }|S )a  
        Second derivative of the C-Log-Log ink function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g''(p) : ndarray
            The second derivative of the CLogLog link function
        r    r   r@   r6   )r   r   flr   s       r	   r   zCLogLog.deriv2  sR     KKNNVAE]]AEa<"$%
a!b&j	r   c                 T    t          j        |t          j        |          z
            S )a`  
        Derivative of the inverse of the C-Log-Log transform link function

        Parameters
        ----------
        z : array_like
            The value of the inverse of the CLogLog link function at `p`

        Returns
        -------
        g^(-1)'(z) : ndarray
            The derivative of the inverse of the CLogLog link function
        rA   r   s     r	   r!   zCLogLog.inverse_deriv  s      va"&))m$$$r   N)	r'   r(   r)   r*   r   r   r   r   r!   r+   r   r	   r   r     si        	 	& & &*& & &*0 0 0*  (% % % % %r   r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	LogLogz
    The log-log transform

    LogLog inherits from Logit in order to have access to its _clean method
    for the link and its derivative.
    c                 |    |                      |          }t          j        t          j        |                      S )a  
        Log-Log transform link function

        Parameters
        ----------
        p : ndarray
            Mean parameters

        Returns
        -------
        z : ndarray
            The LogLog transform of `p`

        Notes
        -----
        g(p) = -log(-log(p))
        r6   r   s     r	   r   zLogLog.__call__!  s0    $ KKNNq		z""""r   c                 R    t          j        t          j        |                      S )aW  
        Inverse of Log-Log transform link function


        Parameters
        ----------
        z : array_like
            The value of the inverse of the LogLog link function at `p`

        Returns
        -------
        p : ndarray
            Mean parameters

        Notes
        -----
        g^(-1)(`z`) = exp(-exp(-`z`))
        rA   r   s     r	   r   zLogLog.inverse6  s     & vrvqbzzk"""r   c                 `    |                      |          }d|t          j        |          z  z  S )aR  
        Derivative of Log-Log transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g'(p) : ndarray
            The derivative of the LogLog transform link function

        Notes
        -----
        g'(p) = - 1 /(p * log(p))
        r[   r6   r   s     r	   r   zLogLog.derivK  s*    $ KKNNa26!99o&&r   c                     |                      |          }dt          j        |          z   |t          j        |          z  dz  z  }|S )a  
        Second derivative of the Log-Log link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g''(p) : ndarray
            The second derivative of the LogLog link function
        r    r@   r6   )r   r   r   s      r	   r   zLogLog.deriv2`  s?     KKNN"&))mRVAYYA55	r   c                 X    t          j        t          j        |            |z
            S )a\  
        Derivative of the inverse of the Log-Log transform link function

        Parameters
        ----------
        z : array_like
            The value of the inverse of the LogLog link function at `p`

        Returns
        -------
        g^(-1)'(z) : ndarray
            The derivative of the inverse of the LogLog link function
        rA   r   s     r	   r!   zLogLog.inverse_derivr  s$     vrvqbzzkAo&&&r   c                 ^    |                      |          t          j        |           dz
  z  S )ak  
        Second derivative of the inverse of the Log-Log transform link function

        Parameters
        ----------
        z : array_like
            The value of the inverse of the LogLog link function at `p`

        Returns
        -------
        g^(-1)''(z) : ndarray
            The second derivative of the inverse of the LogLog link function
        r    )r!   r1   r:   r   s     r	   r%   zLogLog.inverse_deriv2  s+     !!!$$r

Q77r   Nr&   r+   r   r	   r   r     sx         # # #*# # #*' ' '*  $' ' ' 8 8 8 8 8r   r   c                   >    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
S )NegativeBinomiala?  
    The negative binomial link function

    Parameters
    ----------
    alpha : float, optional
        Alpha is the ancillary parameter of the Negative Binomial link
        function. It is assumed to be nonstochastic.  The default value is 1.
        Permissible values are usually assumed to be in (.01, 2).
    r/   c                     || _         d S rG   alpha)r   r   s     r	   rJ   zNegativeBinomial.__init__  rK   r   c                 L    t          j        |t          t           j                  S rG   rt   rv   s     r	   r4   zNegativeBinomial._clean  rx   r   c                 p    |                      |          }t          j        ||d| j        z  z   z            S )a>  
        Negative Binomial transform link function

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        z : ndarray
            The negative binomial transform of `p`

        Notes
        -----
        g(p) = log(p/(p + 1/alpha))
        r    )r4   r1   r7   r   r   s     r	   r   zNegativeBinomial.__call__  s3    $ KKNNva1q4:~-.///r   c                 H    d| j         dt          j        |           z
  z  z  S )aa  
        Inverse of the negative binomial transform

        Parameters
        ----------
        z : array_like
            The value of the inverse of the negative binomial link at `p`.

        Returns
        -------
        p : ndarray
            Mean parameters

        Notes
        -----
        g^(-1)(z) = exp(z)/(alpha*(1-exp(z)))
        r   r    )r   r1   r:   r   s     r	   r   zNegativeBinomial.inverse  s$    $ TZ1rvqbzz>233r   c                 (    d|| j         |dz  z  z   z  S )a[  
        Derivative of the negative binomial transform

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g'(p) : ndarray
            The derivative of the negative binomial transform link function

        Notes
        -----
        g'(x) = 1/(x+alpha*x^2)
        r    r@   r   r   s     r	   r   zNegativeBinomial.deriv  s    $ A
Q!V++,,r   c                 T    dd| j         z  |z  z    }|| j         |dz  z  z   dz  }||z  S )a  
        Second derivative of the negative binomial link function.

        Parameters
        ----------
        p : array_like
            Mean parameters

        Returns
        -------
        g''(p) : ndarray
            The second derivative of the negative binomial transform link
            function

        Notes
        -----
        g''(x) = -(1+2*alpha*x)/(x+alpha*x^2)^2
        r    r@   r   )r   r   numerdenoms       r	   r   zNegativeBinomial.deriv2  s@    & a$*nq(()TZ!q&((Q.u}r   c                 P    t          j        |          }|| j        d|z
  dz  z  z  S )ak  
        Derivative of the inverse of the negative binomial transform

        Parameters
        ----------
        z : array_like
            Usually the linear predictor for a GLM or GEE model

        Returns
        -------
        g^(-1)'(z) : ndarray
            The value of the derivative of the inverse of the negative
            binomial link
        r    r@   )r1   r:   r   r;   s      r	   r!   zNegativeBinomial.inverse_deriv  s+     F1IIDJ!a%A-..r   NrW   )r'   r(   r)   r*   rJ   r4   r   r   r   r   r!   r+   r   r	   r   r     s        	 	   - - -0 0 0*4 4 4(- - -(  ./ / / / /r   r   c                   "     e Zd ZdZ fdZ xZS )logitzN
    Alias of Logit

    .. deprecated: 0.14.0

       Use Logit instead.
    c                 h    t          dd           t                                                       d S )Nr   r-   r
   r]   rJ   r^   s    r	   rJ   zlogit.__init__  s/    !'7333r   ra   rc   s   @r	   r   r     B                 r   r   c                   "     e Zd ZdZ fdZ xZS )inverse_powerzi
    Deprecated alias of InversePower.

    .. deprecated: 0.14.0

        Use InversePower instead.
    c                 h    t          dd           t                                                       d S )Nr   rY   r   r^   s    r	   rJ   zinverse_power.__init__$  s/    !/>BBBr   ra   rc   s   @r	   r   r     r   r   r   c                   "     e Zd ZdZ fdZ xZS )sqrtzY
    Deprecated alias of Sqrt.

    .. deprecated: 0.14.0

        Use Sqrt instead.
    c                 h    t          dd           t                                                       d S )Nr   rf   r   r^   s    r	   rJ   zsqrt.__init__2  /    !&&111r   ra   rc   s   @r	   r   r   )  r   r   r   c                   "     e Zd ZdZ fdZ xZS )inverse_squaredzm
    Deprecated alias of InverseSquared.

    .. deprecated: 0.14.0

        Use InverseSquared instead.
    c                 h    t          dd           t                                                       d S )Nr   rl   r   r^   s    r	   rJ   zinverse_squared.__init__@  s1    !"35EFFFr   ra   rc   s   @r	   r   r   7  r   r   r   c                   "     e Zd ZdZ fdZ xZS )identityza
    Deprecated alias of Identity.

    .. deprecated: 0.14.0

        Use Identity instead.
    c                 h    t          dd           t                                                       d S )Nr   ro   r   r^   s    r	   rJ   zidentity.__init__N  s/    !*j999r   ra   rc   s   @r	   r   r   E  r   r   r   c                   "     e Zd ZdZ fdZ xZS )r7   z
    The log transform

    .. deprecated: 0.14.0

       Use Log instead.

    Notes
    -----
    log is a an alias of Log.
    c                 h    t          dd           t                                                       d S )Nr7   rr   r   r^   s    r	   rJ   zlog.__init__`  s/    !%///r   ra   rc   s   @r	   r7   r7   S  B        
 
        r   r7   c                   "     e Zd ZdZ fdZ xZS )logcz
    The log-complement transform

    .. deprecated: 0.14.0

       Use LogC instead.

    Notes
    -----
    logc is a an alias of LogC.
    c                 h    t          dd           t                                                       d S )Nr   r   r   r^   s    r	   rJ   zlogc.__init__r  r   r   ra   rc   s   @r	   r   r   e  r   r   r   c                   "     e Zd ZdZ fdZ xZS )probitz
    The probit (standard normal CDF) transform

    .. deprecated: 0.14.0

       Use Probit instead.

    Notes
    -----
    probit is an alias of Probit.
    c                 h    t          dd           t                                                       d S )Nr   r   r   r^   s    r	   rJ   zprobit.__init__  /    !(H555r   ra   rc   s   @r	   r   r   w  r   r   r   c                   "     e Zd ZdZ fdZ xZS )r   z
    The Cauchy (standard Cauchy CDF) transform

    .. deprecated: 0.14.0

       Use Cauchy instead.

    Notes
    -----
    cauchy is an alias of Cauchy.
    c                 h    t          dd           t                                                       d S )Nr   r   r   r^   s    r	   rJ   zcauchy.__init__  r   r   ra   rc   s   @r	   r   r     r   r   r   c                   "     e Zd ZdZ fdZ xZS )cloglogz
    The CLogLog transform link function.

    .. deprecated: 0.14.0

       Use CLogLog instead.

    Notes
    -----
    g(`p`) = log(-log(1-`p`))

    cloglog is an alias for CLogLog
    cloglog = CLogLog()
    c                 h    t          dd           t                                                       d S )Nr   r   r   r^   s    r	   rJ   zcloglog.__init__  s/    !)Y777r   ra   rc   s   @r	   r   r     B                 r   r   c                   "     e Zd ZdZ fdZ xZS )loglogz
    The LogLog transform link function.

    .. deprecated: 0.14.0

       Use LogLog instead.

    Notes
    -----
    g(`p`) = -log(-log(`p`))

    loglog is an alias for LogLog
    loglog = LogLog()
    c                 h    t          dd           t                                                       d S )Nr   r   r   r^   s    r	   rJ   zloglog.__init__  r   r   ra   rc   s   @r	   r   r     r   r   r   c                   $     e Zd ZdZd fd	Z xZS )nbinomz
    The negative binomial link function.

    .. deprecated: 0.14.0

       Use NegativeBinomial instead.

    Notes
    -----
    g(p) = log(p/(p + 1/alpha))

    nbinom is an alias of NegativeBinomial.
    nbinom = NegativeBinomial(alpha=1.)
    r/   c                 l    t          dd           t                                          |           d S )Nr   r   r   r   )r   r   r_   s     r	   rJ   znbinom.__init__  s5    !(,>???u%%%%%r   rW   ra   rc   s   @r	   r   r     sG         & & & & & & & & & &r   r   )&r*   numpyr1   scipy.statsr   r   finfofloatepsr3   r
   r   r-   rE   rY   rf   rl   ro   rr   r   r   r   r   r   r   r   r   r   r   r   r   r7   r   r   r   r   r   r   r+   r   r	   <module>r      s,            BHUOO	  i6 i6 i6 i6 i6 i6 i6 i6X@$ @$ @$ @$ @$D @$ @$ @$FXP XP XP XP XPD XP XP XPv$ $ $ $ $5 $ $ $# # # # #5 # # #$ $ $ $ $U $ $ $# # # # #u # # #o o o o o$ o o odA A A A A4 A A AJQK QK QK QK QKe QK QK QKh4 4 4 4 4W 4 4 4<"5 "5 "5 "5 "5W "5 "5 "5Jm% m% m% m% m%e m% m% m%`w8 w8 w8 w8 w8U w8 w8 w8tv/ v/ v/ v/ v/t v/ v/ v/t    E       L       4       n       x       #   $    4   $    V   $    V   $    g   *    V   *& & & & & & & & & &r   