
    >hX                        S r SSKrSSKrSSKJrJrJr  SSKJ	r	  S r
S rS rS rS	 rS#S
 jrS$S jr  S%S jr  S&S jrS'S jrS(S jrS(S jr " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S \5      r " S! S"\5      r\" 5       R>                  r \" 5       R>                  r!\" 5       R>                  r"g))aD  Statistical power, solving for nobs, ... - trial version

Created on Sat Jan 12 21:48:06 2013

Author: Josef Perktold

Example
roundtrip - root with respect to all variables

       calculated, desired
nobs   33.367204205 33.367204205
effect 0.5 0.5
alpha  0.05 0.05
power   0.8 0.8


TODO:
refactoring
 - rename beta -> power,    beta (type 2 error is beta = 1-power)  DONE
 - I think the current implementation can handle any kinds of extra keywords
   (except for maybe raising meaningful exceptions
 - streamline code, I think internally classes can be merged
   how to extend to k-sample tests?
   user interface for different tests that map to the same (internal) test class
 - sequence of arguments might be inconsistent,
   arg and/or kwds so python checks what's required and what can be None.
 - templating for docstrings ?


    N)statsoptimizespecial)brentq_expandingc                 0    [         R                  " XU 5      $ Nr   nctdtrxdfncs      jC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/stats/power.pynct_cdfr   '   s    >>"!$$    c                 6    S[         R                  " XU 5      -
  $ N   r	   r   s      r   nct_sfr   +   s    w~~ba(((r   c                 0    [         R                  " XX05      $ r   r   ncfdtrr   dfndfdr   s       r   ncf_cdfr   /   s    >>#B**r   c                 6    S[         R                  " XX05      -
  $ r   r   r   s       r   ncf_sfr   3   s    w~~c...r   c                 0    [         R                  " XX05      $ r   )r   ncfdtri)qr   r   r   s       r   ncf_ppfr"   7   s    ??3R++r   c           	         U nUc  US-
  nUS;   a  US-  nOUS;   a  UnO[        S5      eSnUS;   a  [        R                  R                  Xc5      n[        R
                  " [        R                  " U5      5      (       a  [        R                  nO#[        XU[        R                  " U5      -  5      nUS;   a  [        R                  R                  Xc5      n	[        R
                  " [        R                  " U	5      5      (       a  [        R                  nU$ U[        XU[        R                  " U5      -  5      -  nU$ )	zCalculate power of a ttest
    r   	two-sided2s       @smallerlarger8alternative has to be 'two-sided', 'larger' or 'smaller'r   r%   r&   r*   r%   r&   r)   )
ValueErrorr   tisfnpanyisnannanr   sqrtppfr   )
effect_sizenobsalphar   alternativedalpha_pow_crit_uppcrit_lows
             r   ttest_powerr@   ;   s    	A	zAX))	-	- ( ) 	) D3377;;v* 66"((8$%%66D ("''$-8D4477;;v*66"((8$%%66D K GH!BGGDM/::DKr   c                    U nUS;   a  US-  nOUS;   a  UnO[        S5      eSnUS;   aZ  [        R                  R                  U5      n[        R                  R	                  X[
        R                  " U5      -  U-  -
  5      nUS;   a]  [        R                  R                  U5      nU[        R                  R                  X[
        R                  " U5      -  U-  -
  5      -  nU$ )a  Calculate power of a normal distributed test statistic

This is an generalization of `normal_power` when variance under Null and
Alternative differ.

Parameters
----------
effect size : float
    difference in the estimated means or statistics under the alternative
    normalized by the standard deviation (without division by sqrt(nobs).
nobs : float or int
    number of observations
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
alternative : string, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.
r$   r'   r(   r+   r   r,   r-   	r.   r   normr0   sfr1   r5   r6   cdf)	r7   r8   r9   r:   sigmar;   r<   r=   crits	            r   normal_powerrH   a   s    , 	A))	-	- ( ) 	) D33zz~~f%zz}}TbggdmOE$99:44zz~~f%

toe&;;<<Kr   c                    U nUc  UnUS;   a  US-  nOUS;   a  UnO[        S5      eX4-  nSn	US;   a]  [        R                  R                  U5      n
[        R                  R	                  X-  U[
        R                  " U5      -  U-  -
  5      n	US;   a`  [        R                  R                  U5      n
U	[        R                  R                  X-  U[
        R                  " U5      -  U-  -
  5      -  n	U	$ )a  Calculate power of a normal distributed test statistic

This is an generalization of `normal_power` when variance under Null and
Alternative differ.

Parameters
----------
diff : float
    difference in the estimated means or statistics under the alternative.
nobs : float or int
    number of observations
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
std_null : float
    standard deviation under the Null hypothesis without division by
    sqrt(nobs)
std_alternative : float
    standard deviation under the Alternative hypothesis without division
    by sqrt(nobs)
alternative : string, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.

Returns
-------
power : float
r$   r'   r(   r+   r   r,   r-   rB   )diffr8   r9   std_nullstd_alternativer:   r;   r<   	std_ratior=   rG   s              r   normal_power_hetrN      s    @ 	A"))	-	- ( ) 	) *ID33zz~~f%zz}}T-rwwt}_>? @44zz~~f%

t/ @ A B 	BKr   c                     Uc  Un[         R                  R                  U5      n[         R                  R                  U5      n[        R                  " Xc-  XT-  -
  S5      U -  S-  nU$ )a  explicit sample size computation if only one tail is relevant

The sample size is based on the power in one tail assuming that the
alternative is in the tail where the test has power that increases
with sample size.
Use alpha/2 to compute the one tail approximation to the two-sided
test, i.e. consider only one tail of two-sided test.

Parameters
----------
diff : float
    difference in the estimated means or statistics under the alternative.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a type II
    error. Power is the probability that the test correctly rejects the
    Null Hypothesis if the Alternative Hypothesis is true.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
    Note: alpha is used for one tail. Use alpha/2 for two-sided
    alternative.
std_null : float
    standard deviation under the Null hypothesis without division by
    sqrt(nobs)
std_alternative : float
    standard deviation under the Alternative hypothesis without division
    by sqrt(nobs). Defaults to None. If None, ``std_alternative`` is set
    to the value of ``std_null``.

Returns
-------
nobs : float
    Sample size to achieve (at least) the desired power.
    If the minimum power is satisfied for all positive sample sizes, then
    ``nobs`` will be zero. This will be the case when power <= alpha if
    std_alternative is equal to std_null.

r      )r   rC   r0   r1   maximum)rJ   powerr9   rK   rL   
crit_powerrG   n1s           r   normal_sample_size_one_tailrU      sc    R "&J::>>% D
**T_z'CCQ
G
BIr   c                 |    US-
  nX-
  n[         R                  R                  X%U5      n[        XuX`S-  U-  5      nU$ )zpower for ftest for one way anova with k equal sized groups

nobs total sample size, sum over all groups

should be general nobs observations, k_groups restrictions ???
r   rP   r   fr0   r   )	r7   r8   r9   k_groupsr   df_numdf_denomrG   r=   s	            r   ftest_anova_powerr\      sB     \FH77;;uh/D$q.4*?@DKr   c                 |    X!peU S-  Xe-   U-   -  n[         R                  R                  X5U5      n[        XXg5      n	U	$ )a  Calculate the power of a F-test.

Parameters
----------
effect_size : float
    The effect size is here Cohen's ``f``, the square root of ``f2``.
df2 : int or float
    Denominator degrees of freedom.
    This corresponds to the df_resid in Wald tests.
df1 : int or float
    Numerator degrees of freedom.
    This corresponds to the number of constraints in Wald tests.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ncc : int
    degrees of freedom correction for non-centrality parameter.
    see Notes

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

Notes
-----
changed in 0.14: use df2, df1 instead of df_num, df_denom as arg names.
The latter had reversed meaning.

The sample size is given implicitly by ``df2`` with fixed number of
constraints given by numerator degrees of freedom ``df1``:

    nobs = df2 + df1 + ncc

Set ncc=0 to match t-test, or f-test in LikelihoodModelResults.
ncc=1 matches the non-centrality parameter in R::pwr::pwr.f2.test

ftest_power with ncc=0 should also be correct for f_test in regression
models, with df_num (df1) as number of constraints and d_denom (df2) as
df_resid.
rP   rW   )
r7   df2df1r9   nccrZ   r[   r   rG   r=   s
             r   ftest_powerra     sG    X H	a8,s2	3B77;;uh/D $-DKr   c                 r    XU-   U-   -  n[         R                  R                  X1U5      n[        XaX%5      nU$ )aq  Calculate the power of a F-test.

Based on Cohen's `f^2` effect size.

This assumes

    df_num : numerator degrees of freedom, (number of constraints)
    df_denom : denominator degrees of freedom (df_resid in regression)
    nobs = df_denom + df_num + ncc
    nc = effect_size * nobs  (noncentrality index)

Power is computed one-sided in the upper tail.

Parameters
----------
effect_size : float
    Cohen's f2 effect size or noncentrality divided by nobs.
df_num : int or float
    Numerator degrees of freedom.
    This corresponds to the number of constraints in Wald tests.
df_denom : int or float
    Denominator degrees of freedom.
    This corresponds to the df_resid in Wald tests.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ncc : int
    degrees of freedom correction for non-centrality parameter.
    see Notes

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

Notes

The sample size is given implicitly by ``df_denom`` with fixed number of
constraints given by numerator degrees of freedom ``df_num``:

    nobs = df_denom + df_num + ncc

Set ncc=0 to match t-test, or f-test in LikelihoodModelResults.
ncc=1 matches the non-centrality parameter in R::pwr::pwr.f2.test

ftest_power with ncc=0 should also be correct for f_test in regression
models, with df_num (df1) as number of constraints and d_denom (df2) as
df_resid.
rW   )r7   rZ   r[   r9   r`   r   rG   r=   s           r   ftest_power_f2rc   :  s>    j 
6)C/	0B77;;uh/D $-DKr   c                   >    \ rS rSrSrS rS rS rS r  S
S jr	S	r
g)Poweriz  zSStatistical Power calculations, Base Class

so far this could all be class methods
c                    U R                   R                  U5        [        SSSSSSSSS9U l        S	S
KJn  U" [        5      U l        S H  n[        SSS9U R                  U'   M     S H  n[        SSS9U R                  U'   M     S H  n[        SSS9U R                  U'   M     S H  n[        SSS9U R                  U'   M     g )Ng{Gz?g      $@g333333?g333333?r   
      )r7   r8   r9   rR   nobs1ratiorZ   r[   r   )defaultdict)r8   ri   rZ   r[   r'   g      I@low	start_upp)r[         ?)rj   :0yE>rP   r9   g-q=g?)rm   upp)__dict__updatedict	start_ttpcollectionsrk   start_bqexp)selfkwdsrk   keys       r   __init__Power.__init__  s    T"$S$'s!%'!  	,&t,:C$(R3$?DS! ;C$(R3$?DS!  C$(TQ$?DS! C$(U	$BDS! r   c                     [         er   )NotImplementedError)ry   argsrz   s      r   rR   Power.power  s    !!r   c                 N    UR                  S5      nU R                  " U0 UD6U-
  $ )NrR   )poprR   )ry   r   rz   power_s       r   _power_identityPower._power_identity  s)    '"zz4(4(611r   c                   ^ ^^ TR                  5        VVs/ s H  u  p#Ub  M
  UPM     snnm[        T5      S:w  a  [        S5      eTS   mTS:X  a  TS	 T R                  " S0 TD6$ TS   S:X  a>  SSKnSSKJn  UR                  " SU5        TS:X  a  TS	   $ TS	:X  a  TS   $ [        S
5      eST l        UUU 4S jn T R                  T   nT R                  T   n	/ n
 [        U4SS0U	D6u  pSnU
R                  U5        SnU(       d  WR                  (       a  SnO[         R"                  " U5      (       d0  [$        R&                  " XgSS9u  pnnUS   nU
R                  U5        OSnSnU
R                  S/5        US:X  a  [         R(                  " U5      S:  a  SnOITS;   aA  [$        R*                  " USSSS9u  nnUR                  (       a  SOSnU
R                  U5        OSnUS:X  d  SSKnSSKJnJn  UR                  " UU5        U
R1                  SU5        U
T l        W$ s  snnf ! [         a&    SnSSKnSSKJn  UR                  " ST 3U5         GNf = f! [         a    SnU
R                  S5         GNf = f)a  solve for any one of the parameters of a t-test

for t-test the keywords are:
    effect_size, nobs, alpha, power

exactly one needs to be ``None``, all others need numeric values

*attaches*

cache_fit_res : list
    Cache of the result of the root finding procedure for the latest
    call to ``solve_power``, mainly for debugging purposes.
    The first element is the success indicator, one if successful.
    The remaining elements contain the return information of the up to
    three solvers that have been tried.


Nr   z%need exactly one keyword that is Noner   rR   r7   )HypothesisTestWarningz"Warning: Effect size of 0 detectedr9   zACannot detect an effect-size of 0. Try changing your effect-size.c                    > U TT'   TR                   " S0 TD6nT=R                  S-  sl        TR                  S:  a  [        S5      e[        R                  " U5      (       a  [        R
                  $ U$ )Nr   i  z possible endless loop (500 NaNs) )r   _counterRuntimeErrorr1   r3   inf)r   fvalr{   rz   ry   s     r   funcPower.solve_power.<locals>.func  s`    DI''/$/DMMQM}}s""#EFFxx~~vvr   ?)ValueWarningz'Warning: using default start_value for full_outputTFr   fvecg-C6?)r9   rR   r7   rp   G?)ConvergenceWarningconvergence_docr   )itemslenr.   rR   warningsstatsmodels.tools.sm_exceptionsr   warnr   rv   KeyErrorr   rx   r   append	convergedr1   r3   r   fsolveabsbrentqr   r   insertcache_fit_res)ry   rz   kvr   r   r   start_valuer   fit_kwdsfit_resvalresfailedsuccessinfodictiermsgr   rr   r   r{   s   ``                    @r   solve_powerPower.solve_power  s   , !JJL6LSQAqL6s8q=DEE!f'>W::%%%!#MMM>@UVg~G}$g~G}$ !dee 
		Y..-K ##C(	!'K$K(KHCFNN3
 CMMG 88K((*2//$FJ+L'sC  'x(v&axBFF4L4/ ;;%__T49=?FC#$;;aAGNN1%G!|!MM/+=> 	q'"$
} 7N  	YKDMMCC5I<X		Y  	!FNN4 	!s.   	H-H-?H3  #I& 3,I#"I#&JJNc           
      "   SSK Jn	  SSKJn
  U	R	                  U5      u  pSSKJn  UR                  R                  nSnSnUS:X  a  U
" [        U5      5      n[        R                  " SS[        U5      5       Vs/ s H  nU" U5      PM     nn[        U5       H5  u  nnU R                  " UX$40 UD6nUR                  UUXUU   S	U-  S
9  SnM7     OUS;   a  U
" [        U5      5      n[        R                  " SS[        U5      5       Vs/ s H  nU" U5      PM     nn[        U5       H6  u  nnU R                  " UUU40 UD6nUR                  UUXUU   SU-  S
9  SnM8     OhUS;   aW  U
" [        U5      5      n[        U5       H6  u  nnU R                  " UUU40 UD6nUR                  UUXUU   SU-  S
9  SnM8     O[        S5      eUc  SnUR!                  W5        UR#                  U5        UR%                  SS9  U$ s  snf s  snf )a  
Plot power with number of observations or effect size on x-axis

Parameters
----------
dep_var : {'nobs', 'effect_size', 'alpha'}
    This specifies which variable is used for the horizontal axis.
    If dep_var='nobs' (default), then one curve is created for each
    value of ``effect_size``. If dep_var='effect_size' or alpha, then
    one curve is created for each value of ``nobs``.
nobs : {scalar, array_like}
    specifies the values of the number of observations in the plot
effect_size : {scalar, array_like}
    specifies the values of the effect_size in the plot
alpha : {float, array_like}
    The significance level (type I error) used in the power
    calculation. Can only be more than a scalar, if ``dep_var='alpha'``
ax : None or axis instance
    If ax is None, than a matplotlib figure is created. If ax is a
    matplotlib axis instance, then it is reused, and the plot elements
    are created with it.
title : str
    title for the axis. Use an empty string, ``''``, to avoid a title.
plt_kwds : {None, dict}
    not used yet
kwds : dict
    These remaining keyword arguments are used as arguments to the
    power function. Many power function support ``alternative`` as a
    keyword argument, two-sample test support ``ratio``.

Returns
-------
Figure
    If `ax` is None, the created figure.  Otherwise the figure to which
    `ax` is connected.

Notes
-----
This works only for classes where the ``power`` method has
``effect_size``, ``nobs`` and ``alpha`` as the first three arguments.
If the second argument is ``nobs1``, then the number of observations
in the plot are those for the first sample.
TODO: fix this for FTestPower and GofChisquarePower

TODO: maybe add line variable, if we want more than nobs and effectsize
r   )utils)rainbowNr   rP   r8   r   zes=%4.2F)lwr9   colorlabelzNumber of Observations)zeffect sizer7   eszN=%4.2FzEffect Sizerq   r9   zdepvar not implementedzPower of Testzlower right)loc)statsmodels.graphicsr   statsmodels.graphics.plottoolsr   create_mpl_axmatplotlib.pyplotpyplotcmDark2r   r1   linspace	enumeraterR   plotr.   
set_xlabel	set_titlelegend)ry   dep_varr8   r7   r9   axtitleplt_kwdsrz   r   r   figpltcolormap	plt_alphar   colorsiiir   rR   xlabelns                          r   
plot_powerPower.plot_power  s   d 	/:%%b)'66<<	fS-.F+-;;q#s;?O+PQ+Pahqk+PFQ#K0B

2t;d;e$Rj
R  A1	 1
 <<SY'F+-;;q#s4y+IJ+Iahqk+IFJ"4A

;5ADAUr$Rj	A  ?&	 )
 	!SY'F"4A

;5ADAu$Rj	A  ? 	 ) 566=#E
f
U
		m	$
? R Ks   :HH)r   r   rx   rv   )r8   NNg?NNN)__name__
__module____qualname____firstlineno____doc__r|   rR   r   r   r   __static_attributes__r   r   r   re   re   z  s.    
C,"2tl AE=AZr   re   c                   >   ^  \ rS rSrSrSS jr  SU 4S jjrSrU =r$ )
TTestPowerip  zKStatistical Power calculations for one sample or paired sample t-test

    c                     [        XX4US9$ )a&  Calculate the power of a t-test for one sample or paired samples.

Parameters
----------
effect_size : float
    standardized effect size, mean divided by the standard deviation.
    effect size has to be positive.
nobs : int or float
    sample size, number of observations.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
df : int or float
    degrees of freedom. By default this is None, and the df from the
    one sample or paired ttest is used, ``df = nobs1 - 1``
alternative : str, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.
    .

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

r   r:   r@   )ry   r7   r8   r9   r   r:   s         r   rR   TTestPower.poweru  s    @ ;e'24 	4r   c                 &   > [         TU ]  UUUUUS9$ )a  solve for any one parameter of the power of a one sample t-test

for the one sample t-test the keywords are:
    effect_size, nobs, alpha, power

Exactly one needs to be ``None``, all others need numeric values.

This test can also be used for a paired t-test, where effect size is
defined in terms of the mean difference, and nobs is the number of
pairs.

Parameters
----------
effect_size : float
    Standardized effect size.The effect size is here Cohen's f, square
    root of "f2".
nobs : int or float
    sample size, number of observations.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
alternative : str, 'two-sided' (default) or 'one-sided'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test.
    'one-sided' assumes we are in the relevant tail.

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.

*attaches*

cache_fit_res : list
    Cache of the result of the root finding procedure for the latest
    call to ``solve_power``, mainly for debugging purposes.
    The first element is the success indicator, one if successful.
    The remaining elements contain the return information of the up to
    three solvers that have been tried.

Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

)r7   r8   r9   rR   r:   superr   )ry   r7   r8   r9   rR   r:   	__class__s         r   r   TTestPower.solve_power  s-    v w"{;?<A<ABM	 # O 	Or   r   Nr%   )NNNNr%   	r   r   r   r   r   rR   r   r   __classcell__r   s   @r   r   r   p  s$    !4H JN +?O ?Or   r   c                   B   ^  \ rS rSrSr  SS jr  SU 4S jjrSrU =r$ )TTestIndPoweri  zkStatistical Power calculations for t-test for two independent sample

currently only uses pooled variance

c                 X    X$-  nUc  US-
  U-   S-
  nSSU-  SU-  -   -  n[        XX5US9$ )a  Calculate the power of a t-test for two independent sample

Parameters
----------
effect_size : float
    standardized effect size, difference between the two means divided
    by the standard deviation. `effect_size` has to be positive.
nobs1 : int or float
    number of observations of sample 1. The number of observations of
    sample two is ratio times the size of sample 1,
    i.e. ``nobs2 = nobs1 * ratio``
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ratio : float
    ratio of the number of observations in sample 2 relative to
    sample 1. see description of nobs1
    The default for ratio is 1; to solve for ratio given the other
    arguments, it has to be explicitly set to None.
df : int or float
    degrees of freedom. By default this is None, and the df from the
    ttest with pooled variance is used, ``df = (nobs1 - 1 + nobs2 - 1)``
alternative : str, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

r   ro   r   r   )	ry   r7   ri   r9   rj   r   r:   nobs2r8   s	            r   rR   TTestIndPower.power  sJ    L :!)e#a'BBJe+,;eTTr   c           	      (   > [         TU ]  UUUUUUS9$ )a  solve for any one parameter of the power of a two sample t-test

for t-test the keywords are:
    effect_size, nobs1, alpha, power, ratio

exactly one needs to be ``None``, all others need numeric values

Parameters
----------
effect_size : float
    standardized effect size, difference between the two means divided
    by the standard deviation. `effect_size` has to be positive.
nobs1 : int or float
    number of observations of sample 1. The number of observations of
    sample two is ratio times the size of sample 1,
    i.e. ``nobs2 = nobs1 * ratio``
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
ratio : float
    ratio of the number of observations in sample 2 relative to
    sample 1. see description of nobs1
    The default for ratio is 1; to solve for ratio given the other
    arguments it has to be explicitly set to None.
alternative : str, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

r7   ri   r9   rR   rj   r:   r   ry   r7   ri   r9   rR   rj   r:   r   s          r   r   TTestIndPower.solve_power  0    h w"{<A<A<A<ABM # O 	Or   r   )r   Nr%   NNNNro   r%   r   r   s   @r   r   r     s.     <@%-U` KO*59O 9Or   r   c                   R   ^  \ rS rSrSrSU 4S jjr  SS jr  S	U 4S jjrSrU =r	$ )
NormalIndPoweriM  zmStatistical Power calculations for z-test for two independent samples.

currently only uses pooled variance

c                 2   > Xl         [        TU ]  " S0 UD6  g )Nr   )ddofr   r|   )ry   r   rz   r   s      r   r|   NormalIndPower.__init__T  s    	 4 r   c                 p    U R                   nUS:  a  X$-  nSSX&-
  -  SXv-
  -  -   -  nOX&-
  n[        XX5S9$ )a  Calculate the power of a z-test for two independent sample

Parameters
----------
effect_size : float
    standardized effect size, difference between the two means divided
    by the standard deviation. effect size has to be positive.
nobs1 : int or float
    number of observations of sample 1. The number of observations of
    sample two is ratio times the size of sample 1,
    i.e. ``nobs2 = nobs1 * ratio``
    ``ratio`` can be set to zero in order to get the power for a
    one sample test.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ratio : float
    ratio of the number of observations in sample 2 relative to
    sample 1. see description of nobs1
alternative : str, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

r   ro   )r:   )r   rH   )	ry   r7   ri   r9   rj   r:   r   r   r8   s	            r   rR   NormalIndPower.powerX  sO    F yy 19KEel+bEL.AABD<DKuNNr   c           	      (   > [         TU ]  UUUUUUS9$ )a>  solve for any one parameter of the power of a two sample z-test

for z-test the keywords are:
    effect_size, nobs1, alpha, power, ratio

exactly one needs to be ``None``, all others need numeric values

Parameters
----------
effect_size : float
    standardized effect size, difference between the two means divided
    by the standard deviation.
    If ratio=0, then this is the standardized mean in the one sample
    test.
nobs1 : int or float
    number of observations of sample 1. The number of observations of
    sample two is ratio times the size of sample 1,
    i.e. ``nobs2 = nobs1 * ratio``
    ``ratio`` can be set to zero in order to get the power for a
    one sample test.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
ratio : float
    ratio of the number of observations in sample 2 relative to
    sample 1. see description of nobs1
    The default for ratio is 1; to solve for ration given the other
    arguments it has to be explicitly set to None.
alternative : str, 'two-sided' (default), 'larger', 'smaller'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test. The one-sided test can be
    either 'larger', 'smaller'.

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

r   r   r   s          r   r   NormalIndPower.solve_power  s0    p w"{<A<A<A<ABM # O 	Or   r   r   r   r%   r   )
r   r   r   r   r   r|   rR   r   r   r   r   s   @r   r   r   M  s2    ! 67%,O^ KO*5=O =Or   r   c                   >   ^  \ rS rSrSrSS jr  SU 4S jjrSrU =r$ )
FTestPoweri  aB  Statistical Power calculations for generic F-test of a constraint

This class is not recommended, use `FTestPowerF2` with corrected interface.

This is based on Cohen's f as effect size measure.

Warning: Methods in this class have the names df_num and df_denom reversed.

See Also
--------
FTestPowerF2 :
    Class with Cohen's f-squared as effect size, corrected keyword names.

Examples
--------
Sample size and power for multiple regression base on R-squared

Compute effect size from R-squared

>>> r2 = 0.1
>>> f2 = r2 / (1 - r2)
>>> f = np.sqrt(f2)
>>> r2, f2, f
(0.1, 0.11111111111111112, 0.33333333333333337)

Find sample size by solving for denominator df, wrongly named ``df_num``

>>> df1 = 1  # number of constraints in hypothesis test
>>> df2 = FTestPower().solve_power(effect_size=f, alpha=0.1, power=0.9,
                                   df_denom=df1)
>>> ncc = 1  # default
>>> nobs = df2 + df1 + ncc
>>> df2, nobs
(76.46459758305376, 78.46459758305376)

verify power at df2

>>> FTestPower().power(effect_size=f, alpha=0.1, df_denom=df1, df_num=df2)
0.8999999972109698

c                     [        XX4US9nU$ )a  Calculate the power of a F-test.

The effect size is Cohen's ``f``, square root of ``f2``.

The sample size is given by ``nobs = df_denom + df_num + ncc``

Warning: The meaning of df_num and df_denom is reversed.

Parameters
----------
effect_size : float
    Standardized effect size. The effect size is here Cohen's ``f``,
    square root of ``f2``.
df_num : int or float
    Warning incorrect name
    denominator degrees of freedom,
    This corresponds to the number of constraints in Wald tests.
df_denom : int or float
    Warning incorrect name
    numerator degrees of freedom.
    This corresponds to the df_resid in Wald tests.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ncc : int
    degrees of freedom correction for non-centrality parameter.
    see Notes

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

Notes
-----

sample size is given implicitly by df_num

set ncc=0 to match t-test, or f-test in LikelihoodModelResults.
ncc=1 matches the non-centrality parameter in R::pwr::pwr.f2.test

ftest_power with ncc=0 should also be correct for f_test in regression
models, with df_num and d_denom as defined there. (not verified yet)
r`   )ra   ry   r7   rZ   r[   r9   r`   r=   s          r   rR   FTestPower.power  s    ` ;SIr   c           	         > U(       a+  SU;   a  [         R                  " S5        O[        SU 35      e[        TU ]  UUUUUUS9$ )aM  solve for any one parameter of the power of a F-test

for the one sample F-test the keywords are:
    effect_size, df_num, df_denom, alpha, power

Exactly one needs to be ``None``, all others need numeric values.

The effect size is Cohen's ``f``, square root of ``f2``.

The sample size is given by ``nobs = df_denom + df_num + ncc``.

Warning: The meaning of df_num and df_denom is reversed.

Parameters
----------
effect_size : float
    Standardized effect size. The effect size is here Cohen's ``f``,
    square root of ``f2``.
df_num : int or float
    Warning incorrect name
    denominator degrees of freedom,
    This corresponds to the number of constraints in Wald tests.
    Sample size is given by ``nobs = df_denom + df_num + ncc``
df_denom : int or float
    Warning incorrect name
    numerator degrees of freedom.
    This corresponds to the df_resid in Wald tests.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
ncc : int
    degrees of freedom correction for non-centrality parameter.
    see Notes
kwargs : empty
    ``kwargs`` are not used and included for backwards compatibility.
    If ``nobs`` is used as keyword, then a warning is issued. All
    other keywords in ``kwargs`` raise a ValueError.

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The method uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

r8   znobs is not usedzincorrect keyword(s) r7   rZ   r[   r9   rR   r`   )r   r   r.   r   r   )	ry   r7   rZ   r[   r9   rR   r`   kwargsr   s	           r   r   FTestPower.solve_power'  sY    z 01 #8!ABBw"{=C?G<A<A:= # ? 	?r   r   r   NNNNNr   r   r   s   @r   r  r    s%    (T2j CG01G? G?r   r  c                   >   ^  \ rS rSrSrSS jr  SU 4S jjrSrU =r$ )FTestPowerF2ir  a:  Statistical Power calculations for generic F-test of a constraint

This is based on Cohen's f^2 as effect size measure.

Examples
--------
Sample size and power for multiple regression base on R-squared

Compute effect size from R-squared

>>> r2 = 0.1
>>> f2 = r2 / (1 - r2)
>>> f = np.sqrt(f2)
>>> r2, f2, f
(0.1, 0.11111111111111112, 0.33333333333333337)

Find sample size by solving for denominator degrees of freedom.

>>> df1 = 1  # number of constraints in hypothesis test
>>> df2 = FTestPowerF2().solve_power(effect_size=f2, alpha=0.1, power=0.9,
                                     df_num=df1)
>>> ncc = 1  # default
>>> nobs = df2 + df1 + ncc
>>> df2, nobs
(76.46459758305376, 78.46459758305376)

verify power at df2

>>> FTestPowerF2().power(effect_size=f, alpha=0.1, df_num=df1, df_denom=df2)
0.8999999972109698

c                     [        XX4US9nU$ )aC  Calculate the power of a F-test.

The effect size is Cohen's ``f^2``.

The sample size is given by ``nobs = df_denom + df_num + ncc``

Parameters
----------
effect_size : float
    The effect size is here Cohen's ``f2``. This is equal to
    the noncentrality of an F-test divided by nobs.
df_num : int or float
    Numerator degrees of freedom,
    This corresponds to the number of constraints in Wald tests.
df_denom : int or float
    Denominator degrees of freedom.
    This corresponds to the df_resid in Wald tests.
alpha : float in interval (0,1)
    Significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ncc : int
    Degrees of freedom correction for non-centrality parameter.
    see Notes

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

Notes
-----
The sample size is given implicitly by df_denom

set ncc=0 to match t-test, or f-test in LikelihoodModelResults.
ncc=1 matches the non-centrality parameter in R::pwr::pwr.f2.test

ftest_power with ncc=0 should also be correct for f_test in regression
models, with df_num and d_denom as defined there. (not verified yet)
r	  )rc   r
  s          r   rR   FTestPowerF2.power  s    V k8Lr   c           	      (   > [         TU ]  UUUUUUS9$ )a  Solve for any one parameter of the power of a F-test

for the one sample F-test the keywords are:
    effect_size, df_num, df_denom, alpha, power

Exactly one needs to be ``None``, all others need numeric values.

The effect size is Cohen's ``f2``.

The sample size is given by ``nobs = df_denom + df_num + ncc``, and
can be found by solving for df_denom.

Parameters
----------
effect_size : float
    The effect size is here Cohen's ``f2``. This is equal to
    the noncentrality of an F-test divided by nobs.
df_num : int or float
    Numerator degrees of freedom,
    This corresponds to the number of constraints in Wald tests.
df_denom : int or float
    Denominator degrees of freedom.
    This corresponds to the df_resid in Wald tests.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
ncc : int
    degrees of freedom correction for non-centrality parameter.
    see Notes

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

r  r   )ry   r7   rZ   r[   r9   rR   r`   r   s          r   r   FTestPowerF2.solve_power  s.    l w"{=C?G<A<A:= # ? 	?r   r   r  r  r   r   s   @r   r  r  r  s#    B,^ CG01;? ;?r   r  c                   L   ^  \ rS rSrSrSS jr  SU 4S jjr  SS jrSrU =r	$ )	FTestAnovaPoweri  zStatistical Power calculations F-test for one factor balanced ANOVA

This is based on Cohen's f as effect size measure.

See Also
--------
statsmodels.stats.oneway.effectsize_oneway

c                     [        XX4S9$ )a  Calculate the power of a F-test for one factor ANOVA.

Parameters
----------
effect_size : float
    standardized effect size. The effect size is here Cohen's f, square
    root of "f2".
nobs : int or float
    sample size, number of observations.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
k_groups : int or float
    number of groups in the ANOVA or k-sample comparison. Default is 2.

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

)rY   )r\   )ry   r7   r8   r9   rY   s        r   rR   FTestAnovaPower.power  s    0 !EMMr   c                    > Ub/  US-  U R                   S'   [        US-  US-  S9U R                  S'   Uc  U R                  UUUUUS9$ [        TU ]  UUUUUS9$ )aT  solve for any one parameter of the power of a F-test

for the one sample F-test the keywords are:
    effect_size, nobs, alpha, power

Exactly one needs to be ``None``, all others need numeric values.


Parameters
----------
effect_size : float
    standardized effect size, mean divided by the standard deviation.
    effect size has to be positive.
nobs : int or float
    sample size, number of observations.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

rg   r8   rP   rl   r7   r8   r9   rY   rR   )rv   ru   rx   _solve_effect_sizer   r   )ry   r7   r8   r9   rR   rY   r   s         r   r   FTestAnovaPower.solve_power'  s    V %-]DNN6"'+16>m(EDV$ **{04164<16	 + 8 8 w"{;?<A?G<A	 # C 	Cr   c                    ^ ^^^^ UUUUU 4S jn[         R                  " USSSS9u  pxUR                  (       d  [        U5        U$ )zBexperimental, test failure in solve_power for effect_size
        c                 .   > U nTR                  UTTTTS9$ )Nr  )r   )r   r7   r9   rY   r8   rR   ry   s     r   r   0FTestAnovaPower._solve_effect_size.<locals>.funch  s.    K''K/3053;05	 ( 7 7r   rp   r   Tr   )r   r   r   print)	ry   r7   r8   r9   rR   rY   r   r   r   s	   ` ````   r   r  "FTestAnovaPower._solve_effect_sized  s8    	7 	7 tVF{{!H
r   r   )rP   NNNNrP   )
r   r   r   r   r   rR   r   r  r   r   r   s   @r   r  r    s3    N6 JN;Cz EI01 r   r  c                   >   ^  \ rS rSrSrSS jr  SU 4S jjrSrU =r$ )GofChisquarePoweriv  zBStatistical Power calculations for one sample chisquare test

    c                     SSK Jn  U" XXCSS9$ )a  Calculate the power of a chisquare test for one sample

Only two-sided alternative is implemented

Parameters
----------
effect_size : float
    standardized effect size, according to Cohen's definition.
    see :func:`statsmodels.stats.gof.chisquare_effectsize`
nobs : int or float
    sample size, number of observations.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
n_bins : int
    number of bins or cells in the distribution.

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

r   chisquare_powerr  statsmodels.stats.gofr*  )ry   r7   r8   r9   n_binsr   r*  s          r   rR   GofChisquarePower.power{  s    4 	:{&aHHr   c                 &   > [         TU ]  UUUUUS9$ )a  solve for any one parameter of the power of a one sample chisquare-test

for the one sample chisquare-test the keywords are:
    effect_size, nobs, alpha, power

Exactly one needs to be ``None``, all others need numeric values.

n_bins needs to be defined, a default=2 is used.


Parameters
----------
effect_size : float
    standardized effect size, according to Cohen's definition.
    see :func:`statsmodels.stats.gof.chisquare_effectsize`
nobs : int or float
    sample size, number of observations.
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
n_bins : int
    number of bins or cells in the distribution

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

)r7   r8   r-  r9   rR   r   )ry   r7   r8   r9   rR   r-  r   s         r   r   GofChisquarePower.solve_power  s-    \ w"{;?=C<A<A	 # C 	Cr   r   r  r%  r   r   s   @r   r'  r'  v  s#    I< >B'(2C 2Cr   r'  c                   B   ^  \ rS rSrSr  SS jr  SU 4S jjrSrU =r$ )_GofChisquareIndPoweri  zStatistical Power calculations for chisquare goodness-of-fit test

TODO: this is not working yet
      for 2sample case need two nobs in function
      no one-sided chisquare test, is there one? use normal distribution?
      -> drop one-sided options?
c                 D    SSK Jn  X$-  nSSU-  SU-  -   -  nU" XU5      $ )a  Calculate the power of a chisquare for two independent sample

Parameters
----------
effect_size : float
    standardize effect size, difference between the two means divided
    by the standard deviation. effect size has to be positive.
nobs1 : int or float
    number of observations of sample 1. The number of observations of
    sample two is ratio times the size of sample 1,
    i.e. ``nobs2 = nobs1 * ratio``
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
ratio : float
    ratio of the number of observations in sample 2 relative to
    sample 1. see description of nobs1
    The default for ratio is 1; to solve for ration given the other
    arguments it has to be explicitely set to None.
alternative : str, 'two-sided' (default) or 'one-sided'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test.
    'one-sided' assumes we are in the relevant tail.

Returns
-------
power : float
    Power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.

r   r)  ro   r+  )	ry   r7   ri   r9   rj   r:   r*  r   r8   s	            r   rR   _GofChisquareIndPower.power  s3    F 	:BJe+,{%88r   c           	      (   > [         TU ]  UUUUUUS9$ )a  solve for any one parameter of the power of a two sample z-test

for z-test the keywords are:
    effect_size, nobs1, alpha, power, ratio

exactly one needs to be ``None``, all others need numeric values

Parameters
----------
effect_size : float
    standardize effect size, difference between the two means divided
    by the standard deviation.
nobs1 : int or float
    number of observations of sample 1. The number of observations of
    sample two is ratio times the size of sample 1,
    i.e. ``nobs2 = nobs1 * ratio``
alpha : float in interval (0,1)
    significance level, e.g. 0.05, is the probability of a type I
    error, that is wrong rejections if the Null Hypothesis is true.
power : float in interval (0,1)
    power of the test, e.g. 0.8, is one minus the probability of a
    type II error. Power is the probability that the test correctly
    rejects the Null Hypothesis if the Alternative Hypothesis is true.
ratio : float
    ratio of the number of observations in sample 2 relative to
    sample 1. see description of nobs1
    The default for ratio is 1; to solve for ration given the other
    arguments it has to be explicitely set to None.
alternative : str, 'two-sided' (default) or 'one-sided'
    extra argument to choose whether the power is calculated for a
    two-sided (default) or one sided test.
    'one-sided' assumes we are in the relevant tail.

Returns
-------
value : float
    The value of the parameter that was set to None in the call. The
    value solves the power equation given the remaining parameters.


Notes
-----
The function uses scipy.optimize for finding the value that satisfies
the power equation. It first uses ``brentq`` with a prior search for
bounds. If this fails to find a root, ``fsolve`` is used. If ``fsolve``
also fails, then, for ``alpha``, ``power`` and ``effect_size``,
``brentq`` with fixed bounds is used. However, there can still be cases
where this fails.

r   r   r   s          r   r   !_GofChisquareIndPower.solve_power  r   r   r   r  r   r   r   s   @r   r2  r2    s,     67%'9T KO*59O 9Or   r2  r   )r%   ro   )ro   Nr%   )ro   N)rP   Nr  )#r   r   numpyr1   scipyr   r   r   statsmodels.tools.rootfindingr   r   r   r   r   r"   r@   rH   rN   rU   r\   ra   rc   re   r   r   r   r  r  r  r'  r2  r   tt_solve_powertt_ind_solve_powerzt_ind_solve_powerr   r   r   <module>r=     s+  <   * * :%)+/,#L'T FJ(6r >@040f2j:@s slhO hOTqOE qOfwOU wOtg? g?VL?5 L?^re rjUC UCnmOE mO` ))"_00 #%11 r   