Skip to content

Commit

Permalink
Merge pull request #49 from PharmCat/dev
Browse files Browse the repository at this point in the history
v0.3.2
  - bugfix fisher test
  - add show
  - propci for ConTab
  - bump dependencies
  • Loading branch information
PharmCat authored Nov 27, 2020
2 parents e712fbf + 56097d1 commit 4401c16
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 27 deletions.
14 changes: 6 additions & 8 deletions 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.3.1"
version = "0.3.2"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -13,7 +13,6 @@ Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

[extras]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -24,13 +23,12 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
test = ["CSV", "Test", "Plots"]

[compat]
julia = "1.0, 1.1, 1.2, 1.3, 1.4"
Distributions = "0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23"
julia = "1.0, 1.1, 1.2, 1.3, 1.4, 1.5"
Distributions = "0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24"
StatsBase = "0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33"
QuadGK = "2.0, 2.1, 2.2, 2.3, 2.4"
SpecialFunctions = "0.8, 0.9, 0.10"
Roots = "0.7, 0.8, 1.0"
RecipesBase = "0.7, 0.8, 1.0"
SpecialFunctions = "0.8, 0.9, 0.10, 1"
Roots = "0.7, 0.8, 1"
RecipesBase = "0.7, 0.8, 1"
Reexport = "0.1, 0.2"
DataFrames = "0.19, 0.20"
CSV = "0.5, 0.6"
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
[![Coverage Status](https://coveralls.io/repos/github/PharmCat/ClinicalTrialUtilities.jl/badge.svg?branch=master)](https://coveralls.io/github/PharmCat/ClinicalTrialUtilities.jl?branch=master)
[![Latest docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://pharmcat.github.io/ClinicalTrialUtilities.jl/dev/)

## Difference since v0.3.0

Wrong Equivalence Hypothesis alpha level! Use 0.2.7 or 0.3.1 version.

## Description

The package is designed to perform calculations related to the planning and analysis of the results of clinical trials. The package includes the basic functions described below, as well as a few modules to perform specific calculations.
Expand Down
6 changes: 6 additions & 0 deletions cange.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.3.2
- bugfix fisher test
- add show
- propci for ConTab
- bump dependencies

v0.3.1

- deleteat! fix
Expand Down
4 changes: 4 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ When ctpower/ctsamplen used:
- :ei - Equivalencens: two one-sided hypothesis;
- :ns - Non-Inferiority / Superiority: one-sided hypothesis, for some cases you should use two-sided hypothesis for Non-Inferiority/Superiority, you can use alpha/2 for this;

## Invalidated version v0.3.0 (removed from release page)

Wrong Equivalence Hypothesis alpha level! Use 0.2.7, 0.3.1 version or higher.

## Contents

```@contents
Expand Down
62 changes: 54 additions & 8 deletions src/ci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ function propci(x::Int, n::Int; alpha::Real = 0.05, method = :default)::ConfInt
throw(ArgumentError("unknown method!"))
end
end
"""
propci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)
Confidence interval for proportions a / (a + b) and c / (c + d)
"""
function propci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)
d = Dict()
d[tab.row[1]] = propci(tab.a, tab.a + tab.b; alpha = alpha, method = method)
d[tab.row[2]] = propci(tab.c, tab.c + tab.d; alpha = alpha, method = method)
d
end
"""
diffpropci(x1::Int, n1::Int, x2::Int, n2::Int;
alpha::Real = 0.05, method::Symbol = :default)::ConfInt
Expand All @@ -162,18 +173,33 @@ Confidence interval for proportion difference.
# Computation methods:
- :nhs - Newcombes Hybrid (wilson) Score interval for the difference of proportions;
- :nhscc - Newcombes Hybrid Score CC;
- :ac - Agresti-Caffo interval for the difference of proportions;
- :mn | :default - Method of Mee 1984 with Miettinen and Nurminen modification;
- :mee | :fm - Mee maximum likelihood method;
- :wald - Wald CI without CC;
- :waldcc - Wald CI with CC;
- `:nhs` - Newcombes Hybrid (wilson) Score interval for the difference of proportions;
- `:nhscc` - Newcombes Hybrid Score CC;
- `:ac` - Agresti-Caffo interval for the difference of proportions;
- `:mn` | `:default` - Method of Mee 1984 with Miettinen and Nurminen modification;
- `:mee` | `:fm` - Mee maximum likelihood method;
- `:wald` - Wald CI without CC;
- `:waldcc` - Wald CI with CC;
# References
* nhs, nhscc - Newcombe RG (1998), Interval Estimation for the Difference Between Independent Proportions: Comparison of Eleven Methods. Statistics in Medicine 17, 873-890.
* ac - Agresti A, Caffo B., “Simple and effective confidence intervals for proportions and differences of proportions result from adding two successes and two failures”, American Statistician 54: 280–288 (2000)
* mn - Miettinen, O. and Nurminen, M. (1985), Comparative analysis of two rates. Statist. Med., 4: 213-226. doi:10.1002/sim.4780040211
* mee - Mee RW (1984) Confidence bounds for the difference between two probabilities, Biometrics40:1175-1176
* Brown, L.D., Cai, T.T., and DasGupta, A. Interval estimation for a binomial proportion.
Statistical Science, 16(2):101–117, 2001.
* Farrington, C. P. and Manning, G. (1990), “Test Statistics and Sample Size Formulae for Comparative Binomial Trials with Null Hypothesis of Non-zero Risk Difference or Non-unity Relative Risk,” Statistics in Medicine, 9, 1447–1454
* Li HQ, Tang ML, Wong WK. Confidence intervals for ratio of two Poisson rates using the methodof variance estimates recovery. Computational Statistics 2014; 29(3-4):869-889
* Brown, L., Cai, T., & DasGupta, A. (2003). INTERVAL ESTIMATION IN EXPONENTIAL FAMILIES. Statistica Sinica, 13(1), 19-49.
"""
function diffpropci(x1::Int, n1::Int, x2::Int, n2::Int; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
if alpha >= 1.0 || alpha <= 0.0
throw(ArgumentError("Alpha shold be > 0.0 and < 1.0"))
end
if x1 > n1 || x2 > n2
throw(ArgumentError("X cann't be more than N"))
end
if method == :nhs
return propdiffnhsci(x1, n1, x2, n2, alpha)
elseif method == :nhscc
Expand All @@ -194,7 +220,11 @@ function diffpropci(x1::Int, n1::Int, x2::Int, n2::Int; alpha::Real = 0.05, meth
throw(ArgumentError("Method unknown!"))
end
end
#TEST
"""
diffpropci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
Confidence interval for proportion difference: (a / (a + b)) - (c / (c + d))
"""
function diffpropci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
diffpropci(tab.a, tab.a + tab.b, tab.c, tab.c + tab.d; alpha = alpha, method = method)
end
Expand Down Expand Up @@ -226,6 +256,14 @@ function rrpropci(x1::Int, n1::Int, x2::Int, n2::Int; alpha::Real = 0.05, method
throw(ArgumentError("Method unknown!"))
end
end
"""
rrpropci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
Confidence interval for relative risk.
"""
function rrpropci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
rrpropci(tab.a, tab.a + tab.b, tab.c, tab.c + tab.d; alpha = alpha, method = method)
end
"""
orpropci(x1::Int, n1::Int, x2::Int, n2::Int; alpha::Real = 0.05,
method::Symbol = :default)::ConfInt
Expand Down Expand Up @@ -256,6 +294,14 @@ function orpropci(x1::Int, n1::Int, x2::Int, n2::Int; alpha::Real = 0.05, method
throw(ArgumentError("Method unknown!"))
end
end
"""
orpropci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
Confidence interval for odd ratio.
"""
function orpropci(tab::ConTab{2,2}; alpha::Real = 0.05, method::Symbol = :default)::ConfInt
orpropci(tab.a, tab.a + tab.b, tab.c, tab.c + tab.d; alpha = alpha, method = method)
end
"""
meanci(m::Real, σ²::Real, n::Int; alpha::Real = 0.05,
method=:default)::ConfInt
Expand Down
18 changes: 15 additions & 3 deletions src/freque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Base.getproperty(obj::ConTab{2, 2}, attr::Symbol)
elseif attr == :d
return getfield(obj, :tab)[2,2]
else
error("No field!")
return getfield(obj, attr)
end
end

Expand Down Expand Up @@ -129,7 +129,16 @@ function contab(data::DataFrame, sort; row::Symbol, col::Symbol)
end
return DataSet(result)
end
"""
contab(m; row = nothing, col = nothing)
Make contingency table.
"""
function contab(m::Matrix; row = nothing, col = nothing)
if isa(row, Nothing) row = Vector{Symbol}(undef, size(m, 1)) .= Symbol("") end
if isa(col, Nothing) col = Vector{Symbol}(undef, size(m, 2)) .= Symbol("") end
ConTab(m, row, col)
end
"""
mcnmcontab
"""
Expand Down Expand Up @@ -178,7 +187,7 @@ function pirson(a::Matrix{Int})
tm = sum(a, dims=1)[1,:]
tn = sum(a, dims=2)[:,1]
num = sum(tm)
ae = Array{Real, 2}(undef, n, m)
ae = Array{Float64, 2}(undef, n, m)
for im = 1:m
for in = 1:n
ae[in, im] = tn[in]*tm[im]/num
Expand All @@ -199,7 +208,10 @@ end

function fisher(a::Matrix{Int})
dist = Hypergeometric(sum(a[1, :]), sum(a[2, :]), sum(a[:, 1]))
value = min(2 * min(cdf(dist, a[1, 1]), ccdf(dist, a[1, 1])), 1.0)
l = cdf(dist, a[1, 1])
r = ccdf(dist, a[1, 1]-1)
value = min(2 * min(r, l), 1.0)
value, l, r
end
function fisher(t::ConTab{2, 2})
fisher(t.tab)
Expand Down
18 changes: 18 additions & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ function Base.show(io::IO, obj::ConfInt)
print(io, "Estimate: $(obj.estimate) ($(obj.lower) - $(obj.upper))")
end

#-------------------------------------------------------------------------------
# Frequences
function Base.show(io::IO, ct::ConTab{2, 2})
mx = Matrix{Any}(undef, 3, 3)
mx[2:3, 2:3] .= ct.tab
mx[2:3, 1] .= ct.row
mx[1, 2:3] .= ct.col
mx[1,1] = ""
println(io, "Contingency table 2X2")
println(io, "---------------------")
printmatrix(io, mx)
println(io, "---------------------")
if length(ct.sort) > 0
println(io, ct.sort)
end
end


#-------------------------------------------------------------------------------
# OUTPUT
function addspace(s::String, n::Int; first = false)::String
Expand Down
4 changes: 4 additions & 0 deletions test/freque.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ println(" ---------------------------------- ")
frtab = ClinicalTrialUtilities.freque(df; vars=:row, alpha = 0.05)
@test frtab[1,2] == 17

@test ClinicalTrialUtilities.fisher(ClinicalTrialUtilities.ConTab([12 23; 22 33]))[2] 0.3752579856319276

@test ClinicalTrialUtilities.pirson(ClinicalTrialUtilities.ConTab([12 23; 22 33]))[4] 0.5856943077831229


ctds = ClinicalTrialUtilities.contab(metadf, [:trial]; row = :group, col = :result)
cmht = ClinicalTrialUtilities.metaprop(ctds, type = :or, model = :fixed, zeroadj = 0.0, tau = :ho)
Expand Down
4 changes: 0 additions & 4 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,6 @@ println(" ---------------------------------- ")

@test ClinicalTrialUtilities.diffmcnmwaldccci(10, 20, 11, 15; alpha = 0.05).lower -0.04741054890998043

@test ClinicalTrialUtilities.fisher(ClinicalTrialUtilities.ConTab([12 23; 22 33])) 0.7505159712638552

@test ClinicalTrialUtilities.pirson(ClinicalTrialUtilities.ConTab([12 23; 22 33]))[4] 0.5856943077831229

@test ClinicalTrialUtilities.mcnmtest(ClinicalTrialUtilities.McnmConTab([12 23; 22 33]); cc = false) 0.022222222222222223

#= /*SAS Tesing code*/
Expand Down

2 comments on commit 4401c16

@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.3.2

  • bugfix fisher test
  • add show
  • propci for ConTab
  • bump dependencies

@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/25403

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 the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" 4401c1604910b10f94e5b36a1e7f6c7829dd9713
git push origin v0.3.2

Please sign in to comment.