diff --git a/docs/src/instanduse.md b/docs/src/instanduse.md index e8b03e2c..242adb98 100644 --- a/docs/src/instanduse.md +++ b/docs/src/instanduse.md @@ -60,7 +60,7 @@ nothing # hide Make model with `@formula` macro from `StatsModels`. Define `random` and `repreated` effects with [`Metida.VarEffect`](@ref) using [`Metida.@covstr`](@ref) macros. Left side of `@covstr` is model of effect and -right side is a effect itself. [`Metida.HeterogeneousCompoundSymmetry`](@ref) and [`Metida.Diagonal`](@ref) in example bellow is a model of variance-covariance structure. See also [`@lmmformula`](@ref) macro. +right side is a effect itself. [`Metida.HeterogeneousCompoundSymmetry`](@ref) and [`Metida.Diagonal`](@ref) in example bellow is a model of variance-covariance structure. See also [`Metida.@lmmformula`](@ref) macro. !!! note In some cases levels of repeated effect should not be equal inside each level of subject or model will not have any sense. For example, it is assumed that usually CSH or UN (Unstructured) using with levels of repeated effect is different inside each level of subject. diff --git a/src/Metida.jl b/src/Metida.jl index 630c2025..a708728f 100644 --- a/src/Metida.jl +++ b/src/Metida.jl @@ -19,7 +19,7 @@ import StatsBase: fit, fit!, coef, coefnames, confint, nobs, dof_residual, dof, import Base:show, rand, ht_keyindex, getproperty import Random: default_rng, AbstractRNG, rand! -export @formula, @covstr, +export @formula, @covstr, @lmmformula, SI, ScaledIdentity, DIAG, Diag, AR, Autoregressive, diff --git a/src/lmmformula.jl b/src/lmmformula.jl index 9d80beb7..6534207c 100644 --- a/src/lmmformula.jl +++ b/src/lmmformula.jl @@ -28,10 +28,10 @@ repeated = Metida.VarEffect(@covstr(formulation|subject), DIAG), ) ``` -`@lmmformula` have 3 components - 1'st is a formula for fixed effect, it defined +`@lmmformula` have 3 components - 1'st is a formula for fixed effect, it's defined like in `StstsModels` (1st argument just provided to `@formula` macro). Other arguments should be defined like keywords. `repeated` keyword define repeated effect part, -`random` define random effect part. You can use several random factors as in example bellow: +`random` - define random effect part. You can use several random factors as in example bellow: ``` lmm = Metida.LMM(Metida.@lmmformula(var~sequence+period+formulation, @@ -46,8 +46,10 @@ df0) `effect formula` | `blocking factor` [/ `nested factor`] [: `covariance structure`] `|` - devide effect formula form blocking factor definition (necessarily), -`/` and `:` modificator are optional. `/` work like in MixedModels or in RegressionFormulae - -expand factor `f|a/b` to `f|a` + `f|a&b`. It can't be used in repeated effect defenition. +`/` and `:` modificator are optional. + +`/` work like in MixedModels or in RegressionFormulae - +expand factor `f|a/b` to `f|a` + `f|a&b`. It can't be used in repeated effect definition. `:` - covariance structure defined right after `:` (SI, DIAG, CS, CSH, ets...), if `:` not used then SI used for this effect. @@ -121,3 +123,19 @@ macro lmmformula(formula, args...) if length(ranfac) == 0 ranfac = nothing end return LMMformula(f, ranfac, repeff) end + +function Base.show(io::IO, f::LMMformula) + println(io, "LMM formula:") + print(io, "Fixed-effect formula: ") + println(io, f.formula) + if !isnothing(f.random) + for i = 1:length(f.random) + println(io, "Radom-effect $i formula:") + println(io, f.random[i]) + end + end + if !isnothing(f.repeated) + println(io, "Repeated-effect formula:") + println(io, f.repeated) + end +end diff --git a/src/miboot.jl b/src/miboot.jl index 291dfcdf..dad10808 100644 --- a/src/miboot.jl +++ b/src/miboot.jl @@ -103,6 +103,9 @@ sdstraps(br::BootstrapResult, idx::Int) = getindex(br.vv, idx) Parametric bootstrap. +!!! warning + Experimental: API not stable, results not validated + - double - use double approach (default - true); - n - number of bootstrap samples for coefficient estimtion; - varn - number of bottstrap samples for varianvce estimation; @@ -365,6 +368,9 @@ end Multiple imputation. +!!! warning + Experimental: API not stable, results not validated + For each subject random vector of missing values generated from distribution: ```math @@ -421,6 +427,9 @@ end Multiple imputation with parametric bootstrap step. +!!! warning + Experimental: API not stable, results not validated + Example: ```julia diff --git a/test/test.jl b/test/test.jl index 629dbb86..5664260d 100644 --- a/test/test.jl +++ b/test/test.jl @@ -334,6 +334,15 @@ end ) Metida.fit!(lmm) @test Metida.m2logreml(lmm) ≈ 697.2241355154041 atol=1E-8 + + + lmm = Metida.LMM(Metida.@lmmformula(response ~ 1 + factor, + random = 1|subject/r1, + repeated = p|subject:Metida.CSH), + ftdf3; contrasts=Dict(:factor => DummyCoding(; base=1.0))) + + Metida.fit!(lmm) + @test Metida.m2logreml(lmm) ≈ 697.2241355154041 atol=1E-8 #@test Metida.dof_satter(lmm)[2] ≈ 21.944891442712407 atol=1E-8 end @testset " Model: AR/SI " begin