ó
áp7]c           @   sª  d  Z  d d l Z d d l Z e j e ƒ j Z d e	 f d „  ƒ  YZ
 d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e
 f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d  „  ƒ  YZ d! e
 f d" „  ƒ  YZ d# e f d$ „  ƒ  YZ d S(%   sB   
Defines the link functions to be used with GLM and GEE families.
iÿÿÿÿNt   Linkc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s”   
    A generic link function for one-parameter exponential family.

    `Link` does nothing, but lays out the methods expected of any subclass.
    c         C   s   t  S(   s  
        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
        (   t   NotImplementedError(   t   selft   p(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   __call__   s    c         C   s   t  S(   s~  
        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) : array
            The value of the inverse of the link function g^(-1)(z) = p


        (   R   (   R   t   z(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   inverse!   s    c         C   s   t  S(   s  
        Derivative of the link function g'(p).  Just a placeholder.

        Parameters
        ----------
        p : array-like

        Returns
        -------
        g'(p) : array
            The value of the derivative of the link function g'(p)
        (   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   deriv4   s    c         C   s)   d d l  m } t j | | |  j ƒ ƒ S(   sm   Second derivative of the link function g''(p)

        implemented through numerical differentiation
        iÿÿÿÿ(   t   approx_fprime_cs(   t   statsmodels.tools.numdiffR   t   npt   diagR   (   R   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   deriv2C   s    c         C   s   d |  j  |  j | ƒ ƒ S(   sð  
        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) : array
            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 overriden in subclasses.
        i   (   R   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   inverse_derivL   s    c         C   s.   |  j  | ƒ } |  j | ƒ |  j | ƒ d S(   s
  
        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) : array
            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 overriden in subclasses.
        i   (   R   R   R   (   R   R   t   iz(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   inverse_deriv2a   s    (	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR    
   s   						t   Logitc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sË   
    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         C   s   t  j | t d t ƒ S(   sí   
        Clip logistic values to range (eps, 1-eps)

        Parameters
        ----------
        p : array-like
            Probabilities

        Returns
        -------
        pclip : array
            Clipped probabilities
        g      ð?(   R
   t   clipt	   FLOAT_EPS(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   _clean†   s    c         C   s$   |  j  | ƒ } t j | d | ƒ S(   s  
        The logit transform

        Parameters
        ----------
        p : array-like
            Probabilities

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

        Notes
        -----
        g(p) = log(p / (1 - p))
        g      ð?(   R   R
   t   log(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   –   s    c         C   s+   t  j | ƒ } t  j | ƒ } d d | S(   s2  
        Inverse of the logit transform

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

        Returns
        -------
        p : array
            Probabilities

        Notes
        -----
        g^(-1)(z) = exp(z)/(1+exp(z))
        g      ð?(   R
   t   asarrayt   exp(   R   R   t   t(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   «   s    c         C   s   |  j  | ƒ } d | d | S(   sr  
        Derivative of the logit transform

        Parameters
        ----------
        p: array-like
            Probabilities

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

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

        Alias for `Logit`:
        logit = Logit()
        g      ð?i   (   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Á   s    c         C   s   t  j | ƒ } | d | d S(   sR  
        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) : array
            The value of the derivative of the inverse of the logit function

        i   i   (   R
   R   (   R   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Ú   s    c         C   s"   | d | } d | d | d S(   s  
        Second derivative of the logit function.

        Parameters
        ----------
        p : array-like
            probabilities

        Returns
        -------
        g''(z) : array
            The value of the second derivative of the logit function
        i   i   (    (   R   R   t   v(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ì   s    (	   R   R   R   R   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   y   s   					t   logitc           B   s   e  Z RS(    (   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   þ   s   t   Powerc           B   sP   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(	   s$  
    The power transform

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

    Notes
    -----
    Aliases of Power:
    inverse = Power(power=-1)
    sqrt = Power(power=.5)
    inverse_squared = Power(power=-2.)
    identity = Power(power=1.)
    g      ð?c         C   s   | |  _  d  S(   N(   t   power(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   __init__  s    c         C   s*   |  j  d k r | St j  | |  j  ƒ Sd S(   s  
        Power transform link function

        Parameters
        ----------
        p : array-like
            Mean parameters

        Returns
        -------
        z : array-like
            Power transform of x

        Notes
        -----
        g(p) = x**self.power
        i   N(   R   R
   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR     s    c         C   s.   |  j  d k r | St j  | d |  j  ƒ Sd S(   sN  
        Inverse of the power transform link function

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

        Returns
        -------
        `p` : array
            Mean parameters

        Notes
        -----
        g^(-1)(z`) = `z`**(1/`power`)
        i   g      ð?N(   R   R
   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   .  s    c         C   s>   |  j  d k r t j | ƒ S|  j  t j  | |  j  d ƒ Sd S(   sA  
        Derivative of the power transform

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g'(`p`) = `power` * `p`**(`power` - 1)
        i   N(   R   R
   t	   ones_like(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   E  s    c         C   sI   |  j  d k r t j | ƒ S|  j  |  j  d t j  | |  j  d ƒ Sd S(   se  
        Second derivative of the power transform

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g''(`p`) = `power` * (`power` - 1) * `p`**(`power` - 2)
        i   i   N(   R   R
   t
   zeros_like(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   \  s    c         C   sE   |  j  d k r t j | ƒ St j  | d |  j  |  j  ƒ |  j  Sd S(   sc  
        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) : array
            The value of the derivative of the inverse of the power transform
        function
        i   N(   R   R
   R    (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   s  s    c         C   sX   |  j  d k r t j | ƒ Sd |  j  t j  | d d |  j  |  j  ƒ |  j  d Sd S(   sj  
        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) : array
            The value of the derivative of the inverse of the power transform
        function
        i   i   N(   R   R
   R!   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ‡  s    (
   R   R   R   R   R   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR     s   					t   inverse_powerc           B   s   e  Z d  Z d „  Z RS(   s{   
    The inverse transform

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

    Alias of statsmodels.family.links.Power(power=-1.)
    c         C   s   t  t |  ƒ j d d ƒ d  S(   NR   g      ð¿(   t   superR"   R   (   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   §  s    (   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR"     s   	t   sqrtc           B   s   e  Z d  Z d „  Z RS(   s†   
    The square-root transform

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

    Alias of statsmodels.family.links.Power(power=.5)
    c         C   s   t  t |  ƒ j d d ƒ d  S(   NR   g      à?(   R#   R$   R   (   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   µ  s    (   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR$   «  s   	t   inverse_squaredc           B   s   e  Z d  Z d „  Z RS(   s   
    The inverse squared transform

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

    Alias of statsmodels.family.links.Power(power=2.)
    c         C   s   t  t |  ƒ j d d ƒ d  S(   NR   g       À(   R#   R%   R   (   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Ã  s    (   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR%   ¹  s   	t   identityc           B   s   e  Z d  Z d „  Z RS(   s}   
    The identity transform

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

    Alias of statsmodels.family.links.Power(power=1.)
    c         C   s   t  t |  ƒ j d d ƒ d  S(   NR   g      ð?(   R#   R&   R   (   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Ñ  s    (   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR&   Ç  s   	t   Logc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s¼   
    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         C   s   t  j | t t  j ƒ S(   N(   R
   R   R   t   inf(   R   t   x(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ß  s    c         K   s   |  j  | ƒ } t j | ƒ S(   s   
        Log transform link function

        Parameters
        ----------
        x : array-like
            Mean parameters

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

        Notes
        -----
        g(p) = log(p)
        (   R   R
   R   (   R   R   t   extraR)   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   â  s    c         C   s   t  j | ƒ S(   sV  
        Inverse of log transform link function

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

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

        Notes
        -----
        g^{-1}(z) = exp(z)
        (   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ÷  s    c         C   s   |  j  | ƒ } d | S(   s*  
        Derivative of log transform link function

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g'(x) = 1/x
        g      ð?(   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR     s    c         C   s   |  j  | ƒ } d | d S(   sA  
        Second derivative of the log transform link function

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g''(x) = -1/x^2
        g      ð¿i   (   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR      s    c         C   s   t  j | ƒ S(   sh  
        Derivative of the inverse of the log transform link function

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

        Returns
        -------
        g^(-1)'(z) : array
            The value of the derivative of the inverse of the log function,
            the exponential function
        (   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   5  s    (	   R   R   R   R   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR'   Õ  s   					R   c           B   s   e  Z d  Z RS(   sN   
    The log transform

    Notes
    -----
    log is a an alias of Log.
    (   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   G  s   t   CDFLinkc           B   sM   e  Z d  Z e j j d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   s?  
    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         C   s   | |  _  d  S(   N(   t   dbn(   R   R,   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   d  s    c         C   s   |  j  | ƒ } |  j j | ƒ S(   s  
        CDF link function

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g(`p`) = `dbn`.ppf(`p`)
        (   R   R,   t   ppf(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   g  s    c         C   s   |  j  j | ƒ S(   sn  
        The inverse of the CDF link

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

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

        Notes
        -----
        g^(-1)(`z`) = `dbn`.cdf(`z`)
        (   R,   t   cdf(   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   |  s    c         C   s/   |  j  | ƒ } d |  j j |  j j | ƒ ƒ S(   s9  
        Derivative of CDF link

        Parameters
        ----------
        p : array-like
            mean parameters

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

        Notes
        -----
        g'(`p`) = 1./ `dbn`.pdf(`dbn`.ppf(`p`))
        g      ð?(   R   R,   t   pdfR-   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR     s    c         C   s>   d d l  m } t j | ƒ } t j | | |  j d t ƒƒ S(   sv   
        Second derivative of the link function g''(p)

        implemented through numerical differentiation
        iÿÿÿÿ(   t   approx_fprimet   centered(   R	   R0   R
   t
   atleast_1dR   R   t   True(   R   R   R0   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ¥  s    c         C   s   d |  j  |  j | ƒ ƒ S(   sI  
        Derivative of the inverse of the CDF transformation link function

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

        Returns
        -------
        g^(-1)'(z) : array
            The value of the derivative of the inverse of the logit function
        i   (   R   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   °  s    (   R   R   R   t   scipyt   statst   normR   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR+   S  s   				t   probitc           B   s   e  Z d  Z RS(   s   
    The probit (standard normal CDF) transform

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

    probit is an alias of CDFLink.
    (   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR7   Á  s   	t   cauchyc           B   s    e  Z d  Z d „  Z d „  Z RS(   s­   
    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         C   s#   t  t |  ƒ j d t j j ƒ d  S(   NR,   (   R#   R8   R   R4   R5   (   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Ù  s    c         C   sD   t  j | d } d t  j d t  j | ƒ t  j | ƒ d } | S(   s  
        Second derivative of the Cauchy link function.

        Parameters
        ----------
        p: array-like
            Probabilities

        Returns
        -------
        g''(p) : array
            Value of the second derivative of Cauchy link function at `p`
        g      à?i   i   (   R
   t   pit   sint   cos(   R   R   t   at   d2(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Ü  s    /(   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR8   Î  s   		t   CLogLogc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÎ   
    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         C   s*   |  j  | ƒ } t j t j d | ƒ ƒ S(   s  
        C-Log-Log transform link function

        Parameters
        ----------
        p : array
            Mean parameters

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

        Notes
        -----
        g(p) = log(-log(1-p))
        i   (   R   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ú  s    c         C   s   d t  j t  j | ƒ ƒ S(   sY  
        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 : array
            Mean parameters

        Notes
        -----
        g^(-1)(`z`) = 1-exp(-exp(`z`))
        i   (   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR     s    c         C   s,   |  j  | ƒ } d | d t j d | ƒ S(   sX  
        Derivative of C-Log-Log transform link function

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g'(p) = - 1 / ((p-1)*log(1-p))
        g      ð?i   (   R   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   $  s    c         C   sN   |  j  | ƒ } t j d | ƒ } d d | d | } | d d | 9} | S(   s  
        Second derivative of the C-Log-Log ink function

        Parameters
        ----------
        p : array-like
            Mean parameters

        Returns
        -------
        g''(p) : array
            The second derivative of the CLogLog link function
        i   iÿÿÿÿi   (   R   R
   R   (   R   R   t   flR=   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   9  s
    c         C   s   t  j | t  j | ƒ ƒ S(   s^  
        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) : array
            The derivative of the inverse of the CLogLog link function
        (   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   M  s    (   R   R   R   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR>   ï  s   
				t   cloglogc           B   s   e  Z d  Z RS(   sž   
    The CLogLog transform link function.

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

    cloglog is an alias for CLogLog
    cloglog = CLogLog()
    (   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR@   ^  s   
t   NegativeBinomialc           B   sP   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(	   s?  
    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).
    g      ð?c         C   s   | |  _  d  S(   N(   t   alpha(   R   RB   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   x  s    c         C   s   t  j | t t  j ƒ S(   N(   R
   R   R   R(   (   R   R)   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   {  s    c         C   s+   |  j  | ƒ } t j | | d |  j ƒ S(   s<  
        Negative Binomial transform link function

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g(p) = log(p/(p + 1/alpha))
        i   (   R   R
   R   RB   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   ~  s    c         C   s   d |  j  d t j | ƒ S(   s_  
        Inverse of the negative binomial transform

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

        Returns
        -------
        p : array
            Mean parameters

        Notes
        -----
        g^(-1)(z) = exp(z)/(alpha*(1-exp(z)))
        iÿÿÿÿi   (   RB   R
   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   “  s    c         C   s   d | |  j  | d S(   sY  
        Derivative of the negative binomial transform

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g'(x) = 1/(x+alpha*x^2)
        i   i   (   RB   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   §  s    c         C   s7   d d |  j  | } | |  j  | d d } | | S(   s‰  
        Second derivative of the negative binomial link function.

        Parameters
        ----------
        p : array-like
            Mean parameters

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

        Notes
        -----
        g''(x) = -(1+2*alpha*x)/(x+alpha*x^2)^2
        i   i   (   RB   (   R   R   t   numert   denom(    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   »  s    c         C   s&   t  j | ƒ } | |  j d | d S(   si  
        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) : array
            The value of the derivative of the inverse of the negative
            binomial link
        i   i   (   R
   R   RB   (   R   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyR   Ò  s    (
   R   R   R   R   R   R   R   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyRA   l  s   
					t   nbinomc           B   s   e  Z d  Z RS(   s¸   
    The negative binomial link function.

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

    nbinom is an alias of NegativeBinomial.
    nbinom = NegativeBinomial(alpha=1.)
    (   R   R   R   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyRE   å  s   
(   R   t   numpyR
   t   scipy.statsR4   t   finfot   floatt   epsR   t   objectR    R   R   R   R"   R$   R%   R&   R'   R   R+   R7   R8   R>   R@   RA   RE   (    (    (    s@   lib/python2.7/site-packages/statsmodels/genmod/families/links.pyt   <module>   s(   o…›rn!oy