Skip to content

Commit

Permalink
Merge pull request #2 from PharmCat/dev
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
PharmCat authored Feb 16, 2023
2 parents 3190272 + b47d125 commit 6238f4e
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 131 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaStats"
uuid = "75cdad26-409a-4e43-8ad7-d54b4fa665a0"
authors = ["PharmCat <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]

Expand All @@ -13,7 +13,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
[compat]

StatsBase = "0.29, 0.30, 0.31, 0.32, 0.33"
MetidaBase = "0.9"
MetidaBase = "0.9, 0.10"
Distributions = "0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
julia = "1"

Expand Down
262 changes: 133 additions & 129 deletions src/descriptive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,147 +213,151 @@ function descriptives(data::DataSet{T}; kwargs...) where T <: ObsData
cicalk = false
q = NaN
end

#
ds = Vector{Descriptives}(undef, length(data))
i = 1
for d in data
# skipmissing
if kwargs[:skipmissing]
vec = skipnanormissing(d.obs)
else
vec = d.obs
end
n_ = length(vec)
if cicalk
if n_ > 1 q = quantile(TDist(n_ - 1), 1 - (1-kwargs[:level])/2) end
end
# skipnonpositive
logstats = makelogvec #calk logstats
if makelogvec
if kwargs[:skipnonpositive]
logvec = log.(skipnonpositive(d.obs))
ds[i] = Descriptives(d, descriptives_(d.obs, kwargs, makelogvec, cicalk))
i += 1
end
DataSet(identity.(ds))

end

function descriptives_(obsvec, kwargs, makelogvec, cicalk)
# skipmissing
if kwargs[:skipmissing]
vec = skipnanormissing(obsvec)
else
if kwargs[:skipmissing]
itr = skipnanormissing(d.obs)
if any(!ispositive, itr)
logvec = Float64[]
logstats = false
else
logvec = log.(itr)
end
vec = obsvec
end
n_ = length(vec)
if cicalk
if n_ > 1 q = quantile(TDist(n_ - 1), 1 - (1-kwargs[:level])/2) end
end
# skipnonpositive
logstats = makelogvec #calk logstats
if makelogvec
if kwargs[:skipnonpositive]
logvec = log.(skipnonpositive(obsvec))
else
if any(!ispositive, d.obs)
logvec = Float64[]
logstats = false
if kwargs[:skipmissing]
itr = skipnanormissing(obsvec)
if any(!ispositive, itr)
logvec = Float64[]
logstats = false
else
logvec = log.(itr)
end
else
logvec = log.(d.obs)
if any(!ispositive, obsvec)
logvec = Float64[]
logstats = false
else
logvec = log.(obsvec)
end
end
end
end
end
logn_ = length(skipnonpositive(d.obs))

result = Dict{Symbol, Float64}()

for s in kwargs[:stats]

if s == :n
result[s] = n_
elseif s == :posn
result[s] = logn_
elseif !(n_ > 0)
result[s] = NaN
continue
elseif s == :mean
result[s] = sum(vec) / n_
elseif s == :sd
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = std(vec; corrected = kwargs[:corrected], mean = result[:mean])
elseif s == :var
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = var(vec; corrected = kwargs[:corrected], mean = result[:mean])
elseif s == :bvar
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = var(vec; corrected = false, mean = result[:mean])
elseif s == :se
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = result[:sd] / sqrt(n_)
elseif s == :cv
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = abs(result[:sd] / result[:mean] * 100)
elseif s == :uci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = result[:mean] + q*result[:sd]
elseif s == :lci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = result[:mean] - q*result[:sd]
elseif s == :umeanci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
haskey(result, :se) || begin result[:se] = result[:sd] / sqrt(n_) end
result[s] = result[:mean] + q*result[:se]
elseif s == :lmeanci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
haskey(result, :se) || begin result[:se] = result[:sd] / sqrt(n_) end
result[s] = result[:mean] - q*result[:se]
elseif s == :median
result[s] = median(vec)
elseif s == :min
result[s] = minimum(vec)
elseif s == :max
result[s] = maximum(vec)
elseif s == :q1
result[s] = quantile(vec, 0.25)
elseif s == :q3
result[s] = quantile(vec, 0.75)
elseif s == :iqr
result[s] = abs(quantile(vec, 0.75) - quantile(vec, 0.25))
elseif s == :range
result[s] = abs(maximum(vec) - minimum(vec))
elseif s == :kurt
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = kurtosis_(vec, result[:mean])
elseif s == :skew
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = skewness_(vec, result[:mean])
elseif s == :harmmean
result[s] = harmmean(vec)
elseif s == :ses
result[s] = sesvec(vec)
elseif s == :sek
result[s] = sekvec(vec)
elseif s == :sum
result[s] = sum(vec)
elseif !logstats
result[s] = NaN
continue
elseif s == :logmean
result[s] = sum(logvec) / logn_
elseif s == :geom || s == :geomean
haskey(result, :logmean) || begin result[:logmean] = sum(logvec) / logn_ end
result[s] = exp(result[:logmean])
elseif s == :logvar
haskey(result, :logmean) || begin result[:logmean] = sum(logvec) / logn_ end
result[s] = var(logvec; corrected = kwargs[:corrected], mean = result[:logmean])
elseif s == :geocv
haskey(result, :logmean) || begin result[:logmean] = sum(logvec) / logn_ end
haskey(result, :logvar) || begin result[:logvar] = var(logvec; corrected = kwargs[:corrected], mean = result[:logmean]) end
result[s] = sqrt(exp(result[:logvar])-1)*100
logn_ = length(skipnonpositive(obsvec))

result = Dict{Symbol, Float64}()

for s in kwargs[:stats]

if s == :n
result[s] = n_
elseif s == :posn
result[s] = logn_
elseif !(n_ > 0)
result[s] = NaN
continue
elseif s == :mean
result[s] = sum(vec) / n_
elseif s == :sd
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = std(vec; corrected = kwargs[:corrected], mean = result[:mean])
elseif s == :var
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = var(vec; corrected = kwargs[:corrected], mean = result[:mean])
elseif s == :bvar
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = var(vec; corrected = false, mean = result[:mean])
elseif s == :se
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = result[:sd] / sqrt(n_)
elseif s == :cv
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = abs(result[:sd] / result[:mean] * 100)
elseif s == :uci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = result[:mean] + q*result[:sd]
elseif s == :lci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
result[s] = result[:mean] - q*result[:sd]
elseif s == :umeanci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
haskey(result, :se) || begin result[:se] = result[:sd] / sqrt(n_) end
result[s] = result[:mean] + q*result[:se]
elseif s == :lmeanci
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
haskey(result, :sd) || begin result[:sd] = std(vec; corrected = kwargs[:corrected], mean = result[:mean]) end
haskey(result, :se) || begin result[:se] = result[:sd] / sqrt(n_) end
result[s] = result[:mean] - q*result[:se]
elseif s == :median
result[s] = median(vec)
elseif s == :min
result[s] = minimum(vec)
elseif s == :max
result[s] = maximum(vec)
elseif s == :q1
result[s] = quantile(vec, 0.25)
elseif s == :q3
result[s] = quantile(vec, 0.75)
elseif s == :iqr
result[s] = abs(quantile(vec, 0.75) - quantile(vec, 0.25))
elseif s == :range
result[s] = abs(maximum(vec) - minimum(vec))
elseif s == :kurt
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = kurtosis_(vec, result[:mean])
elseif s == :skew
haskey(result, :mean) || begin result[:mean] = sum(vec) / n_ end
result[s] = skewness_(vec, result[:mean])
elseif s == :harmmean
result[s] = harmmean(vec)
elseif s == :ses
result[s] = sesvec(vec)
elseif s == :sek
result[s] = sekvec(vec)
elseif s == :sum
result[s] = sum(vec)
elseif !logstats
result[s] = NaN
continue
elseif s == :logmean
result[s] = sum(logvec) / logn_
elseif s == :geom || s == :geomean
haskey(result, :logmean) || begin result[:logmean] = sum(logvec) / logn_ end
result[s] = exp(result[:logmean])
elseif s == :logvar
haskey(result, :logmean) || begin result[:logmean] = sum(logvec) / logn_ end
result[s] = var(logvec; corrected = kwargs[:corrected], mean = result[:logmean])
elseif s == :geocv
haskey(result, :logmean) || begin result[:logmean] = sum(logvec) / logn_ end
haskey(result, :logvar) || begin result[:logvar] = var(logvec; corrected = kwargs[:corrected], mean = result[:logmean]) end
result[s] = sqrt(exp(result[:logvar]) - 1)*100
end
end
end
filter!(x -> x.first in kwargs[:stats], result)
ds[i] = Descriptives(d, result)
i += 1
end
DataSet(identity.(ds))
filter!(x -> x.first in kwargs[:stats], result)
result
end


function sesvec(vec)
ses(length(vec))
end
Expand Down

3 comments on commit 6238f4e

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

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

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.1.1 -m "<description of version>" 6238f4ecec12fc3f5a73cc605d2f8804fe6bc735
git push origin v0.1.1

Please sign in to comment.