Skip to content

Commit

Permalink
Merge pull request #37 from PharmCat/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
PharmCat authored Feb 13, 2020
2 parents b75af11 + aacf162 commit e2bc589
Show file tree
Hide file tree
Showing 13 changed files with 639 additions and 207 deletions.
7 changes: 5 additions & 2 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.2.2"
version = "0.2.3"

[deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -12,6 +12,8 @@ QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

[extras]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand All @@ -25,9 +27,10 @@ test = ["CSV", "Test", "Plots"]
julia = "1.0, 1.1, 1.2, 1.3"
Distributions = "0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22"
StatsBase = "0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31, 0.32"
DataFrames = "0.19"
DataFrames = "0.19, 0.20"
QuadGK = "2.0, 2.1"
SpecialFunctions = "0.8, 0.9"
Roots = "0.7, 0.8"
CSV = "0.5"
RecipesBase = "0.7"
Reexport = "0.1, 0.2"
10 changes: 9 additions & 1 deletion cange.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v0.2.3

- ConTab struct
- Urine PK
- NCA Tau PK partial areas fix
- NCA test update
- Plotting improve
- minor fix


v0.2.2
- Distributions bump
Expand All @@ -8,7 +17,6 @@ v0.2.2
- fisher & pirson non-public methods for frequencies
- add Show methods
- minor fix
- cosmetics
- add sim
- cosmetics

Expand Down
10 changes: 7 additions & 3 deletions src/ClinicalTrialUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
# If you want to check and get R code you can find some here: http://powerandsamplesize.com/Calculators/
__precompile__(true)
module ClinicalTrialUtilities
using Distributions, StatsBase, Random, Roots, QuadGK, DataFrames, RecipesBase

using Distributions, Random, Roots, QuadGK, RecipesBase, Reexport

@reexport using StatsBase

import SpecialFunctions
import Base.show
import Base.showerror
import Base.getindex
import Base.length
import Base.in
import Base.iterate
import Base.eltype
import StatsBase.confint
import DataFrames.DataFrame

import DataFrames: DataFrame, DataFrames, names!, unstack, deleterows!

function lgamma(x)
return SpecialFunctions.logabsgamma(x)[1]
Expand Down
3 changes: 3 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ end
function Base.iterate(iter::DataSet, i::Int)
return Base.iterate(iter.data, i)
end
function Base.eltype(obj::DataSet)
return eltype(obj.data)
end
10 changes: 9 additions & 1 deletion src/descriptives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,21 @@ end

#Statistics calculation

@inline function descriptive_(data::Array{T,1}, stats::Union{Tuple{Vararg{Symbol}}, Array{Symbol,1}}) where T <: Real
function notnan(x)
return !(x === NaN || x === nothing || x === missing)
end

@inline function descriptive_(data::Vector{T}, stats::Union{Tuple{Vararg{Symbol}}, Array{Symbol,1}}) where T <: Real

#=
dlist = findall(x -> x === NaN || x === nothing || x === missing, data)
if length(dlist) > 0
data = copy(data)
deleteat!(data, dlist)
end
=#

data = data[notnan.(data)]

dn = nothing
dmin = nothing
Expand Down
60 changes: 46 additions & 14 deletions src/freque.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@


struct ConTab{Int32, Int32}
tab::Matrix{Int}
row::Vector
col::Vector

function ConTab(m::Matrix{Int})
row = Vector{Symbol}(undef, size(m, 1)) .= Symbol("")
col = Vector{Symbol}(undef, size(m, 2)) .= Symbol("")
new{size(m, 1), size(m, 2)}(m, row, col)
end
function ConTab(m::Matrix{Int}, row, col)
new{size(m, 1), size(m, 2)}(m, row, col)
end
end

struct Freque
val
n
end


function freque(data::DataFrame; vars::Symbol, alpha = 0.05)::DataFrame
result = DataFrame(value = Any[], n = Int[], p = Float64[], cil = Float64[], ciu = Float64[])
list = unique(data[:, vars])
Expand All @@ -12,46 +34,56 @@ function freque(data::DataFrame; vars::Symbol, alpha = 0.05)::DataFrame
return result
end

function contab(data::DataFrame; row::Symbol, col::Symbol)::Matrix
function contab(data::DataFrame; row::Symbol, col::Symbol)::ConTab
clist = unique(data[:, col])
rlist = unique(data[:, row])
cn = length(clist)
rn = length(rlist)
dfs = Array{Int, 2}(undef, rn, cn)
dfs = Matrix{Int}(undef, rn, cn)
for ri = 1:rn
rowl = data[data[:, row] .== rlist[ri], col]
for ci = 1:cn
cnt = count(x -> x == clist[ci], rowl)
dfs[ri, ci] = cnt
end
end
return dfs
return ConTab(dfs, rlist, clist)
end


function pirson(a::Matrix{Int})
n = length(a[:,1])
m = length(a[1,:])
tm = sum(a, dims=1)[1,:]
tn = sum(a, dims=2)[:,1]
n = length(a[:,1])
m = length(a[1,:])
tm = sum(a, dims=1)[1,:]
tn = sum(a, dims=2)[:,1]
num = sum(tm)
ae = Array{Real, 2}(undef, n, m)
ae = Array{Real, 2}(undef, n, m)
for im = 1:m
for in = 1:n
ae[in, im] = tn[in]*tm[im]/num
end
end
chsq = sum(((a .- ae) .^2 ) ./ ae)
chsq = sum(((a .- ae) .^2 ) ./ ae)
chsqy = sum(((abs.((a .- ae)) .- 0.5) .^2 ) ./ ae)
ml = 2 * sum( a .* log.( a ./ ae ))
df = (n - 1)*(m - 1)
ϕ = sqrt(chsq / (num*(n - 1)*(m - 1)))
C = sqrt(chsq/(chsq+num))
K = sqrt(chsq/num/sqrt((n - 1)*(m - 1)))
ml = 2 * sum( a .* log.( a ./ ae ))
df = (n - 1)*(m - 1)
ϕ = sqrt(chsq / (num*(n - 1)*(m - 1)))
C = sqrt(chsq/(chsq+num))
K = sqrt(chsq/num/sqrt((n - 1)*(m - 1)))
return chsq, chsqy, ml, 1-cdf(Chisq(df), chsq)
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)
end


function fisher(t::ConTab{2, 2})
fisher(t.tab)
end

#=
function StatsBase.confint(t::ConTab{2, 2})
end
=#
Loading

2 comments on commit e2bc589

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

  • ConTab struct
  • Urine PK
  • NCA Tau PK partial areas fix & validate
  • NCA test update
  • Plotting improve
  • minor fix

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

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.3 -m "<description of version>" e2bc5891719765f1d3d7cded1846b958acbd82a5
git push origin v0.2.3

Please sign in to comment.