Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Aug 2, 2022
1 parent fd1e5ef commit a8f1b3b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/src/instanduse.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Metida.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 22 additions & 4 deletions src/lmmformula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/miboot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -421,6 +427,9 @@ end
Multiple imputation with parametric bootstrap step.
!!! warning
Experimental: API not stable, results not validated
Example:
```julia
Expand Down
9 changes: 9 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit a8f1b3b

@PharmCat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/64899

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" a8f1b3bb2dc947cbf4f8453aa002e4214548b953
git push origin v0.14.0

Please sign in to comment.