
    'YHhw                     D    d Z ddlZddlmZ ddlZ G d d      Z	 	 ddZy)zM
Created on Fri Dec 19 11:29:18 2014

Author: Josef Perktold
License: BSD-3

    N)statsc                   z    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y)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| _        y |dk(  r(t
        j                  | _        | j                  f| _        y || _        d| _        y )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          [/var/www/html/planif/env/lib/python3.12/site-packages/statsmodels/regression/_prediction.py__init__zPredictionResults.__init__$   so    '%"$<46>

DIDNS[DI"ggZDNDIDN    c                 Z    t        j                  | j                  | j                  z         S N)npsqrtr   r   r   s    r   se_obszPredictionResults.se_obs6   s     wwt))DNN:;;r   c                     | j                   S r   )ser   s    r   se_meanzPredictionResults.se_mean:   s    ww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                 @    t        j                  | j                        S r   )r   r   r   r   s    r   r   zPredictionResults.seH   s     wwt))**r   c                    |r| j                   n| j                  } | j                  j                  d|dz  z
  g| j                   }| 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   su    (  T[[T\\DIIMM!ebj.:4>>:##a"f,##a"f,u~..r   c                 `   | j                  |d      }| j                  |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                  |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--e-7
!00
6 $
9&-adm
?#&-adm
?#%+AqD\
>"%+AqD\
>"
 ll:T__#-??#46
r   )NNN)F皙?)r?   )__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r,   r>   r   r   r   r   r      s    * 15 $ < <       + +/6r   r   c                    |rtt        | j                  d      r^|\d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kD  r
|dddf   }n	|dddf   }t        j"                  |      }nR| j                  j$                  }|t        | j                  dd      }|!t        | j                  j                  dd      }|]t        j                  |      }|j&                  dkD  r9|j                  dk7  s|j                   d   |j                   d   k(  rt)        d	      |i } | j                  j*                  | j                  |fi |}| j-                         }|t        j.                  ||j0                        j0                  z  j3                  d      }	| j4                  }
| j6                  d
k(  r| j8                  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   )dmatrixr4   r$   weightsr   zweights has wrong shapezfixed scalescaler   r	   )r   r   r   ) hasattrmodelpatsyrG   
isinstancer7   Seriesr8   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   }   s,   F WTZZ38H!dBII&<<%Dtzz22D9 w5J
#!
zz$99>{{  #a'D!G}AtG}}}T"zz?djj)T:G ,EJ **W%LL1"gmmA&6$**Q-&G677	'TZZ''TGYGN??DBFF4022277:M

I }}%MM'*	W	C=$D^]I $D(24 4r   )NTNNN)	rC   numpyr   scipyr   pandasr7   r   rg   r   r   r   <module>rk      s1      k k\ =A.2Z4r   