o
    0Gf                     @   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 u rt|dd | _| jd u| _|dkr/|d ur/td|d u s7|dkr@t	j
| _d| _d S |dkrOt	j| _| jf| _d S t|t	jjr^|| _d| _d S td)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   
isinstanceZdistributionsZ	rv_frozen)selfpredicted_meanvar_pred_meanr   Zdf
row_labelsr   r   ?lib/python3.10/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   Z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v r | jjt|g| jR  d }||fS |dv r3| jj|g| jR  }||fS |dv rF| jj|g| jR  }||fS td)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    ZalternativestatZpvaluer   r   r   t_testf   s    zPredictionResults.t_test皙?c                 C   sj   | j }| jjd|d  g| jR  }| j||  }| j||  }t||f}| jr3| 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   alphaZseqr3   r4   Z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.
        )r5   Nr   r   )Zmeanr%   Zmean_ci_lowerZmean_ci_upper)r   r	   r7   r   r)   r   r   )r   r5   Zci_meanr3   r4   Z
to_includer   r   r   summary_frame   s   "
zPredictionResults.summary_frame)NNN)NN)r   r,   )r2   )__name__
__module____qualname____doc__r   r!   propertyr   r   r   r)   r*   r1   r7   r8   r   r   r   r   r      s(    








!r   )Znumpyr   Zpandasr   Zscipyr   r   r   r   r   r   <module>   s    