
    M/Ph                     <    d dl Zd dlZd dlmZ  G d d          ZdS )    N)statsc                       e Zd ZdZ	 	 	 ddZddZed             Zed             Zed             Z	ed             Z
ed	             ZddZddZ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                    t          j        |          | _        t          j        |          | _        || _        || _        |t          |dd           | _        | j        d u| _        |dk    r|t          d          ||dk    rt          j
        | _        d| _        d S |dk    r t          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_mean_df_row_labelsgetattr_use_pandas
ValueErrorr   r	   dist	dist_argsr   
isinstancedistributions	rv_frozen)selfpredicted_meanvar_pred_meanr   df
row_labelss         _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tsa/base/prediction.py__init__zPredictionResults.__init__   s      "z.99 j77%&~wEED+473;;2>CDDD<46>>
DIDNNNS[[DI"h[DNNNe1;<< 	PDIDNNNNOOO    c                     | j         s|S |j        dk    rt          j        || j        |          S t          j        || j        |          S )N   )r   name)r   columns)r   ndimpdSeriesr   	DataFrame)r   valuer#   r$   s       r   _wrap_pandaszPredictionResults._wrap_pandas:   sQ     	L:??9U$*:FFFF|E)97KKKKr    c                     | j         S )z$The row labels used in pandas-types.)r   r   s    r   r   zPredictionResults.row_labelsA   s     r    c                 8    |                      | j        d          S )zThe predicted meanr   )r*   r   r,   s    r   r   z PredictionResults.predicted_meanF   s       !57GHHHr    c                 f    | j         j        dk    r| j         S |                     | j         d          S )z"The variance of the predicted mean   r   )r   r%   r*   r,   s    r   r   zPredictionResults.var_pred_meanK   s7     #a''&&  !4oFFFr    c                    | j         j        }|dk    rt          j        | j                   }nF|dk    r1t          j        | 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TdiagonalNotImplementedErrorr*   )r   r%   valuess      r   se_meanzPredictionResults.se_meanR   s}     "'199WT011FFQYYWT02;;==>>FF%&GHHH  333r    c                 f    | j         | j        z  }t          |t          j                  rd|_        |S )z9The ratio of the predicted mean to its standard deviationtvalues)r   r8   r   r&   r'   r#   )r   vals     r   r:   zPredictionResults.tvalues^   s3     !DL0c29%% 	! CH
r    r   	two-sidedc                 $   | j         |z
  | j        z  }|dv r. | j        j        t	          j        |          g| j        R  dz  }nI|dv r | j        j        |g| j        R  }n,|dv r | j        j        |g| j        R  }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-sided2sr/   )largerl)smallerszinvalid alternative)	r   r8   r   sfr   absr   cdfr   )r   r)   alternativestatpvalues        r   t_testzPredictionResults.t_testf   s    * #e+t|;888!TY\"&,,@@@@1DFFO++!TY\$8888FF,,,"TY]49$.999FF2333V|r    皙?c                     | j         } | j        j        d|dz  z
  g| j        R  }| j        ||z  z
  }| j        ||z  z   }t          j        ||f          }| j        r|                     |ddg          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$   )	r8   r   ppfr   r   r   column_stackr   r*   )r   alphaseqrL   rM   cis          r   conf_intzPredictionResults.conf_int   s    $ \DIM!eck/;DN;;;#a"f,#a"f,_eU^,, 	E$$R'71C$DDD	r    c                     t          j        |                     |                    }|dddf         |dddf         }}| j        | j        ||d}t          j        |          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.
        )rP   Nr   r"   )meanr2   mean_ci_lowermean_ci_upper)r   r   rT   r   r8   r&   r(   )r   rP   ci_meanrL   rM   
to_includes         r   summary_framezPredictionResults.summary_frame   sq    & *T]]]7788qqq!t}gaaadmu'|""	
 

 |J'''r    )NNN)NN)r   r<   )rJ   )__name__
__module____qualname____doc__r   r*   propertyr   r   r   r8   r:   rI   rT   r[   r
   r    r   r   r      s#        0 P P P P>L L L L     X  I I XI G G XG 	4 	4 X	4   X   B   6( ( ( ( ( (r    r   )numpyr   pandasr&   scipyr   r   r
   r    r   <module>rd      sk                 w( w( w( w( w( w( w( w( w( w(r    