Skip to content

Commit

Permalink
v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed May 22, 2021
1 parent 803e32c commit 916abee
Show file tree
Hide file tree
Showing 12 changed files with 661 additions and 109 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClinicalTrialUtilities"
uuid = "535c2557-d7d0-564d-8ff9-4ae146c18cfe"
authors = ["Vladimir Arnautov ([email protected])"]
version = "0.5.1"
version = "0.6.0"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
14 changes: 13 additions & 1 deletion change.log
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
v0.6.0
- changes in PK parameters names
- nca! administration settings
- adjust kel range for nca! with adm = :iv
- MRTtauinf used for Vsstau calculation
- changes in plots
- descriptive, CI add
- export fix
- DataSet sort!
- documentation
- nca tests

v0.5.1
- DataFrames 1
- SpecialFunctions 1

v0.5.0
- StableRNGs test
- StableRNGs test+
- rng keyword for randomtable, randomseq
- auc_sparse for PKSubject

Expand Down
66 changes: 66 additions & 0 deletions docs/src/nca.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,72 @@ NCA analysis based on following steps:
4. Exporting to DataFrame;
5. Descriptive statistics / HTML export.

### Description

```julia
include("ncatable.jl")
```
#### AUC

```math
AUC = \sum_{n=1}^N AUC_{n}
```

Where AUCn - partial AUC.

Linear trapezoidal rule

```math
AUC\mid_{t_1}^{t_2} = \delta t \times \frac{C_1 + C_2}{2}
AUMC\mid_{t_1}^{t_2} = \delta t \times \frac{t_1 \times C_1 + t_2 \times C_2}{2}
```

Logarithmic trapezoidal rule

```math
AUC\mid_{t_1}^{t_2} = \delta t \times \frac{ C_2 - C_1}{ln(C_2/C_1)}
AUMC\mid_{t_1}^{t_2} = \delta t \times \frac{t_2 \times C_2 - t_1 \times C_1}{ln(C_2/C_1)} - \delta t^2 \times \frac{ C_2 - C_1}{ln(C_2/C_1)^2}
```

Linear interpolation rule

```math
C_x = C_1 + \frac{(t_x-t_1)\times(C_2 - C_1)}{t_2 - t_1}
```

Logarithmic interpolation rule

```math
C_x = exp\left(ln(C_1) + \frac{(t_x-t_1)\times(ln(C_2) - ln(C_1))}{t_2 - t_1}\right)
```

#### \lambda_z - elimination constant

#### HL

```math
HL = ln(2) / \lambda_z
```

#### AUCinf

```math
AUCinf = AUClast + \frac{Clast}{\lambda_z}
```

#### AUMCinf

```math
AUMCinf = AUMClast + \frac{tlast\times Clast}{\lambda_z} + \frac{Clast}{\lambda_z^2}
```

#### Accumulation index

```math
Accind = \frac{1}{1 - exp(-\lambda_z \tau)}
```

### nca!
```@docs
Expand Down
1 change: 1 addition & 0 deletions docs/src/ncatable.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

5 changes: 5 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ function Base.deleteat!(a::DataSet{T}, inds::Dict) where T
return a
end

function Base.sort!(a::DataSet; by)
sort!(a.data; by = by)
a
end

################################################################################
#=
function Tables.istable(table::DataSet)
Expand Down
29 changes: 20 additions & 9 deletions src/descriptives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ Descriptive statistics.
function descriptive(data;
sort::Union{Symbol, Array{T,1}} = Array{Symbol,1}(undef,0),
vars = [],
stats::Union{Symbol, Array{T,1}, Tuple{Vararg{Symbol}}} = :default)::DataSet{Descriptive} where T <: Union{Symbol, String}
stats::Union{Symbol, Array{T,1}, Tuple{Vararg{Symbol}}} = :default, level = 0.95)::DataSet{Descriptive} where T <: Union{Symbol, String}

stats = checkstats(stats)

if isa(vars, UnitRange{Int64})
vars = names(data)[vars]
end
if isa(vars, Array) && length(vars) == 0
vars = filter(x -> x sort, names(data))
del = []
Expand All @@ -158,7 +160,7 @@ function descriptive(data;
#pushvardescriptive!(d, vars, Matrix(data[:,vars]), Dict(), stats)
mx = Matrix(data[:,vars])
for v = 1:length(vars) #For each variable in list
push!(d, Descriptive(vars[v], nothing, Dict(:Variable => v), descriptive_(mx[:, v], stats)))
push!(d, Descriptive(vars[v], nothing, Dict(:Variable => v), descriptive_(mx[:, v], stats, level)))
end
return DataSet(d)
end
Expand All @@ -173,30 +175,32 @@ function descriptive(data;
for v = 1:length(vars) #For each variable in list
dict = Dict{Symbol, Any}(sort .=> sortval)
dict[:Variable] = vars[v]
push!(d, Descriptive(vars[v], nothing, dict, descriptive_(mx[:, v], stats)))
push!(d, Descriptive(vars[v], nothing, dict, descriptive_(mx[:, v], stats, level)))
end
#pushvardescriptive!(d, vars, mx, sortval, stats) #push variable descriprives for mx
end
return DataSet(d)
end
function descriptive(data::Array{T, 1}; stats::Union{Symbol, Vector, Tuple} = :default, var = nothing, varname = nothing, sort = Dict())::Descriptive where T <: Real
function descriptive(data::Array{T, 1}; stats::Union{Symbol, Vector, Tuple} = :default, var = nothing, varname = nothing, sort = Dict(), level = 0.95)::Descriptive where T <: Real
stats = checkstats(stats)
return Descriptive(var, varname, sort, descriptive_(data, stats))
return Descriptive(var, varname, sort, descriptive_(data, stats, level))

end

"""
Check if all statistics in allstat list. return stats tuple
"""
@inline function checkstats(stats::Union{Symbol, Array{T,1}, Tuple{Vararg{Symbol}}})::Tuple{Vararg{Symbol}} where T <: Union{Symbol, String}
allstat = (:n, :min, :max, :range, :mean, :var, :sd, :sem, :cv, :harmmean, :geomean, :geovar, :geosd, :geocv, :skew, :ses, :kurt, :sek, :uq, :median, :lq, :iqr, :mode)
allstat = (:n, :min, :max, :range, :mean, :var, :sd, :sem, :cv, :harmmean, :geomean, :geovar, :geosd, :geocv, :skew, :ses, :kurt, :sek, :uq, :median, :lq, :iqr, :mode, :meanci)
if isa(stats, Symbol)
if stats == :default stats = (:n, :mean, :sd, :sem, :uq, :median, :lq)
elseif stats == :all stats = allstat
else stats = Tuple(stats) end
end
stats = Tuple(Symbol.(stats))
if any(x -> x allstat, stats) throw(ArgumentError("stats element not in allstat list")) end
if any(x -> x allstat, stats)
throw(ArgumentError("stats element ($(findall(x -> x allstat, stats))) not in allstat list"))
end
return stats
end
"""
Expand Down Expand Up @@ -237,7 +241,7 @@ 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
@inline function descriptive_(data::Vector{T}, stats::Union{Tuple{Vararg{Symbol}}, Array{Symbol,1}}, level) where T <: Real

#=
dlist = findall(x -> x === NaN || x === nothing || x === missing, data)
Expand Down Expand Up @@ -395,6 +399,13 @@ end
dict[s] = abs(duq-dlq)
elseif s == :mode
dict[s] = mode(data)
elseif s == :meanci
if dmean === nothing dmean = mean(data) end
if dvar === nothing dvar = var(data) end
if dn === nothing dn = length(data) end
e = sqrt(dvar/dn)*quantile(TDist(dn-1), 1-(1-level)/2)
dict[Symbol(string(s)*"L"*string(level))] = dmean-e
dict[Symbol(string(s)*"U"*string(level))] = dmean+e
end
end
return dict
Expand Down
2 changes: 1 addition & 1 deletion src/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ HTLM export.
while s
s = false
for r = 2:rown
if tablematrix[r,c] !=0 && data[r,c] === data[r-1,c]
if tablematrix[r,c] !=0 && !ismissing(data[r,c]) && !ismissing(data[r-1,c]) && data[r,c] == data[r-1,c]
tablematrix[r,c] -= 1;
tablematrix[r-1,c] += 1;
s = true;
Expand Down
Loading

2 comments on commit 916abee

@PharmCat
Copy link
Owner

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.6.0

  • changes in PK parameters names
  • nca! administration settings
  • adjust kel range for nca! with adm = :iv
  • MRTtauinf used for Vsstau calculation
  • changes in plots
  • descriptive, CI add
  • export fix
  • DataSet sort!
  • documentation
  • nca tests

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

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.6.0 -m "<description of version>" 916abee8a0bde1a762bc0c8b871696e7a86bd33b
git push origin v0.6.0

Please sign in to comment.