
    !g                     *    d Z ddlZddlmZ d ZddZy)zZAdditional functions

prediction standard errors and confidence intervals


A: josef pktd
    N)statsc                     t        j                  |       } | j                  dk(  r| dddf   } | S | j                  dk(  rt        j                  |       } | S | j                  dkD  rt	        d      | S )zM convert array_like to 2d from 1d or 0d

    not tested because not used
       Nr   ztoo many dimensions)npasarrayndim
atleast_2d
ValueError)xs    c/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/statsmodels/sandbox/regression/predstd.pyatleast_2dcolr      sp    
 	

1A	!agJ
 H	 &&A+MM! H &&1*.//H    c                 J   | j                         }|;| j                  j                  }| j                  }|| j                  j                  }nt        j                  |      }|j                  d   |j                  d   k7  rt        d      | j                  j                  | j                  |      }|d}nJt        j                  |      }|j                  dkD  r&t        |      |j                  d   k7  rt        d      | j                  |z  |t        j                  ||j                         j                   z  j#                  d      z   }t        j$                  |      }t&        j(                  j+                  |dz  | j,                        }|||z  z   }	|||z  z
  }
||
|	fS )a  calculate standard deviation and confidence interval for prediction

    applies to WLS and OLS, not to general GLS,
    that is independently but not identically distributed observations

    Parameters
    ----------
    res : regression result instance
        results of WLS or OLS regression required attributes see notes
    exog : array_like (optional)
        exogenous variables for points to predict
    weights : scalar or array_like (optional)
        weights as defined for WLS (inverse of variance of observation)
    alpha : float (default: alpha = 0.05)
        confidence level for two-sided hypothesis

    Returns
    -------
    predstd : array_like, 1d
        standard error of prediction
        same length as rows of exog
    interval_l, interval_u : array_like
        lower und upper confidence bounds

    Notes
    -----
    The result instance needs to have at least the following
    res.model.predict() : predicted values or
    res.fittedvalues : values used in estimation
    res.cov_params() : covariance matrix of parameter estimates

    If exog is 1d, then it is interpreted as one observation,
    i.e. a row vector.

    testing status: not compared with other packages

    References
    ----------

    Greene p.111 for OLS, extended to WLS by analogy

    r   zwrong shape of exogg      ?r   z+weights and exog do not have matching shapeg       @)
cov_paramsmodelexogfittedvaluesweightsr   r	   shaper
   predictparamsr   sizelen	mse_residdotTsumsqrtr   tisfdf_resid)resr   r   alphacovb	predictedpredvarpredstdtppf
interval_u
interval_ls              r   wls_prediction_stdr+      s^   ^ >>D|yy~~$$	?ii''G}}T"::a=DJJqM)233II%%cjj$7	?Gjj)G||aCLDJJqM$A !NOO mmG#tbffT466.B.D.D'D&I&I!&LLGgggG77;;uRx.DTG^+JTG^+JJ
**r   )NNg?)__doc__numpyr   scipyr   r   r+    r   r   <module>r0      s     J+r   