U
    Kvf                     @   s.   d dl Zd dlZd dlmZ G dd dZdS )    N)statsc                   @   s~   e Zd ZdZdddZdddZedd Zed	d
 Zedd Z	edd Z
edd ZdddZdddZdddZdS )PredictionResultsa  
    Prediction results

    Parameters
    ----------
    predicted_mean : {ndarray, Series, DataFrame}
        The predicted mean values
    var_pred_mean : {ndarray, Series, DataFrame}
        The variance of the predicted mean values
    dist : {None, "norm", "t", rv_frozen}
        The distribution to use when constructing prediction intervals.
        Default is normal.
    df : int, optional
        The degree of freedom parameter for the t. Not used if dist is None,
        "norm" or a callable.
    row_labels : {Sequence[Hashable], pd.Index}
        Row labels to use for the summary frame. If None, attempts to read the
        index of ``predicted_mean``
    Nc                 C   s   t || _t || _|| _|| _|d kr:t|dd | _| jd k	| _|dkr^|d k	r^td|d ksn|dkr~t	j
| _d| _n@|dkrt	j| _| jf| _n$t|t	jjr|| _d| _ntdd S )Nindextz$df must be None when dist is not "t"norm z/dist must be a None, "norm", "t" or a callable.)npasarray_predicted_mean_var_pred_meanZ_df_row_labelsgetattr_use_pandas
ValueErrorr   r   dist	dist_argsr   
isinstancedistributionsZ	rv_frozen)selfpredicted_meanvar_pred_meanr   Zdf
row_labelsr   r   C/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/tsa/base/prediction.py__init__   s&    zPredictionResults.__init__c                 C   s8   | j s
|S |jdkr&tj|| j|dS tj|| j|dS )N   )r   name)r   columns)r   ndimpdSeriesr   	DataFrame)r   valuer   r   r   r   r   _wrap_pandas:   s
    
zPredictionResults._wrap_pandasc                 C   s   | j S )z$The row labels used in pandas-types.)r   r   r   r   r   r   A   s    zPredictionResults.row_labelsc                 C   s   |  | jdS )zThe predicted meanr   )r"   r
   r#   r   r   r   r   F   s    z PredictionResults.predicted_meanc                 C   s    | j jdkr| j S | | j dS )z"The variance of the predicted mean   r   )r   r   r"   r#   r   r   r   r   K   s    zPredictionResults.var_pred_meanc                 C   sN   | j j}|dkrt| j }n$|dkr:t| j j }ntd| |dS )z,The standard deviation of the predicted meanr      zvar_pre_mean must be 1 or 3 dimmean_se)r   r   r   sqrtTZdiagonalNotImplementedErrorr"   )r   r   valuesr   r   r   se_meanR   s    zPredictionResults.se_meanc                 C   s"   | j | j }t|tjrd|_|S )z9The ratio of the predicted mean to its standard deviationtvalues)r   r+   r   r   r   r   )r   valr   r   r   r,   ^   s    zPredictionResults.tvaluesr   	two-sidedc                 C   s   | j | | j }|dkr8| jjt|f| j d }nD|dkrV| jj|f| j }n&|dkrt| jj|f| j }ntd||fS )a8  
        z- or t-test for hypothesis that mean is equal to value

        Parameters
        ----------
        value : array_like
            value under the null hypothesis
        alternative : str
            '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.
        )r.   z2-sidedZ2sr$   )Zlargerl)Zsmallerszinvalid alternative)	r   r+   r   Zsfr   absr   Zcdfr   )r   r!   alternativestatZpvaluer   r   r   t_testf   s     zPredictionResults.t_test皙?c                 C   sh   | j }| jjd|d  f| j }| j||  }| j||  }t||f}| jrd| j|ddgdS |S )a	  
        Confidence interval construction for the predicted mean.

        This is currently only available for t and z tests.

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

        Returns
        -------
        pi : {ndarray, DataFrame}
            The array has the lower and the upper limit of the prediction
            interval in the columns.
        r   g       @lowerupper)r   )	r+   r   Zppfr   r   r   Zcolumn_stackr   r"   )r   alphaseqr6   r7   cir   r   r   conf_int   s    zPredictionResults.conf_intc                 C   sP   t | j|d}|dddf |dddf  }}| j| j||d}t|S )a  
        Summary frame of mean, variance and confidence interval.

        Returns
        -------
        DataFrame
            DataFrame containing four columns:

            * mean
            * mean_se
            * mean_ci_lower
            * mean_ci_upper

        Notes
        -----
        Fixes alpha to 0.05 so that the confidence interval should have 95%
        coverage.
        )r8   Nr   r   )Zmeanr&   Zmean_ci_lowerZmean_ci_upper)r   r	   r<   r   r+   r   r    )r   r8   Zci_meanr6   r7   Z
to_includer   r   r   summary_frame   s    "zPredictionResults.summary_frame)NNN)NN)r   r.   )r5   )r5   )__name__
__module____qualname____doc__r   r"   propertyr   r   r   r+   r,   r4   r<   r=   r   r   r   r   r      s&      







!
r   )Znumpyr   Zpandasr   Zscipyr   r   r   r   r   r   <module>   s   