From de420e326520bd2626530f68fedc9e081dc2c33e Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:03:43 +0300 Subject: [PATCH 1/4] gha upd --- .github/workflows/Documenter.yml | 5 ++++- .github/workflows/Tier1.yml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index bd915ca..8fe81c1 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -22,9 +22,12 @@ jobs: Documenter: name: Documentation runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 40 steps: - uses: actions/checkout@v3 + - uses: julia-actions/setup-julia@v1 + with: + version: "1.8" - uses: julia-actions/julia-buildpkg@latest - uses: julia-actions/julia-docdeploy@latest env: diff --git a/.github/workflows/Tier1.yml b/.github/workflows/Tier1.yml index 032688a..70e36fb 100644 --- a/.github/workflows/Tier1.yml +++ b/.github/workflows/Tier1.yml @@ -23,7 +23,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: [1.6, 1.7, 1.8] + julia-version: [1.6, 1.8, 1] julia-arch: [x64] os: [ubuntu-latest, macOS-latest, windows-latest] steps: From 81db17869eae1c95ed3f7c51916b742fa763ffe5 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:59:42 +0300 Subject: [PATCH 2/4] doc upd --- docs/src/api.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/src/api.md b/docs/src/api.md index 9b3c86d..ebc6594 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -12,7 +12,6 @@ MetidaFreq.contab MetidaFreq.freq ``` - ## Contingency tables utilities ### MetidaFreq.addcol @@ -94,6 +93,12 @@ MetidaFreq.metapropfixed MetidaFreq.metaproprandom ``` +## Base + +### Base.getindex +```@docs +getindex +``` ## HypothesisTests @@ -111,3 +116,10 @@ HypothesisTests.MultinomialLRTest ```@docs HypothesisTests.FisherExactTest ``` + +## Experimental + +### MetidaFreq.oddsci +```@docs +MetidaFreq.oddsci +``` From 4bea3cb7b71da5774ae645c23de6dc6fee2a14af Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:28:43 +0300 Subject: [PATCH 3/4] frequdict, change freq --- .github/workflows/Documenter.yml | 2 +- Project.toml | 6 ++-- docs/src/api.md | 5 ++++ src/freq.jl | 49 +++++++++++++++++++++++++------- test/tests.jl | 13 +++++++-- 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index 8fe81c1..9d392c4 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -22,7 +22,7 @@ jobs: Documenter: name: Documentation runs-on: ubuntu-latest - timeout-minutes: 40 + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 diff --git a/Project.toml b/Project.toml index c72f6ad..c8b5cfd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MetidaFreq" uuid = "bd16ee1e-1b2f-4f89-b253-604a522f8c5f" authors = ["PharmCat "] -version = "0.1.5" +version = "0.2.0" [deps] @@ -18,11 +18,11 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [compat] CategoricalArrays = "0.8, 0.9, 0.10" -Distributions = "0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25" +Distributions = "0.20, 0.21, 0.22, 0.23, 0.24, 0.25" HypothesisTests = "0.10, 0.11" MetidaBase = "0.11, 0.12" Optim = "1" -Roots = "1, 2" +Roots = "2" StatsBase = "0.30, 0.31, 0.32, 0.33, 0.34" Tables = "1" julia = "1" diff --git a/docs/src/api.md b/docs/src/api.md index ebc6594..0b201bd 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -12,6 +12,11 @@ MetidaFreq.contab MetidaFreq.freq ``` +### MetidaFreq.freqdict +```@docs +MetidaFreq.freqdict +``` + ## Contingency tables utilities ### MetidaFreq.addcol diff --git a/src/freq.jl b/src/freq.jl index 75bd7a9..22fba7a 100644 --- a/src/freq.jl +++ b/src/freq.jl @@ -1,13 +1,11 @@ - """ - freq(data, col; id = Dict()) - + freqdict(data::AbstractVector) + +Return frequencies as `Dict`. """ -function freq(data, col; id = Dict()) - if isa(col, String) cols = Symbol(col) else cols = col end - column = Tables.getcolumn(data, cols) - d = Dict{eltype(column), Int}() - for i in column +function freqdict(data::AbstractVector) + d = Dict{eltype(data), Int}() + for i in data ind = ht_keyindex(d, i) if ind > 0 @inbounds d.vals[ind] += one(Int) @@ -15,10 +13,39 @@ function freq(data, col; id = Dict()) @inbounds d[i] = one(Int) end end + d +end + +""" + freq(data, col; id = Dict()) + +Return frequencies as ix1 contingency table. +""" +function freq(data, col; id = Dict()) + if isa(col, String) cols = Symbol(col) else cols = col end + column = Tables.getcolumn(data, cols) + d = freqdict(column) k = collect(keys(d)) - mx = Matrix{Int}(undef, 1, length(k)) + mx = Matrix{Int}(undef, length(k), 1 ) for i = 1:length(k) - @inbounds mx[1, i] = d[k[i]] + @inbounds mx[i, 1] = d[k[i]] end - ConTab(mx, [string(col)], string.(k), id) + ConTab(mx, string.(k), [string(col)], id) end + +""" + freq(data::AbstractVector; id = Dict()) + +Return frequencies as ix1 contingency table. +""" +function freq(data::AbstractVector; id = Dict()) + d = freqdict(data) + k = collect(keys(d)) + mx = Matrix{Int}(undef, length(k), 1) + for i = 1:length(k) + @inbounds mx[i, 1] = d[k[i]] + end + ConTab(mx, string.(k), [""], id) +end + + diff --git a/test/tests.jl b/test/tests.jl index ab33740..4c9d496 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -307,8 +307,17 @@ end ct = MetidaFreq.freq(freqdat, :row) @test ct.tab[1,1] == 26 - @test ct.tab[1,2] == 17 - @test size(ct) == (1,2) + @test ct.tab[2,1] == 17 + @test size(ct) == (2,1) + + ct = MetidaFreq.freq(freqdat[!, :row]) + @test ct.tab[1,1] == 26 + @test ct.tab[2,1] == 17 + @test size(ct) == (2,1) + + ctd = MetidaFreq.freqdict(freqdat[!, :row]) + @test ctd["w"] == 26 + @test ctd["q"] == 17 ct = MetidaFreq.contab(freqdat, :row, :col) @test ct.tab[1,1] == 21 From f7450d9152c82bab0db4074475986774a8c16714 Mon Sep 17 00:00:00 2001 From: PharmCat <13901158+PharmCat@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:59:20 +0300 Subject: [PATCH 4/4] upd --- docs/Project.toml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index b2e85d5..26c1ca7 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -10,10 +10,9 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -Documenter = "≥0.26" -MetidaFreq = "0.1" -HypothesisTests = "0.10" -CSV = "0.7, 0.8, 0.9, 0.10" +Documenter = "1" +HypothesisTests = "0.10, 0.11" +CSV = "0.9, 0.10" DataFrames = "1" PrettyTables = "2"