Skip to content

Commit

Permalink
add categorise (#7)
Browse files Browse the repository at this point in the history
* add categorise

- categorise method for continuouscomposites and faceted modifications
- added tests

* add docstring to categorise
  • Loading branch information
simonsteiger authored Jul 29, 2024
1 parent f8543d6 commit 47498b4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/RheumaComposites.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export weight
export score
export isremission
export decompose
export categorise

include("utils/units.jl")
include("utils/valid.jl")
Expand All @@ -36,6 +37,6 @@ include("utils/weight.jl")
include("utils/score.jl")
include("utils/remission.jl")
include("utils/decompose.jl")
# include("utils/categorise.jl")
include("utils/categorise.jl")

end
54 changes: 54 additions & 0 deletions src/utils/categorise.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function categorise(::Type{DAS28CRP}, v)
out = v < 2.4 ? "Remission" :
v <= 2.9 ? "Low" :
v <= 4.6 ? "Moderate" :
"High"
return out
end

function categorise(::Type{DAS28ESR}, v)
out = v < 2.6 ? "Remission" :
v <= 3.2 ? "Low" :
v <= 5.1 ? "Moderate" :
"High"
return out
end

function categorise(::Type{SDAI}, v)
out = v < 3.3 ? "Remission" :
v <= 11.0 ? "Low" :
v <= 26.0 ? "Moderate" :
"High"
return out
end

"""
categorise(x::ContinuousComposite)
Convert `x` to a discrete value.
# Examples
```jldoctest
julia> DAS28ESR(t28=4, s28=5, pga=12u"mm", apr=44u"mm/hr") |> categorise
"Moderate"
```
categorise(::Type{SDAI}, v)
Convert `v` to a discrete value using `SDAI` thresholds.
The same functionality exists for other `ContinuousComposites`.
See also [`DAS28ESR`](@ref), [`DAS28CRP`](@ref).
# Examples
```jldoctest
julia> categorise(SDAI, 3.6)
"Low"
```
"""
categorise(x::ContinuousComposite) = categorise(typeof(x), score(x))

categorise(x::Faceted{<:ContinuousComposite}) = categorise(typeof(x.c0), score(x.c0))
14 changes: 14 additions & 0 deletions test/types/das28.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ end
@test sum(decompose(faceted(das28e, facets), digits=5)) 1.0 atol = 1e-5
end

@testset "Categorise DAS28ESR" begin
@test categorise(das28e) == "Moderate"
@test categorise.(DAS28ESR, [2.59, 2.61]) == ["Remission", "Low"]
@test categorise.(DAS28ESR, [3.19, 3.21]) == ["Low", "Moderate"]
@test categorise.(DAS28ESR, [5.09, 5.11]) == ["Moderate", "High"]
end

@testset "Construct DAS28CRP" begin
@test das28c isa AbstractComposite
@test das28c isa ContinuousComposite
Expand Down Expand Up @@ -82,3 +89,10 @@ end
@test score(faceted(das28c, facets)) == score(das28c)
@test sum(decompose(faceted(das28c, facets), digits=5)) 1.0 atol = 1e-5
end

@testset "Categorise DAS28CRP" begin
@test categorise(das28c) == "Moderate"
@test categorise.(DAS28CRP, [2.39, 2.51]) == ["Remission", "Low"]
@test categorise.(DAS28CRP, [2.89, 2.91]) == ["Low", "Moderate"]
@test categorise.(DAS28CRP, [4.59, 4.61]) == ["Moderate", "High"]
end
7 changes: 7 additions & 0 deletions test/types/sdai.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ end
@test isremission(sdai)
@test !isremission(SDAI(t28=3, s28=4, pga=4u"cm", ega=4u"cm", crp=5u"mg/dL"))
end

@testset "Categorise SDAI" begin
@test categorise(sdai) == "Remission"
@test categorise.(SDAI, [3.29, 3.31]) == ["Remission", "Low"]
@test categorise.(SDAI, [10.99, 11.01]) == ["Low", "Moderate"]
@test categorise.(SDAI, [25.99, 26.01]) == ["Moderate", "High"]
end

0 comments on commit 47498b4

Please sign in to comment.