diff --git a/Project.toml b/Project.toml index edb8c08..db6b795 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,7 @@ uuid = "00e1d80e-504f-4d7b-946f-0aea2e7abfe3" keywords = ["bioequivalence"] desc = "Bioequivalence" authors = ["Vladimir Arnautov "] -version = "0.2.3" +version = "0.2.4" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" diff --git a/src/MetidaBioeq.jl b/src/MetidaBioeq.jl index fb4b03e..cb1f349 100644 --- a/src/MetidaBioeq.jl +++ b/src/MetidaBioeq.jl @@ -4,7 +4,7 @@ using MetidaNCA, Metida, GLM, MixedModels, DataFrames, CategoricalArrays, Distr import Base: show -export result, bioquivalence, estimate +export result, bioquivalence, estimate, makeseq include("types.jl") include("bioequivalence.jl") diff --git a/src/bioequivalence.jl b/src/bioequivalence.jl index d788127..ec4d249 100644 --- a/src/bioequivalence.jl +++ b/src/bioequivalence.jl @@ -33,6 +33,7 @@ end seqcheck::Bool = true, designcheck::Bool = true, dropcheck::Bool = true, + dropmissingsubj = false, info::Bool = true, warns::Bool = true, autoseq::Bool = false, @@ -49,6 +50,7 @@ end * `seqcheck` - check sequencs; * `designcheck` - check design correctness; * `dropcheck` - dropuot check; +* `dropmissingsubj` - drop subjects with missing data; * `info` - show information; * `warns` - show warnings; * `autoseq` - try to make sequence collumn; @@ -67,6 +69,7 @@ function bioequivalence(data; seqcheck::Bool = true, designcheck::Bool = true, dropcheck::Bool = true, + dropmissingsubj::Bool = false, info::Bool = true, warns::Bool = true, autoseq::Bool = false, @@ -188,7 +191,25 @@ function bioequivalence(data; if dropcheck if !isnothing(vars) && !nomissing(data, vars) info && @info "Dropuot(s) found in dataframe!" - dropout = true + if dropmissingsubj + droplists = map(x-> Set(data[findall(ismissing, data[!, x]), subject]), vars) + if all(x-> isequal(x, first(droplists)), droplists) + sbjdel = x -> x ∉ first(droplists) + data = filter(subject => sbjdel, data) + subjects = filter(sbjdel, subjects) + + subjnum = length(subjects) + obsnum = size(data, 1) + info && @info "Dropuot(s) removed!" + dropout = false + else + warns && @warn "Different subjects have missing values for different variables. Dropuot(s) NOT removed!" + dropout = true + end + + else + dropout = true + end elseif !isnothing(vars) info && @info "No dropuot(s) found in dataframe!" dropout = false diff --git a/test/tests.jl b/test/tests.jl index 87f655b..4aa20ec 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -6,6 +6,8 @@ io = IOBuffer(); rdsdict = Dict() rdsdict[1] = rds1 = bedf2x2 = CSV.File(joinpath(path, "csv", "2x2rds1.csv")) |> DataFrame + + transform!(bedf2x2, :Subj => categorical, renamecols = false) transform!(bedf2x2, :Per => categorical, renamecols = false) bedf2x2.logVar = log.(bedf2x2.Var) @@ -16,6 +18,13 @@ transform!(bedf2x2x4, :Period => categorical, renamecols = false) refvals = CSV.File(joinpath(path, "csv", "ciref.csv")) |> DataFrame + +rds1missing = allowmissing!(deepcopy(rds1), [:Var, :logVar]) +rds1missing[1, :Var] = missing +rds1missing[36, :Var] = missing +rds1missing[1, :logVar] = missing +rds1missing[36, :logVar] = missing + @testset " Basic test" begin @test MetidaBioeq.nomissing(bedf2x2x4, :logVar) == false @@ -68,8 +77,6 @@ refvals = CSV.File(joinpath(path, "csv", "ciref.csv")) |> DataFrame @test beres.method == "B" @test beres.estimator== "mm" - - # Crossover design 2X2 # be2 = MetidaBioeq.bioequivalence(bedf2x2, @@ -168,7 +175,48 @@ refvals = CSV.File(joinpath(path, "csv", "ciref.csv")) |> DataFrame @test_nowarn MetidaBioeq.estimate(be2; estimator = "mm", method = "B") @test_nowarn MetidaBioeq.estimate(be2; estimator = "met", method = "B") -end + # Drop missing + # no drop + bedm = MetidaBioeq.bioequivalence(rds1missing, + vars = [:Var, :logVar], + subject = :Subj, + formulation = :Trt, + reference = "R", + period = :Per, + sequence = :Seq, + autoseq = true) + + @test bedm.dropout + @test length(bedm.subjects) == 18 + + bedm = MetidaBioeq.bioequivalence(rds1missing, + vars = [:Var, :logVar], + subject = :Subj, + formulation = :Trt, + reference = "R", + period = :Per, + sequence = :Seq, + autoseq = true, + dropmissingsubj = true) + + @test bedm.dropout == false + @test length(bedm.subjects) == 16 + + rds1missing[2, :Var] = missing + @test_warn "Different subjects have missing values for different variables. Dropuot(s) NOT removed!" bedm = MetidaBioeq.bioequivalence(rds1missing, + vars = [:Var, :logVar], + subject = :Subj, + formulation = :Trt, + reference = "R", + period = :Per, + sequence = :Seq, + autoseq = true, + dropmissingsubj = true) + + @test bedm.dropout + @test length(bedm.subjects) == 18 + +end # end Basic tests rdsdict[2] = CSV.File(joinpath(path, "csv", "2x2rds2.csv")) |> DataFrame rdsdict[3] = CSV.File(joinpath(path, "csv", "2x2rds3.csv")) |> DataFrame