
    M/Phw                     L    d Z ddlZddlmZ ddlZ G d d          Z	 	 ddZdS )	zM
Created on Fri Dec 19 11:29:18 2014

Author: Josef Perktold
License: BSD-3

    N)statsc                       e Zd Z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S )PredictionResultsaE  
    Results class for predictions.

    Parameters
    ----------
    predicted_mean : ndarray
        The array containing the prediction means.
    var_pred_mean : ndarray
        The array of the variance of the prediction means.
    var_resid : ndarray
        The array of residual variances.
    df : int
        The degree of freedom used if dist is 't'.
    dist : {'norm', 't', object}
        Either a string for the normal or t distribution or another object
        that exposes a `ppf` method.
    row_labels : list[str]
        Row labels used in summary frame.
    Nc                     || _         || _        || _        || _        || _        ||dk    rt
          j        | _        d| _        d S |dk    r t
          j	        | _        | j        f| _        d S || _        d| _        d S )Nnorm t)
	predictedvar_preddf	var_resid
row_labelsr   r   dist	dist_argsr	   )selfpredicted_meanvar_pred_meanr   r   r   r   s          b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/regression/_prediction.py__init__zPredictionResults.__init__$   sy    '%"$<46>>
DIDNNNS[[DI"gZDNNNDIDNNN    c                 D    t          j        | j        | j        z             S N)npsqrtr   r   r   s    r   se_obszPredictionResults.se_obs6   s    wt)DN:;;;r   c                     | j         S r   )ser   s    r   se_meanzPredictionResults.se_mean:   s	    wr   c                     | j         S r   )r
   r   s    r   r   z PredictionResults.predicted_mean>   s     ~r   c                     | j         S r   )r   r   s    r   r   zPredictionResults.var_pred_meanC   s     }r   c                 4    t          j        | j                  S r   )r   r   r   r   s    r   r   zPredictionResults.seH   s     wt)***r   F皙?c                     |r| j         n| j        } | j        j        d|dz  z
  g| j        R  }| j        ||z  z
  }| j        ||z  z   }t          j        ||f          S )a.  
        Returns the confidence interval of the value, `effect` of the
        constraint.

        This is currently only available for t and z tests.

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

        Returns
        -------
        ci : ndarray, (k_constraints, 2)
            The array has the lower and the upper limit of the confidence
            interval in the columns.
           g       @)r   r   r   ppfr   r   r   column_stack)r   obsalphar   qloweruppers          r   conf_intzPredictionResults.conf_intM   sq    (  1T[[T\DIM!ebj.:4>:::#a"f,#a"f,u~...r   c                 p   |                      |d          }|                      |d          }i }| j        |d<   | j        |d<   |d d df         |d<   |d d df         |d	<   |d d df         |d
<   |d d df         |d<   || _        t	          j        || j        |                                          }|S )NT)r)   r(   Fmeanmean_ser   mean_ci_lowerr%   mean_ci_upperobs_ci_lowerobs_ci_upper)indexcolumns)r-   r   r   tablepd	DataFramer   keys)r   r)   ci_obsci_mean
to_includeress         r   summary_framezPredictionResults.summary_frameh   s    U55--e-77
!0
6 $
9&-aaadm
?#&-aaadm
?#%+AAAqD\
>"%+AAAqD\
>"
 l:T_#-??#4#46 6 6
r   )NNN)Fr#   )r#   )__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r-   r?   r   r   r   r   r      s         * 15       $ < < X<   X   X   X + + X+/ / / /6     r   r   Tc                 ~   |rft          | j        d          rQ|Oddlm} t	          |t
          j                  rt          j        |          } || j        j        j	        |          }||"t          |dd          }t          |          rd}t          j        |          }|j        dk    r/| j        j        d         dk    r|dddf         }n|dddf         }t          j        |          }nA| j        j        }|t          | j        dd          }|t          | j        j        dd          }|Ut          j        |          }|j        dk    r6|j        dk    s|j        d         |j        d         k    rt)          d	          |i } | j        j        | j        |fi |}|                                 }|t          j        ||j                  j        z                      d          }	| j        }
| j        d
k    r| j        d         }
||
|z  }
ddg| j                 }t=          ||	|
| j        ||          S )a  
    Compute prediction results.

    Parameters
    ----------
    exog : array_like, optional
        The values for which you want to predict.
    transform : bool, optional
        If the model was fit via a formula, do you want to pass
        exog through the formula. Default is True. E.g., if you fit
        a model y ~ log(x1) + log(x2), and transform is True, then
        you can pass a data structure that contains x1 and x2 in
        their original form. Otherwise, you'd need to log the data
        first.
    weights : array_like, optional
        Weights interpreted as in WLS, used for the variance of the predicted
        residual.
    row_labels : list
        A list of row labels to use.  If not provided, read `exog` is
        available.
    **kwargs
        Some models can take additional keyword arguments, see the predict
        method of the model for the details.

    Returns
    -------
    linear_model.PredictionResults
        The prediction results instance contains prediction and prediction
        variance and can on demand calculate confidence intervals and summary
        tables for the prediction of the mean and of new observations.
    formulaNr   )dmatrixr5   r%   weightsr   zweights has wrong shapezfixed scalescaler   r	   )r   r   r   ) hasattrmodelpatsyrG   
isinstancer8   Seriesr9   datadesign_infogetattrcallabler   asarrayndimparamsshape
atleast_2dexogsize
ValueErrorpredict
cov_paramsdotTsumrI   cov_typecov_kwdsuse_tr   df_resid)r   rX   	transformrH   r   	pred_kwdsrG   r   covbr   r   r   s               r   get_predictionrg   }   sg   F  :WTZ33 :8H!!!!!!dBI&& 	&<%%Dwtz2D99 w55J
## "!
z$9>>{ #a''D!!!G}AAAtG}}T""z?dj)T::G ,EEJ *W%%L1""gmA&6$*Q-&G&G6777	'TZ'TGGYGGN??DBF4002277::M
I }%%M'*	W	C=$D^]I $D(24 4 4 4r   )NTNNN)	rC   numpyr   scipyr   pandasr8   r   rg   r   r   r   <module>rk      s                  k k k k k k k k\ =A.2Z4 Z4 Z4 Z4 Z4 Z4r   