ó
áp7]c           @   sT   d  Z  d d l Z d d l m Z d e f d „  ƒ  YZ d e 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   sV   e  Z d d d d  „ Z e d „  ƒ Z e d „  ƒ Z e d d „ Z d d d „ Z	 RS(   c         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ | d  k sE | d k r] 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   NoneR    R   t   distt	   dist_argsR   (   t   selfR   R   R   R   R
   R   (    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   __init__   s    						c         C   s   t  j |  j |  j ƒ S(   N(   t   npt   sqrtR   R   (   R   (    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   se_obs#   s    c         C   s   t  j |  j ƒ S(   N(   R   R   R   (   R   (    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   se_mean'   s    gš™™™™™©?c         C   sm   | r |  j  n |  j } |  j j d | d |  j Œ } |  j | | } |  j | | } t j | | f ƒ 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.

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

        i   g       @(   R   R   R
   t   ppfR   R   R   t   column_stack(   R   t   obst   alphat   set   qt   lowert   upper(    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   conf_int+   s
     t   allc   	      C   s  d d  l  } d d l m } |  j d | d t ƒ } |  j d | d t ƒ } | ƒ  } |  j | d <|  j | d <| d  d  … d f | d <| d  d  … d	 f | d
 <| d  d  … d f | d <| d  d  … d	 f | d <| |  _ | j	 | d |  j
 d | j ƒ  ƒ} | S(   Niÿÿÿÿ(   t   OrderedDictR   R   t   meant   mean_sei    t   mean_ci_loweri   t   mean_ci_uppert   obs_ci_lowert   obs_ci_uppert   indext   columns(   t   pandast   collectionsR   R   t   Truet   FalseR   R   t   tablet	   DataFrameR   t   keys(	   R   t   whatR   t   pdR   t   ci_obst   ci_meant
   to_includet   res(    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   summary_frameG   s    		N(
   t   __name__t
   __module__R	   R   t   propertyR   R   R(   R   R2   (    (    (    sA   lib/python2.7/site-packages/statsmodels/regression/_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  | d k rÙi  } n  |  j j |  j | |  } |  j ƒ  } | t	 j | | j ƒ j j d ƒ }	 |  j }
 |  j d k rM|  j d }
 n  | d k	 rf|
 | :}
 n  d d g |  j } t | |	 |
 d |  j d | d | ƒS(   sQ  
    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 : 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 shapes   fixed scalet   scaleR   R   R   R
   (   t   hasattrt   modelR	   t   patsyR7   t   datat   design_infot   getattrt   callableR   t   asarrayt   ndimt   exogt   shapet
   atleast_2dt   sizet
   ValueErrort   predictt   paramst
   cov_paramst   dott   Tt   sumR9   t   cov_typet   cov_kwdst   use_tR   t   df_resid(   R   RC   t	   transformR8   R   t	   pred_kwdsR7   R   t   covbR   R   R
   (    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   get_prediction_   sJ     $$)	%	(
   t   __doc__t   numpyR   t   scipyR    t   objectR   R	   R'   RU   (    (    (    sA   lib/python2.7/site-packages/statsmodels/regression/_prediction.pyt   <module>   s
   P	