Owen’s Q implementation issues [Power / Sample Size]
Dear Ben,
These discrepancies may be due to not at least hidden bugs! They are too great in magnitude to be simply the result of rounding errors.
I have implemented the evaluation of the distinct integral the Q-function is based on for simplicity and in analogy to the function
To check my implementation in package
Using the calls that results if one tries to compute the power for T/R=1, CV=7.5% and n=4 the following results are obtained:
Boing! Totally consistence of the values from both implementations
.
(Red is rounding to the results from the call of
The same coincidence is observed with T/R=1, CV=7.5% and n=6 with power=0.9869919 via
The deduction in which software there is eventually a bug or a flawed implementation is left to you
.
BTW:
❝ First, there still are some discrepancies, e.g. in case of T/R=1, CV=7.5% (see e.g. #4266): for n=4 power.TOST "exact" gives 0.7290143 whereas nQuery gives 0.71559 (for n=6: 0.9869919 vs. 0.97943). I guess it's just not the same exact method that is implemented? (rounding?)
These discrepancies may be due to not at least hidden bugs! They are too great in magnitude to be simply the result of rounding errors.
I have implemented the evaluation of the distinct integral the Q-function is based on for simplicity and in analogy to the function
power.equivalence.md()
of package MBESS
using the R-function integrate()
from package stats
. This is a little bit "black box programming" because I have no precise idea what integrate()
really does and if there are circumstances where it can fail like all numeric integration routines.To check my implementation in package
PowerTOST
I have coded the algorithm given by Owen itself (repeated integration by parts) in a function OwensQOwen()
.Using the calls that results if one tries to compute the power for T/R=1, CV=7.5% and n=4 the following results are obtained:
df=2
tvalue= 2.919986
delta1= 4.213542
delta2= -4.213542
R= 2.040712
p1 <- OwensQ(df, +tvalue, delta1, 0, R) # PowerTOST implementation
p2 <- OwensQ(df, -tvalue, delta2, 0, R)
power <- p2 - p1
-- gives
p1= 0.07316842
p2= 0.8021825
power = 0.7290141
p1 <- OwensQOwen(df, +tvalue, delta1, 0, R) #Owen's integration by parts
p2 <- OwensQOwen(df, -tvalue, delta2, 0, R)
power <- p2 - p1
-- gives
p1= 0.07316842
p2= 0.8021825
power = 0.7290141
Boing! Totally consistence of the values from both implementations

(Red is rounding to the results from the call of
power.TOST()
with full internal precision of tvalue, delta1, delta2 and R).The same coincidence is observed with T/R=1, CV=7.5% and n=6 with power=0.9869919 via
OwensQOwen()
.The deduction in which software there is eventually a bug or a flawed implementation is left to you

BTW:
OwensQOwen()
code is available upon request.—
Regards,
Detlew
Regards,
Detlew
Complete thread:
- Exact and approximate method Ben 2012-03-02 15:12 [Power / Sample Size]
- Sorry for the confusion caused Helmut 2012-03-02 17:21
- Thanks for clarifying Ben 2012-03-02 18:14
- Owen’s Q (Anders, are you there?) Helmut 2012-03-02 19:38
- Owen’s Q Ben 2012-03-03 13:35
- Exact or not, that‘s the question Helmut 2012-03-03 15:34
- Owen’s Q implementation issuesd_labes 2012-03-13 12:01
- Owen’s Q implementation issues Ben 2012-03-13 21:52
- Owen’s Q Ben 2012-03-03 13:35
- Owen’s Q (Anders, are you there?) Helmut 2012-03-02 19:38
- Sorry for the confusion caused ElMaestro 2012-03-04 21:56
- Sorry for the confusion caused Helmut 2012-03-05 01:57
- AS 184 without wasting bucks d_labes 2012-03-05 15:28
- Thanks for clarifying Ben 2012-03-02 18:14
- PowerTOST_0.9-4 on CRAN now d_labes 2012-03-05 15:17
- Sorry for the confusion caused Helmut 2012-03-02 17:21