Skip to content

Commit

Permalink
Merge pull request #15 from markgpritchard/v0_2_2
Browse files Browse the repository at this point in the history
minor changes; update Julia versions used in automatic testing
  • Loading branch information
markgpritchard authored Nov 12, 2024
2 parents 9b18370 + 7e73692 commit 89abc1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ jobs:
matrix:
version:
- '1.6'
- '1.9'
- '1.10'
- '1.11'
- 'nightly'
os:
- ubuntu-latest
Expand Down
49 changes: 15 additions & 34 deletions src/TableOne.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ end

# If no strata supplied, default to showing totals column only
tableone(data, vars::Vector; kwargs...) = tableone(data, nothing, vars; kwargs...)

tableone(data; kwargs...) = tableone(data, nothing; kwargs...)

function tableone(data, strata::Nothing, vars::Vector; addtotal=true, kwargs...)
function tableone(data, ::Nothing, vars::Vector; addtotal=true, kwargs...)
stratanames = String[ ]
return _tableone(
data, strata, vars, stratanames;
data, nothing, vars, stratanames;
addtotal, includemissingintotal=true, kwargs...
)
end
Expand Down Expand Up @@ -111,13 +110,11 @@ function _tableone(
ids = findall(!ismissing, getproperty(data, strata))
push!(strataids, :Total => ids)
end

if addtotal
ids = strataids[:Total]
n = length(ids)
insertcols!(table1, :Total => [ "$n" ])
end

if addnmissing
if addtotal && includemissingintotal
# then all records are included in the `Total` column so nothing is missing
Expand Down Expand Up @@ -159,9 +156,7 @@ function _tableone_novars(
end

function _tableone_novars(
data, strata,
binvars::Nothing, catvars::Nothing, npvars::Nothing,
paramvars::Nothing, cramvars::Nothing;
data, strata, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing;
kwargs...
)
alldfvars = Symbol.(names(data))
Expand Down Expand Up @@ -203,9 +198,9 @@ function _tableone_novars(
)
end

__tableone_novars_var(var::Nothing, S) = S[ ]
__tableone_novars_var(var, S) = [ var ]
__tableone_novars_var(var::AbstractVector, S) = var
__tableone_novars_var(::Nothing, S) = S[ ]
__tableone_novars_var(var, ::Any) = [ var ]
__tableone_novars_var(var::AbstractVector, ::Any) = var

# Variables can be listed as Symbols or Strings, but need to be consistent. Functions
# to check this consistency and make sure all lists are vectors
Expand Down Expand Up @@ -330,25 +325,21 @@ function ___catvariable(
ids = strataids[Symbol(sn)]
_catvariable!(_t, varvect, levels, ids, sn, pmatrix, i; kwargs...)
end

if addtotal
ids = strataids[:Total]
_catvariable!(_t, varvect, levels, ids, "Total", nothing, nothing; kwargs...)
end

if addnmissing _addnmissing!(_t, varvect, strataids) end

_addcatpvalue!(_t, pmatrix; kwargs...)
return _t
end

function _catvariable!(_t::DataFrame, varvect, levels, stratumids, sn, pmatrix, i; kwargs...)
estimates::Vector{String} = [ "" ]

for (j, lev) enumerate(levels)
__catvariable!(estimates, varvect, lev, stratumids, pmatrix, i, j; kwargs...)
end

insertcols!(_t, Symbol(sn) => estimates)
end

Expand Down Expand Up @@ -429,7 +420,7 @@ end

function _npvariable!(_t, varvect, ids, sn; digits=1, kwargs...)
med = median(skipmissing(varvect[ids]))
iqr = quantile(skipmissing(varvect[ids]), [.25, .75])
iqr = quantile(skipmissing(varvect[ids]), [ 0.25, 0.75 ])
_med = "$(sprint(show, round(med; digits)))"
_iqr = "$(sprint(show, round(iqr[1]; digits)))$(sprint(show, round(iqr[2]; digits)))"
estimates::Vector{String} = [ "$_med [$_iqr]" ]
Expand Down Expand Up @@ -542,7 +533,6 @@ function _contvariable(
else
pvectors = nothing
end

return _contvariable(
addfn, pfn, strata, stratanames, strataids, varvect, varname, pvectors;
kwargs...
Expand Down Expand Up @@ -570,7 +560,7 @@ function _contvariable(
return _t
end

_getvarname(var, varnames::Nothing) = String(var)
_getvarname(var, ::Nothing) = String(var)

function _getvarname(var, varnames::Dict)
if var keys(varnames)
Expand All @@ -594,7 +584,7 @@ function _countmissing(varvect, strataids, sn=:Total)
return n
end

_binvariabledisplay(v, varvect, binvardisplay::Nothing) = maximum(skipmissing(unique(varvect)))
_binvariabledisplay(::Any, varvect, ::Nothing) = maximum(skipmissing(unique(varvect)))

function _binvariabledisplay(v, varvect, binvardisplay::Dict)
if v keys(binvardisplay)
Expand All @@ -604,23 +594,18 @@ function _binvariabledisplay(v, varvect, binvardisplay::Dict)
end
end

_catvarpmatrix!(pmatrix::Nothing, n, i, j) = nothing
_catvarpmatrix!(::Nothing, ::Any, ::Any, ::Any) = nothing
_catvarpmatrix!(pmatrix::Matrix{<:Integer}, n::Int, i::Int, j::Int) = pmatrix[j, i] = n
_contpvectors!(pvectors::Nothing, newvect) = nothing
_contpvectors!(::Nothing, ::Any) = nothing
_contpvectors!(pvectors::Vector, newvect) = push!(pvectors, newvect)
_addcatpvalue!(_t, pmatrix::Nothing; kwargs...) = nothing
_addcatpvalue!(::Any, ::Nothing; kwargs...) = nothing

function _addcatpvalue!(_t, pmatrix::Matrix{<:Integer}; kwargs...)
@unpack p, testname = _catpvalue(pmatrix)
_addpvalue!(_t, p, testname; kwargs...)
end

function _addbinpvalue!(
_t, pmatrix::Nothing, stratanames, strataids, varvect, level;
kwargs...
)
return nothing
end
_addbinpvalue!(::Any, ::Nothing, ::Any, ::Any, ::Any, ::Any; kwargs...) = nothing

function _addbinpvalue!(
_t, pmatrix::Matrix{<:Integer}, stratanames, strataids, varvect, level;
Expand All @@ -631,12 +616,11 @@ function _addbinpvalue!(
@unpack n, denom = _catvalues(varvect, level, stratumids)
pmatrix[2, i] = denom - n
end

@unpack p, testname = _catpvalue(pmatrix)
_addpvalue!(_t, p, testname; kwargs...)
end

_addcontpvalue!(_t, func, pvectors::Nothing; kwargs...) = nothing
_addcontpvalue!(::Any, ::Any, ::Nothing; kwargs...) = nothing

function _addcontpvalue!(_t, func, pvectors; kwargs...)
p = pvalue(func(pvectors...))
Expand All @@ -647,7 +631,6 @@ function _addpvalue!(_t, p, testname; addtestname, pdigits, kwargs...)
pcol = [ "" for _ axes(_t, 1) ]
pcol[1] = "$(sprint(show, round(p; digits = pdigits)))"
insertcols!(_t, :p => pcol)

if addtestname _addtestname!(_t, testname) end
end

Expand All @@ -662,7 +645,6 @@ function _addtestname!(_t, testname::AbstractString)
else
tn = testname
end

tncol = [ "" for _ axes(_t, 1) ]
tncol[1] = tn
insertcols!(_t, :test => tncol)
Expand All @@ -676,7 +658,6 @@ function _catpvalue(pmatrix)
p = pvalue(ChisqTest(pmatrix))
testname = ChisqTest
end

return ( p=p, testname=testname )
end

Expand Down

0 comments on commit 89abc1c

Please sign in to comment.