statsmodels.stats.power.TTestIndPower.solve_power#
- TTestIndPower.solve_power(effect_size=None, nobs1=None, alpha=None, power=None, ratio=1.0, alternative='two-sided')[source]#
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
Noneorfloat standardized effect size, difference between the two means divided by the standard deviation. effect_size has to be positive.
- nobs1
Noneorintorfloat 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
Noneorfloatininterval(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
Noneorfloatininterval(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
Noneorfloat,optional ratio of the number of observations in sample 2 relative to sample 1. see description of nobs1.
ratiomust be non-negative and not NaN.ratiocan be set to zero in order to get the power of the one sample t-test withnobs1observations (df = nobs1 - 1). This is a convention and not the limit ofratiogoing to zero: a ratio close to zero, e.g.1e-9, means that sample 2 has almost no observations and the power is close to alpha. The default for ratio is 1; to solve for ratio given the other arguments it has to be explicitly set to None.- alternative{‘two-sided’, ‘larger’, ‘smaller’},
optional 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’.
- effect_size
- 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.
- value
- Raises:
ValueErrorIf
ratiois negative or NaN.
Notes
The function uses scipy.optimize for finding the value that satisfies the power equation. It first uses
brentqwith a prior search for bounds. If this fails to find a root,fsolveis used. Iffsolvealso fails, then, foralpha,powerandeffect_size,brentqwith fixed bounds is used. If these also fail to find a solution of the power equation, for example because it has no solution, aConvergenceWarningis issued andnanis returned.Changed in version 0.15.1:
ratio=0solves the power equation of the one sample t-test, it used to raise aZeroDivisionErroror to give wrong results. A negative or NaNratioraises aValueError, it used to return nan with aConvergenceWarning.