U
    Ãmœd  ã                   @   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ršt	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   úX/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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   )Únumpyr   Zpandasr   Zscipyr   r   r   r   r   r   Ú<module>   s   