Example

using MetidaBioeq, CSV, DataFrames, CategoricalArrays;

bedf2x2 = CSV.File(joinpath(dirname(pathof(MetidaBioeq)), "..", "test", "csv",  "2x2rds1.csv")) |> DataFrame
transform!(bedf2x2, :Subj => categorical, renamecols = false)
transform!(bedf2x2, :Per => categorical, renamecols = false)
bedf2x2.logVar = log.(bedf2x2.Var)

bedf2x2x4 = CSV.File(joinpath(dirname(pathof(MetidaBioeq)), "..", "test", "csv",  "2x2x4rds1.csv")) |> DataFrame
transform!(bedf2x2x4, :Subject => categorical, renamecols = false)
transform!(bedf2x2x4, :Period => categorical, renamecols = false)

Data

bedf2x2[1:5, :]
5×6 DataFrame
RowSubjSeqPerTrtVarlogVar
Cat…String3Cat…String1Float64Float64
13TR1T225.955.42031
21RT1R181.095.19899
32RT1R114.484.7404
44RT1R176.915.17564
55TR1T147.014.9905

BE object

Simple 2x2 study. Data (var) not log-transgormed.

    be1 = MetidaBioeq.bioequivalence(bedf2x2,
    vars = :Var,
    subject = :Subj,
    formulation = :Trt,
    period = :Per,
    sequence = :Seq,
    reference = "R",
    design = "2x2",
    autoseq = true,
    logt = false)
Bioequivalence object:
Design: 2X2X2
Dropouts: false
Subject: Subj (18)
Formulation: Trt (InlineStrings.String1["R", "T"]) (R, T) Ref: R
Period: Per ([1, 2])
Sequence: Seq (InlineStrings.String3["TR", "RT"])

Replicate design 2x2x4 study. Data (logVat) already log-transformed.

    be2 = MetidaBioeq.bioequivalence(bedf2x2x4,
    vars = :logVar,
    subject = :Subject,
    formulation = :Formulation,
    period = :Period,
    sequence = :Sequence,
    reference = "R",
    autoseq = true,
    logt = true)
Bioequivalence object:
Design: 2X2X4
Dropouts: true
Subject: Subject (77)
Formulation: Formulation (InlineStrings.String1["R", "T"]) (R, T) Ref: R
Period: Period ([1, 2, 3, 4])
Sequence: Sequence (InlineStrings.String7["RTRT", "TRTR"])

Estimation

GLM

Estimation witn GLM (simple model).

    beAglm  = MetidaBioeq.estimate(be1;  estimator = "glm", method = "A")
  Result:
1×11 DataFrame
 Row  Parameter   Metric    PE          SE        DF       lnLCI       lnUCI  ⋯
     │ String      String    Float64     Float64   Float64  Float64     Float6 ⋯
─────┼──────────────────────────────────────────────────────────────────────────
   1 │ Trt: T - R  log(Var)  -0.0503868  0.026658     16.0  -0.0969286  -0.003 ⋯
                                                               5 columns omitted
Estimator: glm (A)
    beAglm.models[1]
StatsModels.TableRegressionModel{GLM.LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}, Matrix{Float64}}

:(log(Var)) ~ 1 + Trt + Per + Seq + Subj

Coefficients:
──────────────────────────────────────────────────────────────────────────────────
                  Coef.   Std. Error       t  Pr(>|t|)     Lower 95%     Upper 95%
──────────────────────────────────────────────────────────────────────────────────
(Intercept)   5.26309      0.0596091   88.29    <1e-22    5.13672       5.38945
Trt: T       -0.0503868    0.026658    -1.89    0.0770   -0.106899      0.00612568
Per: 2        0.0709849    0.026658     2.66    0.0170    0.0144724     0.127497
Seq: TR      -0.471931     0.079974    -5.90    <1e-04   -0.641469     -0.302394
Subj: 2      -0.60704      0.079974    -7.59    <1e-05   -0.776578     -0.437503
Subj: 3       0.651289     0.079974     8.14    <1e-06    0.481752      0.820827
Subj: 4      -0.0709459    0.079974    -0.89    0.3882   -0.240483      0.0985915
Subj: 5       0.163045     0.079974     2.04    0.0584   -0.00649258    0.332582
Subj: 6      -0.0981368    0.079974    -1.23    0.2375   -0.267674      0.0714006
Subj: 7      -0.317282     0.079974    -3.97    0.0011   -0.486819     -0.147745
Subj: 8      -0.864003     0.079974   -10.80    <1e-08   -1.03354      -0.694466
Subj: 9      -0.458263     0.079974    -5.73    <1e-04   -0.627801     -0.288726
Subj: 10     -0.461259     0.079974    -5.77    <1e-04   -0.630796     -0.291721
Subj: 11     -0.161922     0.079974    -2.02    0.0599   -0.331459      0.00761585
Subj: 12      0.178699     0.079974     2.23    0.0401    0.00916133    0.348236
Subj: 13      0.241743     0.079974     3.02    0.0081    0.0722058     0.411281
Subj: 14      0.394412     0.079974     4.93    0.0002    0.224874      0.563949
Subj: 15      0.44321      0.079974     5.54    <1e-04    0.273672      0.612747
Subj: 16     -0.306182     0.079974    -3.83    0.0015   -0.475719     -0.136644
Subj: 17     -0.0336157    0.079974    -0.42    0.6798   -0.203153      0.135922
Subj: 18      0.0        NaN          NaN       NaN     NaN           NaN
──────────────────────────────────────────────────────────────────────────────────

MixedModels

Estimation witn MixedModels.jl (method B).

    beBmm  = MetidaBioeq.estimate(be2;  estimator = "mm", method = "B")
  Result:
1×11 DataFrame
 Row  Parameter           Metric  PE        SE        DF       lnLCI      lnU ⋯
     │ String              String  Float64   Float64   Float64  Float64    Flo ⋯
─────┼──────────────────────────────────────────────────────────────────────────
   1 │ Formulation: T - R  logVar  0.146088  0.046513    217.0  0.0692531  0.2 ⋯
                                                               5 columns omitted
Estimator: mm (B)
    beBmm.models[1]
Est.SEzpσ_Subject
(Intercept)7.65120.147751.80<1e-990.8408
Formulation: T0.14610.04653.140.0017
Period: 20.02350.06480.360.7173
Period: 30.00400.06660.060.9519
Period: 40.09120.06511.400.1615
Sequence: TRTR-0.02160.1973-0.110.9129
Residual0.4001

Metida

Estimation witn Metida.jl (method C).

    beBmet  = MetidaBioeq.estimate(be2;  estimator = "met", method = "C")
  Result:
1×11 DataFrame
 Row  Parameter           Metric  PE        SE         DF       lnLCI      ln ⋯
     │ String              String  Float64   Float64    Float64  Float64    Fl ⋯
─────┼──────────────────────────────────────────────────────────────────────────
   1 │ Formulation: T - R  logVar  0.145464  0.0465012  208.081  0.0686345  0. ⋯
                                                               5 columns omitted
Estimator: met (C)
    beBmet.models[1]
Linear Mixed Model: logVar ~ Formulation + Period + Sequence
Random 1: 
    Model: Formulation|Subject
    Type: CSH (3), Subjects: 77
Repeated: 
    Model: Formulation|Subject
    Type: DIAG (2)
Blocks: 77, Maximum block size: 4
Status: converged (No Errors)
    -2 logREML: 530.145    BIC: 558.562

    Fixed-effects parameters:
────────────────────────────────────────────────────────
                      Coef.  Std. Error      z  Pr(>|z|)
────────────────────────────────────────────────────────
(Intercept)      7.64968      0.151214   50.59    <1e-99
Formulation: T   0.145464     0.0465012   3.13    0.0018
Period: 2        0.0446377    0.0636371   0.70    0.4830
Period: 3        0.00659021   0.0644219   0.10    0.9185
Period: 4        0.0727201    0.0639714   1.14    0.2556
Sequence: TRTR  -0.0204707    0.197223   -0.10    0.9173
────────────────────────────────────────────────────────
    Variance components:
    θ vector: [0.852995, 0.828407, 1.0, 0.449575, 0.342628]
  Random 1   σ² Formulation: R   var   0.7276
  Random 1   σ² Formulation: T   var   0.686258
  Random 1   ρ                   rho   1.0
  Residual   σ² Formulation: R   var   0.202118
  Residual   σ² Formulation: T   var   0.117394