> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.3, alpha=0.05, logscale=TRUE, design="parallel", method="owenq", n=31)
Unbalanced design. n(i)=16/15 assumed.
[1] 0.2949476
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.3, alpha=0.05, logscale=TRUE, design="parallel", method="owenq", n=32)
[1] 0.3166927
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x2x4", method="owenq", n=35)
Unbalanced design. n(i)=18/17 assumed.
[1] 0.829747
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x4x4", method="owenq", n=35)
Unbalanced design. n(i)=9/9/9/8 assumed.
[1] 0.8291076
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x4x4", method="owenq", n=34)
Unbalanced design. n(i)=9/9/8/8 assumed.
[1] 0.8180596
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x4x4", method="owenq", n=33)
Unbalanced design. n(i)=9/8/8/8 assumed.
[1] 0.8069565
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x4x4", method="owenq", n=32)
[1] 0.7958094
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x2x3", method="owenq", n=31)
Unbalanced design. n(i)=16/15 assumed.
[1] 0.5800205
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x2x3", method="owenq", n=32)
[1] 0.5988065
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x3x3", method="owenq", n=32)
Unbalanced design. n(i)=11/11/10 assumed.
[1] 0.5976873
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x3x3", method="owenq", n=31)
Unbalanced design. n(i)=11/10/10 assumed.
[1] 0.579468
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x3x3", method="owenq", n=30)
[1] 0.5614358
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="3x3", method="owenq", n=30)
[1] 0.3847067
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="3x6x3", method="owenq", n=30)
[1] 0.3847067
> power.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, logscale=TRUE, design="2x4x2", method="owenq", n=30)
Unbalanced design. n(i)=8/8/7/7 assumed.
[1] 0.0001785665
------------------------------------------------------------------------------------------------------------

ClinicalTrialUtilities.oneSampleMeanEqualityP(1.5,2,1,32;alpha=0.05)
0.8074304194325561
ClinicalTrialUtilities.oneSampleMeanEquivalenceP(2, 2, 0.1, 0.05, 35; alpha=0.05)
0.8108839754376387
ClinicalTrialUtilities.oneSampleMeanNSP(1.5, 2, 1, -.5, 7; alpha=0.05)
0.8415707712023641
ClinicalTrialUtilities.twoSampleMeanEqualityP(5, 10, 10, 63; alpha=0.05, k=1)
0.8013023941055788
ClinicalTrialUtilities.twoSampleMeanEquivalenceP(5, 4, 10, 5,  108; alpha=0.05, k=1)
0.80452354556060
ClinicalTrialUtilities.twoSampleMeanNSP(5, 5, 10, 5, 50; alpha=0.05, k=1)
0.8037819415575257
ClinicalTrialUtilities.oneProportionEqualityP(0.3, 0.5, 50; alpha=0.05)
0.8074304194325561
ClinicalTrialUtilities.oneProportionEquivalenceP(0.6, 0.6, 0.2, 52; alpha=0.05)
0.8060834056011101
ClinicalTrialUtilities.oneProportionNSP(0.3, 0.5, -0.1, 18; alpha=0.05)
0.8161481827204281
ClinicalTrialUtilities.twoProportionEqualityP(0.65, 0.85, 70; alpha=0.05, k=1)
0.8019139068528
ClinicalTrialUtilities.twoProportionEquivalenceP(0.65, 0.85, 0.05, 136; alpha=0.05, k=1)
0.8033294052407269
ClinicalTrialUtilities.twoProportionNSP(0.85, 0.65, -0.1, 25; alpha=0.05, k=1)
0.808599833380679
ClinicalTrialUtilities.orEqualityP(0.4, 0.25, 156; alpha=0.05, k=1)
0.8020239054864792
ClinicalTrialUtilities.orEquivalenceP(0.25, 0.25, 0.5, 366; alpha=0.05, k=1, logdiff=true)
0.8008593380478983
ClinicalTrialUtilities.orNSP(0.4, 0.25, 0.2, 242; alpha=0.05, k=1, logdiff=true)
0.8007200876001626

[1] 22.80907 / [1] 0.9023805
--------------------------------------------------------------------------------
tfn

R Project
1, 2 = 0.07846821
2, 1 = 0.01111628
0, 10 = 0.2341222
0, 100 = 0.2342008
20, 20 = 0
15, 15 =  1.835484e-51
-10,15 = 3.809928e-24
-0.1, 150 = 0.2382264
-5, Inf = Error
Inf, Inf = 0
1.0E-5, -1 = -0.125
1.0E-10, -10 = -0.2341222
-Inf, Inf = 0

                        owensT

> OwensT (1, Inf)
[1] 0.07932763
> OwensT (-1, Inf)
[1] 0.07932763
> OwensT (-1, -Inf)
[1] -0.07932763
> OwensT (1, -Inf)
[1] -0.07932763
> OwensT (1, 0.5)
[1] 0.0430647
> OwensQ (nu=1,t=1,delta=1,b=Inf,a=0)
[1] 0.42202
> OwensQ (nu=1,t=100,delta=40,b=Inf,a=0)
[1] 0.6891712
> OwensQ (nu=1,t=100,delta=40,b=1,a=0)
[1] 0.3718607
> OwensQOwen (nu=4,t=2,delta=1,b=1,a=0)
[1] 0.03739024
> OwensQOwen (nu=7,t=2,delta=1,b=1,a=0)
[1] 0.001888241


julia> ClinicalTrialUtilities.owensT(1,2)
0.07846818535354307
> OwensT (1,2)
[1] 0.07846819

julia> ClinicalTrialUtilities.owensT(2,2)
0.011374908790171596
> OwensT (2,2)
[1] 0.01137491

julia> ClinicalTrialUtilities.owensT(20,2)
0.0
> OwensT (20,2)
[1] 0

julia> ClinicalTrialUtilities.owensT(-0.01,2)
0.17619226214926362
> OwensT (-0.01,2)
[1] 0.1761923

julia> ClinicalTrialUtilities.owensT(-0.01,20)
0.24189025023372523
> OwensT (-0.01,20)
[1] 0.2418903

julia> ClinicalTrialUtilities.owensT(-0.01,200)
0.24798838649952515
> OwensT (-0.01,200)
[1] 0.2479884

julia> ClinicalTrialUtilities.owensT(-1.0E-10,200)
0.24920423175674383
> OwensT (-1.0E-10,200)
[1] 0.2492042

julia> ClinicalTrialUtilities.owensT(5,30)
1.4332578601727874e-7
> OwensT (5,30)
[1] 1.433258e-07

julia> ClinicalTrialUtilities.owensT(-6, -40)
-4.93293822518849e-10
> OwensT (-6,-40)
[1] -4.932938e-10

julia> ClinicalTrialUtilities.owensT(-11, 57)
9.553297872493378e-29
> OwensT (-11, 57)
[1] 9.553298e-29

julia> ClinicalTrialUtilities.owensT(11, 57)
0.0
> OwensT (11, 57)
[1] 0
---------------------------------------------------

                                owensQo

> OwensQOwen (nu=1,t=2,delta=1,b=1,a=0)
[1] 0.321429
> OwensQOwen (nu=3,t=2,delta=1,b=Inf,a=0)
[1] 0.7436299

> OwensQOwen (nu=2, t=1, delta=0.5, a=0, b=0.2)
[1] 0.006781741
julia> ClinicalTrialUtilities.owensQo(2,1,0.5,0.2;a=0)
0.006781740849793494

> OwensQOwen (nu=3, t=1, delta=0.5, a=0, b=0.2)
[1] 0.0007140675
julia> ClinicalTrialUtilities.owensQo(3,1,0.5,0.2;a=0)
0.000714067462717051

> OwensQOwen (nu=4, t=1, delta=0.5, a=0, b=0.2)
[1] 6.655454e-05
julia> ClinicalTrialUtilities.owensQo(4,1,0.5,0.2;a=0)
6.655453722681504e-5

> OwensQOwen (nu=3, t=5, delta=0.5, a=0, b=0.2)
[1] 0.0009950627
julia> ClinicalTrialUtilities.owensQo(3,5,0.5,0.2;a=0)
0.000995062742377012

> OwensQOwen (nu=3, t=5, delta=0.7, a=0, b=0.2)
[1] 0.0008309063
julia> ClinicalTrialUtilities.owensQo(3,5,0.7,0.2;a=0)
0.0008309062844733539

> OwensQOwen (nu=3, t=5, delta=0.7, a=0, b=0.5)
[1] 0.01978927
julia> ClinicalTrialUtilities.owensQo(3,5,0.7,0.5;a=0)
0.01978927435750341

> OwensQOwen (nu=3, t=5, delta=0.7, a=0, b=0.75)
[1] 0.0755257
julia> ClinicalTrialUtilities.owensQo(3,5,0.7,0.75;a=0)
0.07552570026416983

> OwensQOwen (nu=3, t=5, delta=0.9, a=0, b=0.75)
[1] 0.07026852
julia> ClinicalTrialUtilities.owensQo(3,5,0.9,0.75;a=0)
0.07026852130848105

> OwensQOwen (nu=3, t=20, delta=0.9, a=0, b=0.75)
[1] 0.09443499
julia> ClinicalTrialUtilities.owensQo(3,20,0.9,0.75;a=0)
0.09443499306279901
------------------------------------------------------
> OwensQOwen (nu=4, t=20, delta=0.9, a=0, b=0.75)
[1] 0.03276002
julia> ClinicalTrialUtilities.owensQo(4,20,0.9,0.75;a=0)
0.032760015173071005

> OwensQOwen (nu=5, t=20, delta=0.9, a=0, b=0.75)
[1] 0.01032483
julia> ClinicalTrialUtilities.owensQo(5,20,0.9,0.75;a=0)
0.010324834612567557

> OwensQOwen (nu=6, t=20, delta=0.9, a=0, b=0.75)
[1] 0.003003187
julia> ClinicalTrialUtilities.owensQo(6,20,0.9,0.75;a=0)
0.0030031866986452715

> OwensQOwen (nu=9, t=1, delta=0.5, a=0, b=0.2)
[1] 2.186626e-11
julia> ClinicalTrialUtilities.owensQo(9,1,0.5,0.2;a=0)
2.1866258803626692e-11

> OwensQOwen (nu=9, t=-100, delta=2, a=0, b=0.01)
[1] 1.330372e-10
julia> ClinicalTrialUtilities.owensQo(9,-100,2,0.01;a=0)
1.3303723002248448e-10

-------------------------------------------------------------------

julia> ClinicalTrialUtilities.owensTint2(1, 3, 20, 3)
0.4839414490382867
> .Q.integrand (x=1, nu=3, t=20, delta=3)
[1] 0.4839414


> OwensQ (nu=4, t=100, delta=40, a=0, b=Inf)
[1] 0.9584071
julia> ClinicalTrialUtilities.owensQ(4,100,40,0,Inf)
0.9584070994785919

> OwensQ (nu=4, t=100, delta=30, a=0, b=Inf)
[1] 0.9855395
julia> ClinicalTrialUtilities.owensQ(4,100,30,0,Inf)
0.9855394838428024

> OwensQ (nu=4, t=100, delta=40, a=0, b=0.8)
[1] 0.001429002
julia> ClinicalTrialUtilities.owensQ(4,100,40,0,0.8)
0.0014290018033243632

> OwensQ (nu=4, t=100, delta=30, a=0, b=0.8)
[1] 0.02702275
julia> ClinicalTrialUtilities.owensQ(4,100,30,0,0.8)
0.027022754905530633

> .power.TOST (alpha=0.05, ltheta1=0.1, ltheta2=0.4, diffm=0.05, sem=0.11, df=23)
[1] 0.00147511
julia> ClinicalTrialUtilities.powerTOSTOwenQ(0.05,0.1,0.4,0.05,0.11,23)
0.0014751101803128774

julia> ClinicalTrialUtilities.approxPowerTOST(0.05,0.4,0.9,0.05,0.11,23)
1.0769643498109716e-6
> .approx.power.TOST (alpha=0.05, ltheta1=0.4, ltheta2=0.9, diffm=0.05, sem=0.11, df=23)
[1] 1.076964e-06

julia> ClinicalTrialUtilities.approxPowerTOST(0.05,0.1,0.9,0.05,0.11,23)
0.018475943647805915
> .approx.power.TOST (alpha=0.05, ltheta1=0.1, ltheta2=0.9, diffm=0.05, sem=0.11, df=23)
[1] 0.01847594

> .approx.power.TOST (alpha=0.05, ltheta1=0.1, ltheta2=1.0, diffm=0.5, sem=0.2, df=1000)
[1] 0.4415495
julia> ClinicalTrialUtilities.approxPowerTOST(0.05,0.1,1.0,0.5,0.2,1000)
0.4415495199129315

julia> ClinicalTrialUtilities.approxPowerTOST(0.05,1.0,1.0,0.5,0.2,100)
0
> .approx.power.TOST (alpha=0.05, ltheta1=1.0, ltheta2=1.0, diffm=0.5, sem=0.2, df=100)
[1] 0

> .approx2.power.TOST (alpha=0.05, ltheta1=0.1, ltheta2=1.0, diffm=0.5, sem=0.2, df=1000)
[1] 0.4413917
> .approx2.power.TOST (alpha=0.05, ltheta1=1.0, ltheta2=1.0, diffm=0.5, sem=0.2, df=100)
[1] 0

julia> ClinicalTrialUtilities.approx2PowerTOST(0.05,1.0,1.0,0.5,0.2,100)
0
julia> ClinicalTrialUtilities.approx2PowerTOST(0.05,0.1,1.0,0.5,0.2,1000)
0.4413916615556126

> power.TOST(alpha=0.05, logscale=TRUE, theta1=0.8, theta2=1.25, theta0=0.95, CV=0.2, n=20, design="2x2", method="owenq")
[1] 0.8346802
julia> ClinicalTrialUtilities.powerTOST(alpha=0.05, logscale=true, theta1=0.8, theta2=1.25, theta0=0.95, cv=0.2, n=20, design="2x2", method="owenq")
0.8346801908570283

> power.TOST(alpha=0.05, logscale=TRUE, theta1=0.8, theta2=1.25, theta0=0.95, CV=0.2, n=100, design="2x2", method="owenq")
[1] 0.9999957
julia> ClinicalTrialUtilities.powerTOST(alpha=0.05, logscale=true, theta1=0.8, theta2=1.25, theta0=0.95, cv=0.2, n=100, design="2x2", method="owenq")
0.9999956683139025

> power.TOST(alpha=0.05, logscale=TRUE, theta1=0.8, theta2=1.25, theta0=0.95, CV=0.2, n=10, design="2x2", method="nct")
[1] 0.4316618
julia> ClinicalTrialUtilities.powerTOST(alpha=0.05, logscale=true, theta1=0.8, theta2=1.25, theta0=0.95, cv=0.2, n=10, design="2x2", method="nct")
0.4316618202249526

> power.TOST(alpha=0.05, logscale=FALSE, theta1=-0.1, theta2=0.1, theta0=0, CV=0.14, n=30, design="2x2", method="nct")
[1] 0.7079951
julia> ClinicalTrialUtilities.powerTOST(alpha=0.05, logscale=false, theta1=-0.1, theta2=0.1, theta0=0, cv=0.14, n=30, design="2x2", method="nct")
0.7079951477313315

> power.TOST(alpha=0.1, logscale=FALSE, theta1=-0.1, theta2=0.1, theta0=0, CV=0.14, n=21, design="2x2", method="shifted")
Unbalanced design. n(i)=11/10 assumed.
[1] 0.6626132
julia> ClinicalTrialUtilities.powerTOST(alpha=0.1, logscale=false, theta1=-0.1, theta2=0.1, theta0=0, cv=0.14, n=21, design="2x2", method="shifted")
0.6626131671398885

> power.TOST(alpha=0.0000001, logscale=FALSE, theta1=-0.1, theta2=0.1, theta0=0, CV=1, n=10000, design="2x2", method="owenq")
[1] 0.9380914
julia> ClinicalTrialUtilities.powerTOST(alpha=0.0000001, logscale=false, theta1=-0.1, theta2=0.1, theta0=0, cv=1, n=10000, design="2x2", method="owenq")
0.9380914428598442

power.TOST(alpha=0.0001, logscale=FALSE, theta1=-0.1, theta2=0.1, theta0=0, CV=1, n=3500, design="2x2", method="owenq")
[1] 0.3545904
julia> ClinicalTrialUtilities.powerTOST(alpha=0.0001, logscale=false, theta1=-0.1, theta2=0.1, theta0=0, cv=1, n=3500, design="2x2", method="owenq")
0.35459037140683924

> power.TOST(alpha=0.00000005, logscale=FALSE, theta1=-0.1, theta2=0.1, theta0=0, CV=1.5, n=20000, design="2x2", method="owenq")
[1] 0.8197361


> sampleN.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.2, alpha=0.05, targetpower=0.8, logscale=TRUE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.2   0.95    0.8   1.25          20      0.8346802          0.8
>

> sampleN.TOST(theta0=0.95, theta1=0.8, theta2=1.25, CV=0.3, alpha=0.05, targetpower=0.8, logscale=TRUE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.3   0.95    0.8   1.25          40      0.8158453          0.8
>
> sampleN.TOST(theta0=1, theta1=0.8, theta2=1.25, CV=0.3, alpha=0.05, targetpower=0.9, logscale=TRUE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.3      1    0.8   1.25          40      0.9095603          0.9
>

> sampleN.TOST(theta0=1.05, theta1=0.8, theta2=1.25, CV=0.4, alpha=0.05, targetpower=0.85, logscale=TRUE, design="2x2", method="nct", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.4   1.05    0.8   1.25          74      0.8558178         0.85
>

> sampleN.TOST(theta0=1.05, theta1=0.9, theta2=1.25, CV=0.4, alpha=0.05, targetpower=0.85, logscale=TRUE, design="2x2", method="nct", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.4   1.05    0.9   1.25         108      0.8506248         0.85
>

> sampleN.TOST(theta0=1.05, theta1=0.8, theta2=1.2, CV=0.5, alpha=0.05, targetpower=0.8, logscale=TRUE, design="2x2", method="nct", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.5   1.05    0.8    1.2         158      0.8039191          0.8
>

> sampleN.TOST(theta0=1.05, theta1=0.8, theta2=1.25, CV=0.8, alpha=0.05, targetpower=0.8, logscale=TRUE, design="2x2", method="shifted", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.8   1.05    0.8   1.25         210      0.8012471          0.8
>


> sampleN.TOST(theta0=0, theta1=-0.2, theta2=0.2, CV=0.5, alpha=0.05, targetpower=0.8, logscale=FALSE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha  CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05 0.5      0   -0.2    0.2         110      0.8074124          0.8
>

> sampleN.TOST(theta0=0, theta1=-0.2, theta2=0.2, CV=2, alpha=0.05, targetpower=0.8, logscale=FALSE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.05  2      0   -0.2    0.2        1716      0.8005618          0.8
>

> sampleN.TOST(theta0=0, theta1=-0.2, theta2=0.2, CV=2, alpha=0.001, targetpower=0.8, logscale=FALSE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2 0.001  2      0   -0.2    0.2        3828      0.8001454          0.8
>

> sampleN.TOST(theta0=0, theta1=-0.2, theta2=0.2, CV=2, alpha=0.01, targetpower=0.99, logscale=FALSE, design="2x2", method="owenq", robust=TRUE, print=FALSE)
  Design alpha CV theta0 theta1 theta2 Sample size Achieved power Target power
1    2x2  0.01  2      0   -0.2    0.2        4810      0.9900151         0.99
>
> sampleN.TOST(alpha=0.1, targetpower=0.9, theta0=0.95, CV=0.35, design="parallel", method="shifted")

+++++++++++ Equivalence test - TOST +++++++++++
            Sample size estimation
-----------------------------------------------
Study design:  2 parallel groups
log-transformed data (multiplicative model)

alpha = 0.1, target power = 0.9
BE margins = 0.8 ... 1.25
True ratio = 0.95,  CV = 0.35

Sample size (total)
 n     power
106   0.901389

Approximate power calculation with
shifted central t-distribution.

>


Prop.diff(x=c(30,70),y=c(40,50), CImethod="NHS")
$conf.int
[1] -0.275381800 -0.007158419
attr(,"methodname")
[1] "Newcombes Hybrid Score interval for the difference of proportions"
$estimate
[1] -0.1444444
ClinicalTrialUtilities.CI.twoProp(30, 100, 40, 90; alpha=0.05, type="diff", method="nhs")
Main.ClinicalTrialUtilities.CI.ConfInt(-0.275381800397722, -0.007158418963689295, -0.14444444444444443)

julia> ClinicalTrialUtilities.CI.twoProp(30, 100, 40, 90; alpha=0.05, type="diff", method="ac")
Main.ClinicalTrialUtilities.CI.ConfInt(-0.2769445059583262, -0.006516704612858776, -0.14444444444444443)
