power
Power and sample size of the two one-sided tests procedure.
The question a bioequivalence study asks after it ran is whether the 90 %
interval of the geometric mean ratio lies within the acceptance limits
(pkpdutils.stats.bioequivalence); the question it has to answer before it
runs is how many subjects that decision needs. Both are the same procedure:
power_tost is the probability that the two one-sided tests of Schuirmann
(1987) both reject at the assumed ratio and the assumed within-subject
variability, and sample_size_tost is the smallest number of subjects which
reaches a target power.
The power is exact, not simulated: under the normal model of the log values the two test statistics are a bivariate non-central t pair, whose probability is Owen's Q function (Owen 1965),
evaluated here by numerical integration (scipy.integrate.quad) of the
logarithm of the integrand, which is the algorithm of the R package
PowerTOST (Labes, Schuetz & Lang). The design enters through the constant
\(b_k\) of the standard error and the degrees of freedom, both taken from
PowerTOST: a 2x2 crossover has \(b_k = 2\) and \(\nu = n - 2\), two parallel
groups \(b_k = 4\) and \(\nu = n - 2\), the four period full replicate
(TRTR/RTRT) \(b_k = 1\) and \(\nu = 3n - 4\) and the three period replicate
(TRT/RTR) \(b_k = 1.5\) and \(\nu = 2n - 3\), with \(n\) the total number of
subjects of the study.
TOSTDesign
dataclass
¶
A study design of the power calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
the name of the design, as |
bk |
float
|
the design constant of the standard error, \(\mathrm{se} = \sigma\sqrt{b_k/n}\) |
df_factor |
float
|
factor of the degrees of freedom, \(\nu = a n + b\) |
df_offset |
float
|
offset of the degrees of freedom |
step |
int
|
the step of the sample size search, 2 for a design whose sequences have to carry the same number of subjects |
description |
str
|
how the design is spelled out in a report |
df
¶
The degrees of freedom of a study of n subjects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
the total number of subjects. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The degrees of freedom of the residual. |
se
¶
The standard error of the log ratio of a study of n subjects.
The design is assumed to have two sequences (or two groups) of \(n_1 = \lceil n/2 \rceil\) and \(n_2 = \lfloor n/2 \rfloor\) subjects,
which is \(\sigma\sqrt{b_k/n}\) for an even n and the standard error
of the study with one subject more in one sequence for an odd one.
\(b_{k,ni}\) is the unbalanced design constant of PowerTOST
(known.designs(): ½, 1, ¼ and ⅜ for the four designs here),
which is a quarter of \(b_k\) in every one of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma
|
float
|
the standard deviation of the log values. |
required |
n
|
int
|
the total number of subjects. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The standard error. |
owens_q
¶
Owen's Q function, by numerical integration of the log integrand.
(Owen 1965), the probability of the bivariate non-central t pair the two
one-sided tests form. \(Q_\nu(t, \delta; 0, \infty)\) is the distribution
function of the non-central t distribution at t with the non-centrality
\(\delta\), which is the regression test of this function. The integrand
is evaluated as \(\exp((\nu-1)\ln x - x^2/2 - \ln\Gamma(\nu/2) -
\frac{\nu-2}{2}\ln 2)\,\Phi(\cdot)\), so that neither \(x^{\nu-1}\) nor
\(\Gamma(\nu/2)\) overflows for the large degrees of freedom of a big
study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nu
|
float
|
degrees of freedom, positive. |
required |
t
|
float
|
the argument of the normal distribution function. |
required |
delta
|
float
|
the non-centrality. |
required |
a
|
float
|
lower bound of the integral, non-negative. |
required |
b
|
float
|
upper bound of the integral. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The value of the integral, |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
power_tost
¶
The exact power of the two one-sided tests procedure.
With \(\sigma = \sqrt{\ln(1 + \mathrm{CV}^2)}\) the standard deviation of the log values, \(\mathrm{se} = \sigma\sqrt{b_k/n}\) the standard error of the log ratio of the design, \(\Delta = \ln \mathrm{GMR}\) and the log limits \(\ln\theta_L\), \(\ln\theta_U\), the two non-centralities are
and with \(t = t_{1-\alpha,\nu}\) and \(R = (\delta_1 - \delta_2)\sqrt{\nu} / (2t)\) the power is the difference of two Owen's Q values,
the exact probability that both one-sided tests reject (Owen 1965; the
algorithm of PowerTOST::power.TOST). An odd n is split into the two
sequences (or groups) of \(\lceil n/2 \rceil\) and \(\lfloor n/2 \rfloor\)
subjects the study would have, which widens the standard error a little
against the balanced formula, as PowerTOST does for a dropout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cv
|
float
|
the within-subject coefficient of variation as a fraction (the total CV for a parallel design), 0.3 for 30 %. |
required |
n
|
int
|
the total number of subjects of the study. |
required |
gmr
|
float
|
the geometric mean ratio the study is powered for; 0.95 is the usual assumption of a 5 % difference of the formulations. |
0.95
|
limits
|
tuple[float, float]
|
the acceptance limits of the ratio. |
(0.8, 1.25)
|
design
|
DesignName | str
|
the design, one of |
'2x2'
|
alpha
|
float
|
the level of each one-sided test, 0.05 for a 90 % interval. |
0.05
|
Returns:
| Type | Description |
|---|---|
float
|
The power, a probability. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an unknown design, a negative |
sample_size_tost
¶
sample_size_tost(
*,
cv,
gmr=0.95,
target_power=0.8,
design="2x2",
alpha=0.05,
limits=(0.8, 1.25),
max_n=100000,
)
The smallest number of subjects which reaches a target power.
The search walks the sample size upwards from a lower bound derived from
the normal approximation and returns the first size whose power_tost
reaches target_power. A crossover is searched in steps of two, so that
the sequences carry the same number of subjects, and starts at four; a
parallel design is searched in steps of one and starts at three. The
number returned is the total number of subjects of the study, not the
number per sequence or per group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cv
|
float
|
the within-subject coefficient of variation as a fraction (the total CV for a parallel design). |
required |
gmr
|
float
|
the geometric mean ratio the study is powered for. |
0.95
|
target_power
|
float
|
the power to reach, 0.8 or 0.9 in practice. |
0.8
|
design
|
DesignName | str
|
the design, one of |
'2x2'
|
alpha
|
float
|
the level of each one-sided test. |
0.05
|
limits
|
tuple[float, float]
|
the acceptance limits of the ratio. |
(0.8, 1.25)
|
max_n
|
int
|
the largest sample size the search looks at. |
100000
|
Returns:
| Type | Description |
|---|---|
int
|
The total number of subjects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
for an unknown design, a |