Skip to content

Commit

Permalink
Merge pull request #7 from PharmCat/dev
Browse files Browse the repository at this point in the history
gha upd
  • Loading branch information
PharmCat authored Apr 2, 2024
2 parents 4c9b14f + 82d7716 commit c67baef
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MetidaFreq"
uuid = "bd16ee1e-1b2f-4f89-b253-604a522f8c5f"
authors = ["PharmCat <[email protected]>"]
version = "0.1.5"
version = "0.2.0"

[deps]

Expand All @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

17 changes: 17 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ MetidaFreq.contab
MetidaFreq.freq
```

### MetidaFreq.freqdict
```@docs
MetidaFreq.freqdict
```

## Contingency tables utilities

Expand Down Expand Up @@ -94,6 +98,12 @@ MetidaFreq.metapropfixed
MetidaFreq.metaproprandom
```

## Base

### Base.getindex
```@docs
getindex
```

## HypothesisTests

Expand All @@ -111,3 +121,10 @@ HypothesisTests.MultinomialLRTest
```@docs
HypothesisTests.FisherExactTest
```

## Experimental

### MetidaFreq.oddsci
```@docs
MetidaFreq.oddsci
```
49 changes: 38 additions & 11 deletions src/freq.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@

"""
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)
else
@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


13 changes: 11 additions & 2 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c67baef

Please sign in to comment.