
    !g                     4    d dl Zd dlZd dlmZ  G d d      Zy)    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y)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k7  r|t        d      ||dk(  rt        j                  | _        d| _        y |dk(  r(t        j                  | _        | j                  f| _        y t        |t        j                  j                         r|| _        d| _        y 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/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/tsa/base/prediction.py__init__zPredictionResults.__init__   s      "zz.9 jj7%&~wED++473;2>CDD<46>

DIDNS[DI"hh[DNe11;;<DIDNN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:   sM    L::?99U$*:*:FF||E)9)97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                 :    | j                  | j                  d      S )zThe predicted meanr   )r*   r   r,   s    r   r   z PredictionResults.predicted_meanF   s       !5!57GHHr    c                     | j                   j                  dkD  r| j                   S | j                  | j                   d      S )z"The variance of the predicted mean   r   )r   r%   r*   r,   s    r   r   zPredictionResults.var_pred_meanK   s=     ##a'&&&  !4!4oFFr    c                 ,   | j                   j                  }|dk(  r t        j                  | j                         }nH|dk(  r8t        j                  | j                   j                  j                               }nt        d      | j                  |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   sy     ""''19WWT001FQYWWT0022;;=>F%&GHH  33r    c                 z    | 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^   s2     !!DLL0c299% CH
r    c                    | j                   |z
  | j                  z  }|dv rA | j                  j                  t	        j
                  |      g| j                   dz  }||fS |dv r+ | j                  j                  |g| j                   }||fS |dv r+ | j                  j                  |g| j                   }||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.
        )	two-sidedz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!TYY\\"&&,@@1DF V| O+!TYY\\$88F
 V|	 ,,"TYY]]49$..9F V| 233r    c                 0   | j                   } | j                  j                  d|dz  z
  g| j                   }| j                  ||z  z
  }| j                  ||z  z   }t        j                  ||f      }| j                  r| j                  |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qrK   rL   cis          r   conf_intzPredictionResults.conf_int   s    $ \\DIIMM!eck/;DNN;##a"f,##a"f,__eU^,$$R'71C$DD	r    c                     t        j                  | 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.
        )rO   Nr   r"   )meanr2   mean_ci_lowermean_ci_upper)r   r   rS   r   r8   r&   r(   )r   rO   ci_meanrK   rL   
to_includes         r   summary_framezPredictionResults.summary_frame   sd    & **T]]]78q!t}gadmu''||""	

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