diff --git a/Project.toml b/Project.toml index e599a68..e4f0832 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ authors = ["Vladimir Arnautov (mail@pharmcat.net)"] name = "ClinicalTrialUtilities" uuid = "535c2557-d7d0-564d-8ff9-4ae146c18cfe" -version = "0.2.0" +version = "0.2.1" [deps] Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/cange.log b/cange.log index 1e234eb..e4bd932 100644 --- a/cange.log +++ b/cange.log @@ -1,3 +1,10 @@ +v0.2.1 + - error message for besamplen + - cvfromci new method + - pooledcv new method + - minor fix + - cosmetics + v0.2.0 Breaking changes(!): diff --git a/src/samplesize.jl b/src/samplesize.jl index 75fadf7..aaf5cd1 100644 --- a/src/samplesize.jl +++ b/src/samplesize.jl @@ -633,7 +633,7 @@ Bioequivalence sample size estimation. function besamplen(;alpha::Real=0.05, beta::Real=0.2, theta0::Real=0.95, theta1::Real=0.8, theta2::Real=1.25, cv::Real=0.0, sd::Real=0.0, design::Symbol=:d2x2, method::Symbol=:owenq, logscale::Bool=true)::TaskResult if !(0 < beta < 1) throw(ArgumentError("Beta ≥ 1.0 or ≤ 0.0!")) end if !(0 < alpha < 1) throw(ArgumentError("Alfa ≥ 1.0 or ≤ 0.0!")) end - if theta1 ≥ theta2 throw(ArgumentError("theta1 ≥ theta2!")) end + if !(theta2 > theta0 > theta1) throw(ArgumentError("!(theta2 > thetao > theta1), check settings!")) end if !logscale && cv > 0.0 && sd ≤ 0.0 throw(ArgumentError("Use sd instead cv for non-logscale parameters!")) end if !logscale && sd ≤ 0.0 throw(ArgumentError("sd ≤ 0.0!")) end if !logscale && cv > 0.0 @warn "sd and cv provided for non-logscale parameters, only sd used!" end diff --git a/src/show.jl b/src/show.jl index 3f81042..c95389d 100644 --- a/src/show.jl +++ b/src/show.jl @@ -73,7 +73,7 @@ function Base.show(io::IO, obj::TaskResult{CT}) where CT <: CTask{T, D, Bioequi println(io, objectivename(obj.task.objective)) println(io,"-----------------------------------------") println(io," Parameter type: ", paramname(obj.task.param)) - println(io," Design: ", designinfo(obj.task.design)) + println(io," Design: $(obj.task.design)") println(io," Hypothesis: ", obj.task.hyp) #println(io," Lower limit: ", round(obj.task.llim, sigdigits = 4)) #println(io," Upper limit: ", round(obj.task.ulim, sigdigits = 4)) diff --git a/src/utilities.jl b/src/utilities.jl index d6a5c82..19fef2d 100644 --- a/src/utilities.jl +++ b/src/utilities.jl @@ -84,6 +84,9 @@ function cvfromci(;alpha = 0.05, theta1 = 0.8, theta2 = 1.25, n, design=:d2x2, m if mso return ms end return cvfromvar(ms) end +function cvfromci(theta1, theta2, n; alpha = 0.05, design=:d2x2, mso=false, cvms=false) + return cvfromci(;alpha = alpha, theta1 = theta1, theta2 = theta2, n = n, design = design, mso = mso, cvms = cvms) +end """ pooledcv(data::DataFrame; cv=:cv, df=:df, alpha=0.05, returncv=true)::ConfInt @@ -104,13 +107,24 @@ Pooled CV from multiple sources. - false - return var """ -function pooledcv(data::DataFrame; cv=:cv, df=:df, alpha=0.05, returncv=true)::ConfInt +function pooledcv(data::DataFrame; cv = :cv, df = :df, alpha::Real = 0.05, returncv::Bool = true)::ConfInt if isa(cv, String) cv = Symbol(cv) end if isa(df, String) df = Symbol(df) end - tdf = sum(data[:, df]) - result = sum(varfromcv.(data[:, cv]) .* data[:, df])/tdf + return pooledcv(data[!, cv], data[!, df]; alpha = alpha, returncv = returncv) +end +function pooledcv(cv::Vector, df::Vector; alpha=0.05, returncv = true)::ConfInt + tdf = sum(df) + result = sum(varfromcv.(cv) .* df)/tdf CHSQ = Chisq(tdf) if returncv return ConfInt(cvfromvar(result*tdf/quantile(CHSQ, 1-alpha/2)), cvfromvar(result*tdf/quantile(CHSQ, alpha/2)), cvfromvar(result)) else ConfInt(result*tdf/quantile(CHSQ, 1-alpha/2), result*tdf/quantile(CHSQ, alpha/2), result) end end +function pooledcv(cv::Vector, n::Vector, design::Vector; alpha=0.05, returncv = true)::ConfInt + d = Design.(design) + df = Array{Int, 1}(undef, length(d)) + for i = 1:length(d) + df[i] = d[i].df(n[i]) + end + return pooledcv(cv, df; alpha = alpha, returncv = returncv) +end diff --git a/test/citest.jl b/test/citest.jl index c646fb8..73d7782 100644 --- a/test/citest.jl +++ b/test/citest.jl @@ -44,97 +44,97 @@ println(" ---------------------------------- ") #---- twoProp #-- mn - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:or, method=:mn) + ci = ClinicalTrialUtilities.orpropci(30, 100, 40, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 0.29537414 atol=1E-6 @test ci.upper ≈ 0.97166697 atol=1E-6 @test ci.estimate ≈ 0.53571428 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(100, 100, 90, 90; alpha=0.05, type=:or, method=:mn) + ci = ClinicalTrialUtilities.orpropci(100, 100, 90, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 0.0 @test ci.upper ≈ Inf #@test ci.estimate == NaN - ci = ClinicalTrialUtilities.twoprop(0, 100, 90, 90; alpha=0.05, type=:or, method=:mn) + ci = ClinicalTrialUtilities.orpropci(0, 100, 90, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 0.0 @test ci.upper ≈ 0.00041425995552740226 atol=1E-6 @test ci.estimate ≈ 0.0 - ci = ClinicalTrialUtilities.twoprop(100, 100, 0, 90; alpha=0.05, type=:or, method=:mn) + ci = ClinicalTrialUtilities.orpropci(100, 100, 0, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 2413.9431770847045 atol=1E-6 @test ci.upper ≈ Inf @test ci.estimate ≈ Inf #-- mn2 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:or, method=:mn2) + ci = ClinicalTrialUtilities.orpropci(30, 100, 40, 90; alpha=0.05, method=:mn2) @test ci.lower ≈ 0.2951669 atol=1E-6 @test ci.upper ≈ 0.9722965 atol=1E-6 @test ci.estimate ≈ 0.5357142 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(100, 100, 90, 90; alpha=0.05, type=:or, method=:mn2) + ci = ClinicalTrialUtilities.orpropci(100, 100, 90, 90; alpha=0.05, method=:mn2) @test ci.lower ≈ 0.0 @test ci.upper ≈ Inf #@test ci.estimate == NaN - ci = ClinicalTrialUtilities.twoprop(0, 100, 90, 90; alpha=0.05, type=:or, method=:mn2) + ci = ClinicalTrialUtilities.orpropci(0, 100, 90, 90; alpha=0.05, method=:mn2) @test ci.lower ≈ 0.0 @test ci.upper ≈ 0.0004144169697670039 atol=1E-6 @test ci.estimate ≈ 0.0 - ci = ClinicalTrialUtilities.twoprop(100, 100, 0, 90; alpha=0.05, type=:or, method=:mn2) + ci = ClinicalTrialUtilities.orpropci(100, 100, 0, 90; alpha=0.05, method=:mn2) @test ci.lower ≈ 2411.6137253788347 atol=1E-6 @test ci.upper ≈ Inf @test ci.estimate ≈ Inf - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:or, method=:awoolf) + ci = ClinicalTrialUtilities.orpropci(30, 100, 40, 90; alpha=0.05, method=:awoolf) @test ci.lower ≈ 0.2982066 atol=1E-6 @test ci.upper ≈ 0.9758363 atol=1E-6 @test ci.estimate ≈ 0.5394449 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:or, method=:woolf) + ci = ClinicalTrialUtilities.orpropci(30, 100, 40, 90; alpha=0.05, method=:woolf) @test ci.lower ≈ 0.29504200273798975 atol=1E-6 @test ci.upper ≈ 0.9727082695179062 atol=1E-6 @test ci.estimate ≈ 0.5357142857142857 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:or, method=:mover) + ci = ClinicalTrialUtilities.orpropci(30, 100, 40, 90; alpha=0.05, method=:mover) @test ci.lower ≈ 0.2963748435372293 atol=1E-6 @test ci.upper ≈ 0.9689058534780502 atol=1E-6 @test ci.estimate ≈ 0.5357142857142857 atol=1E-6 #---- - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:nhs) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:nhs) @test ci.lower ≈ -0.275381800 atol=1E-6 @test ci.upper ≈ -0.007158419 atol=1E-6 @test ci.estimate ≈ -0.1444444 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:ac) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:ac) @test ci.lower ≈ -0.276944506 atol=1E-6 @test ci.upper ≈ -0.006516705 atol=1E-6 @test ci.estimate ≈ -0.1444444 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:mn) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:mn) @test ci.lower ≈ -0.2781290897168457 atol=1E-6 @test ci.upper ≈ -0.006708341755865329 atol=1E-6 @test ci.estimate ≈ -0.1444444 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:mee) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:mee) @test ci.lower ≈ -0.27778775409226936 atol=1E-6 @test ci.upper ≈ -0.007071205228197489 atol=1E-6 @test ci.estimate ≈ -0.14444444444 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:mee2) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:mee2) #Roots 0.7.4 CTU 0.1.7 @test ci.lower ≈ -0.27778778455 atol=1E-5 #Chang atol for validation @test ci.upper ≈ -0.00707120778 atol=1E-5 @test ci.estimate ≈ -0.14444444444 atol=1E-7 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:wald) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:wald) @test ci.lower ≈ -0.28084842238 atol=1E-6 @test ci.upper ≈ -0.00804046650 atol=1E-6 @test ci.estimate ≈ -0.14444444444 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:diff, method=:waldcc) + ci = ClinicalTrialUtilities.diffpropci(30, 100, 40, 90; alpha=0.05, method=:waldcc) @test ci.lower ≈ -0.29140397794 atol=1E-6 @test ci.upper ≈ 0.00251508905 atol=1E-6 @test ci.estimate ≈ -0.14444444444 atol=1E-6 @@ -142,44 +142,44 @@ println(" ---------------------------------- ") #---- RR #-- mn - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:rr, method=:mn) + ci = ClinicalTrialUtilities.rrpropci(30, 100, 40, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 0.46636099123297575 atol=1E-6 @test ci.upper ≈ 0.9799258384796817 atol=1E-6 @test ci.estimate ≈ 0.675 atol=1E-6 - ci = ClinicalTrialUtilities.twoprop(100, 100, 90, 90; alpha=0.05, type=:rr, method=:mn) + ci = ClinicalTrialUtilities.rrpropci(100, 100, 90, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 0.0 @test ci.upper ≈ Inf #@test ci.estimate == NaN - ci = ClinicalTrialUtilities.twoprop(0, 100, 90, 90; alpha=0.05, type=:rr, method=:mn) + ci = ClinicalTrialUtilities.rrpropci(0, 100, 90, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 0.0 @test ci.upper ≈ 0.018137090385952483 atol=1E-6 @test ci.estimate ≈ 0.0 - ci = ClinicalTrialUtilities.twoprop(100, 100, 0, 90; alpha=0.05, type=:rr, method=:mn) + ci = ClinicalTrialUtilities.rrpropci(100, 100, 0, 90; alpha=0.05, method=:mn) @test ci.lower ≈ 44.8498645475395 atol=1E-6 @test ci.upper ≈ Inf @test ci.estimate ≈ Inf #-- cli - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:rr, method=:cli) + ci = ClinicalTrialUtilities.rrpropci(30, 100, 40, 90; alpha=0.05, method=:cli) @test ci.lower ≈ 0.4663950 atol=1E-6 @test ci.upper ≈ 0.9860541 atol=1E-6 @test ci.estimate ≈ 0.675 atol=1E-4 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:rr, method=:mover) + ci = ClinicalTrialUtilities.rrpropci(30, 100, 40, 90; alpha=0.05, method=:mover) @test ci.lower ≈ 0.4634443 atol=1E-6 @test ci.upper ≈ 0.9808807 atol=1E-6 @test ci.estimate ≈ 0.675 atol=1E-4 - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:rr, method=:mover) + ci = ClinicalTrialUtilities.rrpropci(30, 100, 40, 90; alpha=0.05, method=:mover) @test ci.lower ≈ 0.4634443 atol=1E-6 @test ci.upper ≈ 0.9808807 atol=1E-6 @test ci.estimate ≈ 0.675 atol=1E-4 #katz - ci = ClinicalTrialUtilities.twoprop(30, 100, 40, 90; alpha=0.05, type=:rr, method=:katz) + ci = ClinicalTrialUtilities.rrpropci(30, 100, 40, 90; alpha=0.05, method=:katz) @test ci.lower ≈ 0.4624671 atol=1E-6 @test ci.upper ≈ 0.9852050 atol=1E-6 @test ci.estimate ≈ 0.675 atol=1E-4 diff --git a/test/ctsamplen.jl b/test/ctsamplen.jl new file mode 100644 index 0000000..6072a15 --- /dev/null +++ b/test/ctsamplen.jl @@ -0,0 +1,152 @@ +@testset "#1 ctsamplen Test " begin + #Sample Size Calculations in Clinical Research, Second Edition, Shein-Chung Chow, Ph.D., 2008, International Standard Book Number‑13: 978‑1‑58488‑982‑3 + #1 + t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ea, group=:one, alpha=0.05, beta=0.2, sd=1, a=2, b=1.5) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 32 + Base.show(io, t) + Base.show(io, t.task) + #2 + t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ei, group=:one, alpha=0.05, beta=0.2, sd=0.1, diff=0.05, a=2, b=2) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 35 + Base.show(io, t) + #3 + t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ns, group=:one, alpha=0.05, beta=0.2, sd=1, diff=-0.5, a=2, b=1.5) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 7 + Base.show(io, t) + #4 + t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ea, group=:two, alpha=0.05, beta=0.2, sd=10, a=5, b=10, k=1) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 63 + Base.show(io, t) + #5 + t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ei, group=:two, alpha=0.05, beta=0.2, sd=10, diff=5, a=5, b=4, k=1) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 108 + Base.show(io, t) + #6 + t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ns, group=:two, alpha=0.05, beta=0.2, sd=10, diff=5, a=5, b=5, k=1) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 50 + Base.show(io, t) + #7 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ea, group=:one, alpha=0.05, beta=0.2, a=0.5, b=0.3) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 50 + Base.show(io, t) + #8 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ei, group=:one, alpha=0.05, beta=0.2, diff=0.2, a=0.6, b=0.6) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 52 + Base.show(io, t) + #9 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ns, group=:one, alpha=0.05, beta=0.2, diff=-0.1, a=0.5, b=0.3) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 18 + Base.show(io, t) + #10 p.92 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ea, group=:two, alpha=0.05, beta=0.2, a=0.65, b=0.85) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 70 + Base.show(io, t) + #11 p.93 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ei, group=:two, alpha=0.05, beta=0.2, diff=0.2, a=0.75, b=0.80) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 133 + Base.show(io, t) + #12 p.92 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ns, group=:two, alpha=0.05, beta=0.2, diff=-0.1, a=0.85, b=0.65) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 25 + Base.show(io, t) + #13 p.108 + t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ea, alpha=0.05, beta=0.2, a=0.4, b=0.25) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 156 + Base.show(io, t) + #14.1 p.109 + t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ei, alpha=0.05, beta=0.2, diff=0.5, a=0.25, b=0.25) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 366 + Base.show(io, t) + #15.1 p.108 + t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ns, alpha=0.05, beta=0.2, diff=0.2, a=0.4, b=0.25) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 242 + Base.show(io, t) + #14.2 + t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ei, alpha=0.05, beta=0.2, diff=exp(0.5), a=0.25, b=0.25, logscale = false) + @test ceil(t.result) == 366 + Base.show(io, t) + #15.2 + t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ns, alpha=0.05, beta=0.2, diff=exp(0.2), a=0.4, b=0.25, logscale = false) + @test ceil(t.result) == 242 + Base.show(io, t) + #16 + t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:mcnm, a=0.45, b=0.05) + @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 23 + Base.show(io, t) + + #Additional + #Different type input + @test ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ns, group=:two, alpha=0.05, beta=0.2, diff=1, sd=20.0, a=1, b=2).result ≈ 1236.511446403953 atol=1E-12 + + @test ceil(ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ns, group=:two, alpha=0.05, beta=0.2, diff=0.05, a=0.85, b=0.65).result) == 98 +end + +println(" ---------------------------------- ") +@testset "#2 ctpower Test " begin + + #1 + t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ea, group=:one, a=2, b=1.5, sd=1,n=32, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8074304194325561 atol=1E-7 + Base.show(io, t) + Base.show(io, t.task) + #2 + t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ei, group=:one, a=2, b=2, sd=0.1, diff=0.05, n=35, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8108839754376387 atol=1E-7 + Base.show(io, t) + #3 + t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ns, group=:one, a=2, b=1.5, sd=1, diff=-0.5, n=7, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8415707712023641 atol=1E-7 + Base.show(io, t) + #4 + t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ea, group=:two, a=5, b=10, sd=10, n=63, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8013023941055788 atol=1E-7 + Base.show(io, t) + #5 + t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ei, group=:two, a=5, b=4, sd=10, diff=5, n=108, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.80452354556060 atol=1E-7 + Base.show(io, t) + #6 + t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ns, group=:two, a=5, b=5, sd=10, diff=5, n=50, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8037819415575257 atol=1E-7 + Base.show(io, t) + #7 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ea, group=:one, a=0.5, b=0.3, n=50, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8074304194325561 atol=1E-7 + Base.show(io, t) + #8 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ei, group=:one, a=0.6, b=0.6, diff=0.2, n=52, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8060834056011101 atol=1E-7 + Base.show(io, t) + #9 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ns, group=:one, a=0.5, b=0.3, diff=-0.1, n=18, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8161481827204281 atol=1E-7 + Base.show(io, t) + #10 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ea, group=:two, a=0.65, b=0.85, n=70, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8019139068528 atol=1E-7 + Base.show(io, t) + #11 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ei, group=:two, a=0.65, b=0.85, diff=0.05, n=136, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8033294052407269 atol=1E-7 + Base.show(io, t) + #12 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ns, group=:two, a=0.85, b=0.65, diff=-0.1, n=25, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.808599833380679 atol=1E-7 + Base.show(io, t) + #13 + t = ClinicalTrialUtilities.ctpower(param=:or, type=:ea, a=0.4, b=0.25, n=156, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8020239054864792 atol=1E-7 + Base.show(io, t) + #14 + t = ClinicalTrialUtilities.ctpower(param=:or, type=:ei, a=0.25, b=0.25, diff=0.5, n=366, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8008593380478983 atol=1E-7 + Base.show(io, t) + #15 + t = ClinicalTrialUtilities.ctpower(param=:or, type=:ns, a=0.4, b=0.25, diff=0.2, n=242, alpha=0.05) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8007200876001626 atol=1E-7 + Base.show(io, t) + #16 + t = ClinicalTrialUtilities.ctpower(param=:prop, type=:mcnm, a=0.45, b=0.05, n=23, alpha=0.1) + @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.9023805 atol=1E-7 + Base.show(io, t) +end diff --git a/test/test.jl b/test/test.jl index b279fae..61e6447 100644 --- a/test/test.jl +++ b/test/test.jl @@ -18,158 +18,7 @@ println(" --------- START TEST --------- ") println(" ---------------------------------- ") println(" ---------------------------------- ") -@testset "#1 ctsamplen Test " begin - #Sample Size Calculations in Clinical Research, Second Edition, Shein-Chung Chow, Ph.D., 2008, International Standard Book Number‑13: 978‑1‑58488‑982‑3 - #1 - t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ea, group=:one, alpha=0.05, beta=0.2, sd=1, a=2, b=1.5) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 32 - Base.show(io, t) - Base.show(io, t.task) - #2 - t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ei, group=:one, alpha=0.05, beta=0.2, sd=0.1, diff=0.05, a=2, b=2) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 35 - Base.show(io, t) - #3 - t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ns, group=:one, alpha=0.05, beta=0.2, sd=1, diff=-0.5, a=2, b=1.5) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 7 - Base.show(io, t) - #4 - t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ea, group=:two, alpha=0.05, beta=0.2, sd=10, a=5, b=10, k=1) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 63 - Base.show(io, t) - #5 - t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ei, group=:two, alpha=0.05, beta=0.2, sd=10, diff=5, a=5, b=4, k=1) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 108 - Base.show(io, t) - #6 - t = ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ns, group=:two, alpha=0.05, beta=0.2, sd=10, diff=5, a=5, b=5, k=1) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 50 - Base.show(io, t) - #7 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ea, group=:one, alpha=0.05, beta=0.2, a=0.5, b=0.3) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 50 - Base.show(io, t) - #8 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ei, group=:one, alpha=0.05, beta=0.2, diff=0.2, a=0.6, b=0.6) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 52 - Base.show(io, t) - #9 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ns, group=:one, alpha=0.05, beta=0.2, diff=-0.1, a=0.5, b=0.3) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 18 - Base.show(io, t) - #10 p.92 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ea, group=:two, alpha=0.05, beta=0.2, a=0.65, b=0.85) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 70 - Base.show(io, t) - #11 p.93 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ei, group=:two, alpha=0.05, beta=0.2, diff=0.2, a=0.75, b=0.80) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 133 - Base.show(io, t) - #12 p.92 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ns, group=:two, alpha=0.05, beta=0.2, diff=-0.1, a=0.85, b=0.65) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 25 - Base.show(io, t) - #13 p.108 - t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ea, alpha=0.05, beta=0.2, a=0.4, b=0.25) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 156 - Base.show(io, t) - #14.1 p.109 - t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ei, alpha=0.05, beta=0.2, diff=0.5, a=0.25, b=0.25) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 366 - Base.show(io, t) - #15.1 p.108 - t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ns, alpha=0.05, beta=0.2, diff=0.2, a=0.4, b=0.25) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 242 - Base.show(io, t) - #14.2 - t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ei, alpha=0.05, beta=0.2, diff=exp(0.5), a=0.25, b=0.25, logscale = false) - @test ceil(t.result) == 366 - Base.show(io, t) - #15.2 - t = ClinicalTrialUtilities.ctsamplen(param=:or, type=:ns, alpha=0.05, beta=0.2, diff=exp(0.2), a=0.4, b=0.25, logscale = false) - @test ceil(t.result) == 242 - Base.show(io, t) - #16 - t = ClinicalTrialUtilities.ctsamplen(param=:prop, type=:mcnm, a=0.45, b=0.05) - @test ceil(t.result) == ceil(ClinicalTrialUtilities.ctsamplen(t.task).result) == 23 - Base.show(io, t) - - #Additional - #Different type input - @test ClinicalTrialUtilities.ctsamplen(param=:mean, type=:ns, group=:two, alpha=0.05, beta=0.2, diff=1, sd=20.0, a=1, b=2).result ≈ 1236.511446403953 atol=1E-12 - - @test ceil(ClinicalTrialUtilities.ctsamplen(param=:prop, type=:ns, group=:two, alpha=0.05, beta=0.2, diff=0.05, a=0.85, b=0.65).result) == 98 -end - -println(" ---------------------------------- ") -@testset "#2 ctpower Test " begin - - #1 - t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ea, group=:one, a=2, b=1.5, sd=1,n=32, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8074304194325561 atol=1E-7 - Base.show(io, t) - Base.show(io, t.task) - #2 - t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ei, group=:one, a=2, b=2, sd=0.1, diff=0.05, n=35, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8108839754376387 atol=1E-7 - Base.show(io, t) - #3 - t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ns, group=:one, a=2, b=1.5, sd=1, diff=-0.5, n=7, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8415707712023641 atol=1E-7 - Base.show(io, t) - #4 - t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ea, group=:two, a=5, b=10, sd=10, n=63, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8013023941055788 atol=1E-7 - Base.show(io, t) - #5 - t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ei, group=:two, a=5, b=4, sd=10, diff=5, n=108, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.80452354556060 atol=1E-7 - Base.show(io, t) - #6 - t = ClinicalTrialUtilities.ctpower(param=:mean, type=:ns, group=:two, a=5, b=5, sd=10, diff=5, n=50, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8037819415575257 atol=1E-7 - Base.show(io, t) - #7 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ea, group=:one, a=0.5, b=0.3, n=50, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8074304194325561 atol=1E-7 - Base.show(io, t) - #8 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ei, group=:one, a=0.6, b=0.6, diff=0.2, n=52, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8060834056011101 atol=1E-7 - Base.show(io, t) - #9 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ns, group=:one, a=0.5, b=0.3, diff=-0.1, n=18, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8161481827204281 atol=1E-7 - Base.show(io, t) - #10 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ea, group=:two, a=0.65, b=0.85, n=70, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8019139068528 atol=1E-7 - Base.show(io, t) - #11 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ei, group=:two, a=0.65, b=0.85, diff=0.05, n=136, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8033294052407269 atol=1E-7 - Base.show(io, t) - #12 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:ns, group=:two, a=0.85, b=0.65, diff=-0.1, n=25, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.808599833380679 atol=1E-7 - Base.show(io, t) - #13 - t = ClinicalTrialUtilities.ctpower(param=:or, type=:ea, a=0.4, b=0.25, n=156, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8020239054864792 atol=1E-7 - Base.show(io, t) - #14 - t = ClinicalTrialUtilities.ctpower(param=:or, type=:ei, a=0.25, b=0.25, diff=0.5, n=366, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8008593380478983 atol=1E-7 - Base.show(io, t) - #15 - t = ClinicalTrialUtilities.ctpower(param=:or, type=:ns, a=0.4, b=0.25, diff=0.2, n=242, alpha=0.05) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.8007200876001626 atol=1E-7 - Base.show(io, t) - #16 - t = ClinicalTrialUtilities.ctpower(param=:prop, type=:mcnm, a=0.45, b=0.05, n=23, alpha=0.1) - @test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.9023805 atol=1E-7 - Base.show(io, t) -end +include("ctsamplen.jl") println(" ---------------------------------- ") @testset "#3 besamplen Test " begin @@ -335,36 +184,7 @@ println(" ---------------------------------- ") #@test ClinicalTrialUtilities.ctpower(t.task).result ≈ 0.0001785665 atol=1E-10 end -println(" ---------------------------------- ") -@testset "#5 utils Test " begin - -@testset " ci2cv Test " begin - cvms = ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30, design=:d2x2x4, cvms=true) - @test cvms[1] ≈ 0.583175066140736 && cvms[2] ≈ 0.29273913226894244 - @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30, design=:d2x2x4, mso=true) ≈ 0.29273913226894244 - @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30) ≈ 0.387417014838382 - @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.8, theta2 = 1.25, n=30) ≈ 0.5426467811605913 - @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 1.01, theta2 = 1.21, n=31, design=:d2x2) ≈ 0.21151405971696524 -end - -@testset " pooledcv " begin - data = DataFrame(cv = Float64[], df = Int[]) - push!(data, (0.12, 12)) - push!(data, (0.2, 20)) - push!(data, (0.25, 30)) - ci = ClinicalTrialUtilities.pooledcv(data; cv="cv", df="df") - @test ci.lower ≈ 0.18145259424967664 atol=1E-15 - @test ci.upper ≈ 0.2609307413637307 atol=1E-15 - @test ci.estimate ≈ 0.21393949168210136 atol=1E-15 - ci = ClinicalTrialUtilities.pooledcv(data; cv="cv", df="df", returncv=false) - @test ci.lower ≈ 0.032394625994562894 atol=1E-15 - @test ci.upper ≈ 0.06586718662236608 atol=1E-15 - @test ci.estimate ≈ 0.04475355764465427 atol=1E-15 -end - -@test ClinicalTrialUtilities.cvfromsd(ClinicalTrialUtilities.sdfromcv(0.2)) ≈ 0.2 -@test ClinicalTrialUtilities.cvfromvar(ClinicalTrialUtilities.varfromcv(0.2)) ≈ 0.2 -end +include("utils.jl") println(" ---------------------------------- ") @testset "Internal functions test " begin @@ -498,6 +318,7 @@ println(" ---------------------------------- ") pk = ClinicalTrialUtilities.nca!(pkds) df = ClinicalTrialUtilities.DataFrame(pk; unst = true) ClinicalTrialUtilities.htmlexport(df; io = io, sort = :Subject, rspan=:all, title = "PK Parameters", dict = :pk) + @test true end println(" ---------------------------------- ") diff --git a/test/utils.jl b/test/utils.jl new file mode 100644 index 0000000..0a9140a --- /dev/null +++ b/test/utils.jl @@ -0,0 +1,44 @@ +println(" ---------------------------------- ") +@testset "#5 utils Test " begin + +@testset " ci2cv Test " begin + cvms = ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30, design=:d2x2x4, cvms=true) + @test cvms[1] ≈ 0.583175066140736 && cvms[2] ≈ 0.29273913226894244 + @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30, design=:d2x2x4, mso=true) ≈ 0.29273913226894244 + @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.9, theta2 = 1.25, n=30) ≈ 0.387417014838382 + @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 0.8, theta2 = 1.25, n=30) ≈ 0.5426467811605913 + @test ClinicalTrialUtilities.cvfromci(;alpha = 0.05, theta1 = 1.01, theta2 = 1.21, n=31, design=:d2x2) ≈ 0.21151405971696524 + + @test ClinicalTrialUtilities.cvfromci(0.9, 1.25, 30) ≈ 0.387417014838382 +end + +@testset " pooledcv " begin + data = DataFrame(cv = Float64[], df = Int[]) + push!(data, (0.12, 12)) + push!(data, (0.2, 20)) + push!(data, (0.25, 30)) + ci = ClinicalTrialUtilities.pooledcv(data; cv="cv", df="df") + @test ci.lower ≈ 0.18145259424967664 atol=1E-15 + @test ci.upper ≈ 0.2609307413637307 atol=1E-15 + @test ci.estimate ≈ 0.21393949168210136 atol=1E-15 + + ci = ClinicalTrialUtilities.pooledcv(data; cv="cv", df="df", returncv=false) + @test ci.lower ≈ 0.032394625994562894 atol=1E-15 + @test ci.upper ≈ 0.06586718662236608 atol=1E-15 + @test ci.estimate ≈ 0.04475355764465427 atol=1E-15 + + ci = ClinicalTrialUtilities.pooledcv([0.12, 0.2, 0.25], [12, 20, 30]) + @test ci.lower ≈ 0.18145259424967664 atol=1E-15 + @test ci.upper ≈ 0.2609307413637307 atol=1E-15 + @test ci.estimate ≈ 0.21393949168210136 atol=1E-15 + + ci = ClinicalTrialUtilities.pooledcv([0.12, 0.2, 0.25], [14, 22, 32], [:d2x2, :d2x2, :d2x2]) + @test ci.lower ≈ 0.18145259424967664 atol=1E-15 + @test ci.upper ≈ 0.2609307413637307 atol=1E-15 + @test ci.estimate ≈ 0.21393949168210136 atol=1E-15 +end + +@test ClinicalTrialUtilities.cvfromsd(ClinicalTrialUtilities.sdfromcv(0.2)) ≈ 0.2 + +@test ClinicalTrialUtilities.cvfromvar(ClinicalTrialUtilities.varfromcv(0.2)) ≈ 0.2 +end