Skip to content

Commit

Permalink
dropmissingsubj
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Jul 8, 2024
1 parent 03f085a commit 3e83e18
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "00e1d80e-504f-4d7b-946f-0aea2e7abfe3"
keywords = ["bioequivalence"]
desc = "Bioequivalence"
authors = ["Vladimir Arnautov <[email protected]>"]
version = "0.2.3"
version = "0.2.4"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
2 changes: 1 addition & 1 deletion src/MetidaBioeq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 22 additions & 1 deletion src/bioequivalence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
54 changes: 51 additions & 3 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e83e18

Please sign in to comment.