B
    Z{                 @   s6   d Z ddlZddlmZ G dd deZd	ddZdS )
zM
Created on Fri Dec 19 11:29:18 2014

Author: Josef Perktold
License: BSD-3

    N)statsc               @   sB   e Zd ZdddZedd Zedd Zdd
dZdddZdS )PredictionResultsNc             C   sj   || _ || _|| _|| _|| _|d ks.|dkr>tj| _d| _n(|dkrZtj	| _| jf| _n|| _d| _d S )Nnorm t)
predicted_meanvar_pred_meandf	var_resid
row_labelsr   r   dist	dist_argsr   )selfr   r   r
   r	   r   r   r   r   Alib/python3.7/site-packages/statsmodels/regression/_prediction.py__init__   s    zPredictionResults.__init__c             C   s   t | j| j S )N)npsqrtr   r
   )r   r   r   r   se_obs"   s    zPredictionResults.se_obsc             C   s   t | jS )N)r   r   r   )r   r   r   r   se_mean&   s    zPredictionResults.se_meanF皙?c             C   sV   |r
| j n| j}| jjd|d  f| j }| j||  }| j||  }t||fS )a'  
        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.

           g       @)r   r   r   Zppfr   r   r   Zcolumn_stack)r   obsalphaZseqlowerupperr   r   r   conf_int*   s
    zPredictionResults.conf_intallc       	      C   s   dd l }ddlm} | j|dd}| j|dd}| }| 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|| j|	 d}|S )Nr   )OrderedDictT)r   r   FZmeanZmean_seZmean_ci_lowerr   Zmean_ci_upperZobs_ci_lowerZobs_ci_upper)indexcolumns)
ZpandasZstatsmodels.compat.collectionsr   r   r   r   tableZ	DataFramer   keys)	r   Zwhatr   Zpdr   Zci_obsZci_meanZ
to_includeZresr   r   r   summary_frameF   s    


zPredictionResults.summary_frame)NNN)Fr   )r   r   )	__name__
__module____qualname__r   propertyr   r   r   r#   r   r   r   r   r      s
   

r   Tc             C   s  |r6t | jdr6|dk	r6ddlm} || jjjj|}|dk	r|dkr^t|dd}t|r^d}t	
|}|jdkr| jjjdks| jjjd dkr|dddf }t	|}n6| jj}|dkrt| jdd}|dkrt| jjdd}|dk	r.t	
|}|jdkr.|jdks&|jd |jd kr.td	|dkr<i }| jj| j|f|}|  }|t	||jj d}	| j}
| jd
kr| jd }
|dk	r|
| }
ddg| j }t||	|
| j||dS )aQ  
    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.
    ZformulaNr   )dmatrixr   r   weightsr   zweights has wrong shapezfixed scalescaler   r   )r	   r   r   )hasattrZmodelZpatsyr(   dataZdesign_infoZbuildergetattrcallabler   ZasarrayndimexogshapeZ
atleast_2dsize
ValueErrorZpredictZparamsZ
cov_paramsdotTsumr*   Zcov_typeZcov_kwdsZuse_tr   Zdf_resid)r   r0   Z	transformr)   r   Z	pred_kwdsr(   r   Zcovbr   r
   r   r   r   r   get_prediction^   sL     


"


r7   )NTNNN)__doc__Znumpyr   Zscipyr   objectr   r7   r   r   r   r   <module>   s
   P 