
    M/Ph                     ,    d Z ddlZddlmZ d ZddZdS )zZAdditional functions

prediction standard errors and confidence intervals


A: josef pktd
    N)statsc                     t          j        |           } | j        dk    r| dddf         } n:| j        dk    rt          j        |           } n| j        dk    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    f/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/sandbox/regression/predstd.pyatleast_2dcolr      sj    
 	
1A	!aaagJ
&A++M!
&1**.///H    皙?c                    |                                  }|"| j        j        }| j        }|| j        j        }nt          j        |          }|j        d         |j        d         k    rt          d          | j        	                    | j
        |          }|d}nLt          j        |          }|j        dk    r-t          |          |j        d         k    rt          d          | j        |z  |t          j        ||j                  j        z                      d          z   }t          j        |          }t&          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

    Nr   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|y~$	?i'G}T"":a=DJqM))2333I%%cj$77	?GGj))G|aCLLDJqM$A$A !NOOO mG#tbfT46.B.B.D'D&I&I!&L&LLGggG7;;uRx..DTG^+JTG^+JJ
**r   )NNr   )__doc__numpyr   scipyr   r   r,    r   r   <module>r1      sb                J+ J+ J+ J+ J+ J+r   