ó
įp7]c           @   sl   d  Z  d d l Z d d l m Z d e f d     YZ d e d d d d d d  Z	 d d d d  Z
 d S(   sM   
Created on Fri Dec 19 11:29:18 2014

Author: Josef Perktold
License: BSD-3

i’’’’N(   t   statst   PredictionResultsc           B   s}   e  Z d d d d d d d   Z e d    Z e d    Z e d    Z d d d  Z d d d	  Z	 d
 d d  Z
 RS(   c	   	      C   sÆ   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | d  k sW | d k ro t j	 |  _
 d |  _ n< | d k r t j |  _
 |  j f |  _ n | |  _
 d |  _ d  S(   Nt   normt   t(    (    (   t   predicted_meant   var_pred_meant   dft	   var_residt
   row_labelst   linpredt   linkt   NoneR    R   t   distt	   dist_argsR   (	   t   selfR   R   R   R   R   R   R	   R
   (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   __init__   s    								c         C   s   t   t j |  j |  j  S(   N(   t   NotImplementedErrort   npt   sqrtR   R   (   R   (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   se_obs&   s    c         C   s   t  j |  j  S(   N(   R   R   R   (   R   (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   se_mean+   s    c         C   s   |  j  |  j S(   N(   R   R   (   R   (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   tvalues/   s    i    s	   two-sidedc         C   s¬   |  j  | |  j } | d
 k rH |  j j t j |  |  j  d } nZ | d k ro |  j j | |  j  } n3 | d k r |  j j | |  j  } n t d	   | | f S(   s3  z- or t-test for hypothesis that mean is equal to value

        Parameters
        ----------
        value : array_like
            value under the null hypothesis
        alternative : string
            'two-sided', 'larger', 'smaller'

        Returns
        -------
        stat : ndarray
            test statistic
        pvalue : ndarray
            p-value of the hypothesis test, the distribution is given by
            the attribute of the instance, specified in `__init__`. Default
            if not specified is the normal distribution.

        s	   two-sideds   2-sidedt   2si   t   largert   lt   smallert   ss   invalid alternative(   s	   two-sideds   2-sidedR   (   R   R   (   R   R   (	   R   R   R   t   sfR   t   absR   t   cdft
   ValueError(   R   t   valuet   alternativet   statt   pvalue(    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   t_test3   s    (t   endpointg©?c         K   sļ   t  j d d d  } |  j j |  | k j   } | d k rv | rv |  j j d | d t  } |  j j |  } nu | d k s | rė |  j } |  j	 j
 d | d |  j  }	 |  j |	 | }
 |  j |	 | } t  j |
 | f  } n  | S(	   s£  
        Returns the confidence interval of the value, `effect` of the
        constraint.

        This is currently only available for t and z tests.

        Parameters
        ----------
        alpha : float, optional
            The significance level for the confidence interval.
            ie., The default `alpha` = .05 returns a 95% confidence interval.

        kwds : extra keyword arguments
            currently ignored, only for compatibility, consistent signature

        Returns
        -------
        ci : ndarray, (k_constraints, 2)
            The array has the lower and the upper limit of the confidence
            interval in the columns.

        i    i   i   R$   t   alphat   obst   deltag       @(   R   t   linspaceR
   t   inverset   allR	   t   conf_intt   FalseR   R   t   ppfR   R   t   column_stack(   R   t   methodR%   t   kwdst   tmpt	   is_lineart	   ci_lineart   cit   set   qt   lowert   upper(    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyR+   T   s    	 R*   c         C   s¶   d d l  } d d l m } |  j d |  } |   } |  j | d <|  j | d <| d d  d f | d <| d d  d	 f | d
 <| |  _ | j | d |  j d | j	   } | S(   s   Summary framei’’’’N(   t   OrderedDictR%   t   meant   mean_sei    t   mean_ci_loweri   t   mean_ci_uppert   indext   columns(
   t   pandast   collectionsR9   R+   R   R   t   tablet	   DataFrameR   t   keys(   R   t   whatR%   t   pdR9   t   ci_meant
   to_includet   res(    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   summary_frame{   s    		N(   t   __name__t
   __module__R   R   t   propertyR   R   R   R#   R+   RJ   (    (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyR      s   !'c         C   sĀ  | rO t  |  j d  rO | d k	 rO d d l m } | |  j j j |  } n  | d k	 r| d k r t | d d  } t |  r d } q n  t	 j
 |  } | j d k rö |  j j j d k sŻ |  j j j d d k rö | d d  d f } n  t	 j |  } nW |  j j } | d k r8t |  j d d  } n  | d k r_t |  j j d d  } n  | d k	 rÄt	 j
 |  } | j d k rÄ| j d k s²| j d	 | j d k rÄt d
   qÄn  t | d <|  j j |  j | |  }	 |  j   }
 |  j j j j | j  } | d | t	 j |
 | j  j j d  } |  j } |  j d k re|  j d } n  | d k	 r~| | :} n  d d g |  j } t  |	 | | d |  j! d | d | d | d | S(   s^  
    compute prediction results

    Parameters
    ----------
    exog : array-like, optional
        The values for which you want to predict.
    transform : bool, optional
        If the model was fit via a formula, do you want to pass
        exog through the formula. Default is True. E.g., if you fit
        a model y ~ log(x1) + log(x2), and transform is True, then
        you can pass a data structure that contains x1 and x2 in
        their original form. Otherwise, you'd need to log the data
        first.
    weights : array_like, optional
        Weights interpreted as in WLS, used for the variance of the predicted
        residual.
    args, kwargs :
        Some models can take additional arguments or keywords, see the
        predict method of the model for the details.

    Returns
    -------
    prediction_results : generalized_linear_model.PredictionResults
        The prediction results instance contains prediction and prediction
        variance and can on demand calculate confidence intervals and summary
        tables for the prediction of the mean and of new observations.

    t   formulai’’’’(   t   dmatrixR>   i   Nt   weightsR   i    s   weights has wrong shapet   lineari   s   fixed scalet   scaleR   R   R   R   R	   R
   ("   t   hasattrt   modelR   t   patsyRO   t   datat   design_infot   getattrt   callableR   t   asarrayt   ndimt   exogt   shapet
   atleast_2dt   sizeR   R,   t   predictt   paramst
   cov_paramst   familyR
   t   inverse_derivR   t   dott   Tt   sumRR   t   cov_typet   cov_kwdst   use_tR   t   df_resid(   R   R\   t	   transformRP   R   R	   R
   t	   pred_kwdsRO   R   t   covbt
   link_derivR   R   R   (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   get_prediction_glm   sL    "$$)
-	c         C   s  d d l  m } | d	 k r7 | d	 k r7 | j   } n  | d	 k r^ t |  d  r^ |  j } n  t j |   }  | j |   } | j	 |   } | d t j
 |  } t j }	 t |  t j
 |  d |	 d | d | j   }
 t | | d |	 d | d |
 d | } | S(
   sJ  
    results for univariate, nonlinear, monotonicaly transformed parameters

    This provides transformed values, standard errors and confidence interval
    for transformations of parameters, for example in calculating rates with
    `exp(params)` in the case of Poisson or other models with exponential
    mean function.

    i’’’’(   t   linksR>   i   R   R   R
   R	   N(   t   statsmodels.genmod.familiesRq   R   t   LogRS   R>   R   RZ   R)   Rd   t   diagR    R   R   t   identity(   Ra   Rb   R
   Rl   R   Rq   R   Ro   R   R   R	   RI   (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   params_transform_univariateģ   s    	(   t   __doc__t   numpyR   t   scipyR    t   objectR   R   t   TrueRp   Rv   (    (    (    s=   lib/python2.7/site-packages/statsmodels/genmod/_prediction.pyt   <module>   s   		X