Skip to content

Commit

Permalink
Merge pull request #32 from PharmCat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
PharmCat authored Dec 8, 2019
2 parents c2d4757 + 37eed39 commit 1a6d85c
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 214 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
authors = ["Vladimir Arnautov ([email protected])"]
name = "ClinicalTrialUtilities"
uuid = "535c2557-d7d0-564d-8ff9-4ae146c18cfe"
version = "0.2.0"
version = "0.2.1"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
7 changes: 7 additions & 0 deletions cange.log
Original file line number Diff line number Diff line change
@@ -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(!):
Expand Down
2 changes: 1 addition & 1 deletion src/samplesize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 17 additions & 3 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
52 changes: 26 additions & 26 deletions test/citest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,142 +44,142 @@ 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

#---- 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
Expand Down
Loading

2 comments on commit 1a6d85c

@PharmCat
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

v0.2.1

  • error message for besamplen
  • cvfromci new method
  • pooledcv new method
  • minor fix
  • cosmetics

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/6432

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 1a6d85ca451046cae78ac67e25b2f2ffdcf5bc9d
git push origin v0.2.1

Please sign in to comment.