U
    KvfM  ã                   @   sF   d Z ddlZddlmZ ddlmZ ddd„Zddd	„Zdd
d„Z	dS )zM
Created on Mon Oct  5 12:36:54 2020

Author: Josef Perktold
License: BSD-3

é    N)Úspecial)ÚHolderçš™™™™™©?c              	   C   s†   |d }| | }t  |d¡}t  || |d  ¡}t  || d |d  ¡}t | |d¡}t | |d| |g¡}	t||	||||dd}
|
S )uw  noncentrality parameter for chi-square statistic

    `nc` is zero-truncated umvue

    Parameters
    ----------
    chi2_stat : float
        Chisquare-statistic, for example from a hypothesis test
    df : int or float
        Degrees of freedom
    alpha : float in (0, 1)
        Significance level for the confidence interval, covarage is 1 - alpha.

    Returns
    -------
    HolderTuple
        The main attributes are

        - ``nc`` : estimate of noncentrality parameter
        - ``confint`` : lower and upper bound of confidence interval for `nc``

        Other attributes are estimates for nc by different methods.

    References
    ----------
    .. [1] Kubokawa, T., C.P. Robert, and A.K.Md.E. Saleh. 1993. â€œEstimation of
        Noncentrality Parameters.â€
        Canadian Journal of Statistics 21 (1): 45â€“57.
        https://doi.org/10.2307/3315657.

    .. [2] Li, Qizhai, Junjian Zhang, and Shuai Dai. 2009. â€œOn Estimating the
        Non-Centrality Parameter of a Chi-Squared Distribution.â€
        Statistics & Probability Letters 79 (1): 98â€“104.
        https://doi.org/10.1016/j.spl.2008.07.025.

    é   r   é   ç      à?z7Noncentrality for chisquare-distributed random variable)ÚncÚconfintÚnc_umvueÚnc_lzdÚnc_krsÚ	nc_medianÚname)ÚnpÚmaximumr   Z	chndtrincr   )Z	chi2_statÚdfÚalphaÚ
alpha_halfr
   r   r   r   r   ÚciÚres© r   úA/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/stats/effect_size.pyÚ_noncentrality_chisquare   s     %úr   c                 C   s   |d }| | | }|d | | }t  |d¡}t  ||d |d  |d  ¡}t ||d| ¡}	t ||d| |g| ¡}
t||
|||	dd}|S )uY  noncentrality parameter for f statistic

    `nc` is zero-truncated umvue

    Parameters
    ----------
    fstat : float
        f-statistic, for example from a hypothesis test
        df : int or float
        Degrees of freedom
    alpha : float in (0, 1)
        Significance level for the confidence interval, covarage is 1 - alpha.

    Returns
    -------
    HolderTuple
        The main attributes are

        - ``nc`` : estimate of noncentrality parameter
        - ``confint`` : lower and upper bound of confidence interval for `nc``

        Other attributes are estimates for nc by different methods.

    References
    ----------
    .. [1] Kubokawa, T., C.P. Robert, and A.K.Md.E. Saleh. 1993. â€œEstimation of
       Noncentrality Parameters.â€ Canadian Journal of Statistics 21 (1): 45â€“57.
       https://doi.org/10.2307/3315657.
    r   r   r   r   z/Noncentrality for F-distributed random variable)r   r	   r
   r   r   r   )r   r   r   Z	ncfdtrincr   )Zf_statZdf1Zdf2r   r   Zx_sr
   r   r   r   r   r   r   r   r   Ú_noncentrality_fG   s     ûr   c           
      C   s€   |d }t  t |d d ¡t |d ¡ ¡}t  |d ¡| }| | }t |d| ¡}t |d| |g| ¡}t|||dd}	|	S )uR  noncentrality parameter for t statistic

    Parameters
    ----------
    fstat : float
        f-statistic, for example from a hypothesis test
        df : int or float
        Degrees of freedom
    alpha : float in (0, 1)
        Significance level for the confidence interval, covarage is 1 - alpha.

    Returns
    -------
    HolderTuple
        The main attributes are

        - ``nc`` : estimate of noncentrality parameter
        - ``confint`` : lower and upper bound of confidence interval for `nc``

        Other attributes are estimates for nc by different methods.

    References
    ----------
    .. [1] Hedges, Larry V. 2016. â€œDistribution Theory for Glassâ€™s Estimator of
       Effect Size and Related Estimators:â€
       Journal of Educational Statistics, November.
       https://doi.org/10.3102/10769986006002107.

    r   g       @r   r   z/Noncentrality for t-distributed random variable)r   r	   r   r   )r   Úexpr   ZgammalnÚsqrtZ	nctdtrincr   )
Zt_statr   r   r   ZgfacZc11r   r   r   r   r   r   r   Ú_noncentrality_tx   s    &ýr   )r   )r   )r   )
Ú__doc__Znumpyr   Zscipyr   Zstatsmodels.stats.baser   r   r   r   r   r   r   r   Ú<module>   s   
9
1