Skip to content

Commit

Permalink
v0.6.4 types fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jan 13, 2022
1 parent ebedf6f commit b015fe5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 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 (mail@pharmcat.net)"]
version = "0.6.3"
version = "0.6.4"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
8 changes: 4 additions & 4 deletions src/ci.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
# metafor by Wolfgang Viechtbauer https://cran.r-project.org/package=metafor

struct ConfInt
lower::Real
upper::Real
estimate::Real
alpha::Real
lower::Float64
upper::Float64
estimate::Float64
alpha::Float64
#method::Symbol
function ConfInt(lower, upper, estimate)
new(lower, upper, estimate, NaN)::ConfInt
Expand Down
1 change: 0 additions & 1 deletion src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function Base.getindex(a::DataSet{T}, d::Tuple{Vararg{Pair}})::T where T
return a[Dict(d)]
end


function Base.getindex(a::DataSet{T}, i::Int, s::Symbol)::Real where T
return a.data[i].result[s]
end
Expand Down
27 changes: 13 additions & 14 deletions src/descriptives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Base.show(io::IO, obj::Descriptive)
end


function Base.getindex(a::Descriptive, s::Symbol)::Real
function Base.getindex(a::Descriptive, s::Symbol)
return a.result[s]
end

Expand Down Expand Up @@ -117,7 +117,7 @@ end
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 = :default)::DataSet{Descriptive} where T <: Union{Symbol, String}
Descriptive statistics.
Expand All @@ -126,9 +126,9 @@ Descriptive statistics.
- ``stats`` statistics
"""
function descriptive(data;
sort::Union{Symbol, Array{T,1}} = Array{Symbol,1}(undef,0),
sort::Union{Symbol, Vector{T}} = Vector{Symbol}(undef,0),
vars = [],
stats::Union{Symbol, Array{T,1}, Tuple{Vararg{Symbol}}} = :default, level = 0.95)::DataSet{Descriptive} where T <: Union{Symbol, String}
stats = :default, level = 0.95)::DataSet{Descriptive} where T <: Union{Symbol, String}

stats = checkstats(stats)
if isa(vars, UnitRange{Int64})
Expand Down Expand Up @@ -181,16 +181,15 @@ function descriptive(data;
end
return DataSet(d)
end
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
function descriptive(data::Vector{T}; stats = :default, var = nothing, varname = nothing, sort = Dict(), level = 0.95) where T <: Real
stats = checkstats(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}
@inline function checkstats(stats)
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)
Expand All @@ -206,15 +205,15 @@ end
"""
Push in d Descriptive obj in mx vardata
"""
@inline function pushvardescriptive!(d::Array{Descriptive, 1}, vars::Array{Symbol, 1}, mx, sortval::Union{Tuple{Vararg{Any}}, Nothing}, stats::Tuple{Vararg{Symbol}}) where T<: Real
@inline function pushvardescriptive!(d::Vector{Descriptive}, vars::Vector{Symbol}, mx, sortval, stats)
for v = 1:length(vars) #For each variable in list
push!(d, Descriptive(vars[v], nothing, sortval, descriptive_(mx[:, v], stats)))
end
end
"""
Check if data row sortcol equal sortval
"""
@inline function checksort(data, row::Int, sortcol::Array{Symbol, 1}, sortval::Tuple{Vararg{Any}})::Bool
@inline function checksort(data, row::Int, sortcol::Vector{Symbol}, sortval)
for i = 1:length(sortcol)
if data[row, sortcol[i]] != sortval[i] return false end
end
Expand All @@ -223,7 +222,7 @@ end
"""
Return matrix of filtered data (datacol) by sortcol with sortval
"""
@inline function getsortedmatrix(data; datacol::Array{Symbol,1}, sortcol::Array{Symbol,1}, sortval::Tuple{Vararg{Any}})
@inline function getsortedmatrix(data; datacol::Vector{Symbol}, sortcol::Vector{Symbol}, sortval)
result = Array{promote_type(eltype.(data[!, c] for c in datacol)...), 1}(undef, 0)
for c = 1:size(data, 1) #For each line in data
if checksort(data, c, sortcol, sortval)
Expand All @@ -241,7 +240,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}}, level) where T
@inline function descriptive_(data::Vector{T}, stats, level) where T

#=
dlist = findall(x -> x === NaN || x === nothing || x === missing, data)
Expand Down Expand Up @@ -275,7 +274,7 @@ end



dict = Dict{Symbol, Real}()
dict = Dict{Symbol, Float64}()


if length(data) == 0
Expand Down Expand Up @@ -419,10 +418,10 @@ end
return sqrt(6 * n *(n - 1) / ((n - 2) * (n + 1) * (n + 3)))
end

@inline function sek(data::AbstractVector; ses::T = ses(data)) where T <: Real
@inline function sek(data::AbstractVector; ses = ses(data))
n = length(data)
sek(n; ses = ses)
end
@inline function sek(n::Int; ses::T = ses(n)) where T <: Real
@inline function sek(n::Int; ses = ses(n))
return 2 * ses * sqrt((n * n - 1)/((n - 3) * (n + 5)))
end

2 comments on commit b015fe5

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

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.4 -m "<description of version>" b015fe5a3f403b179dda79be9c9a86bb18464261
git push origin v0.6.4

Please sign in to comment.