Skip to content

Commit

Permalink
support nested grouping variable (#71)
Browse files Browse the repository at this point in the history
* support nested grouping variable

* YAS
  • Loading branch information
palday authored Nov 13, 2023
1 parent 7a89cd3 commit e0d753d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JellyMe4"
uuid = "19ac8677-9a15-4623-9afd-84acc6165ce7"
authors = ["Phillip Alday <me@phillipalday.com>"]
version = "1.1.1"
version = "1.2.0"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand All @@ -22,7 +22,7 @@ CategoricalArrays = "0.10"
DataFrames = "1"
Distributions = "0.25"
GLM = "1.3"
LinearAlgebra = "1"
LinearAlgebra = "0, 1"
MixedModels = "4"
RCall = "0.13"
RegressionFormulae = "0.1"
Expand Down
4 changes: 2 additions & 2 deletions src/formula.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import RCall: rcopy,

"""
fulldummy2dummy(lhs, grp, bar="|")
"""
function _fulldummy2dummy(lhs, grp, bar="|")
terms = Vector{String}(undef, length(lhs.terms))
Expand Down Expand Up @@ -64,7 +64,7 @@ function convert_julia_to_r(f::StatsModels.FormulaTerm)::AbstractString
end

elseif trm isa MixedModels.RandomEffectsTerm
rhs[idx] = _fulldummy2dummy(trm.lhs, trm.rhs.sym)
rhs[idx] = _fulldummy2dummy(trm.lhs, string(trm.rhs))
else
rhs[idx] = string(trm)
end
Expand Down
26 changes: 26 additions & 0 deletions test/lmerMod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Tables: columntable

using JellyMe4: _set_lmer, _set_afex_installed
using MixedModels: dataset
using DataFrames

const LMM = LinearMixedModel
const GLMM = GeneralizedLinearMixedModel
Expand Down Expand Up @@ -136,6 +137,18 @@ const GLMM = GeneralizedLinearMixedModel
@test only(rlmm.rePCA) only(jlmm.rePCA) atol = 0.05
end

@testset "nested grouping" begin
pastes = DataFrame(dataset(:pastes))
@rput pastes
jlmm = fit(MixedModel, @formula(strength ~ 1 + (1 | batch / cask)), pastes;
REML=false, progress=false)
rlmm = rcopy(R"lme4::lmer(strength ~ 1 + (1 | batch / cask), pastes,REML=FALSE)")

@test jlmm.θ rlmm.θ atol = 0.001
@test objective(jlmm) objective(rlmm) atol = 0.001
@test fixef(jlmm) fixef(rlmm) atol = 0.001
end

@testset "dummy" begin
# TODO
end
Expand Down Expand Up @@ -274,6 +287,19 @@ const GLMM = GeneralizedLinearMixedModel
end
end
end

@testset "nested grouping" begin
pastes = DataFrame(dataset(:pastes))
@rput pastes
jlmm = fit(MixedModel, @formula(strength ~ 1 + (1 | batch / cask)), pastes;
REML=false, progress=false)
rlmm = (jlmm, pastes)
@rput rlmm

@test jlmm.θ rcopy(R"""getME(rlmm, "theta")""") atol = 0.001
@test objective(jlmm) rcopy(R"deviance(rlmm)") atol = 0.001
@test only(fixef(jlmm)) rcopy(R"fixef(rlmm)") atol = 0.001
end
end

@testset "lmerControl warnings" begin
Expand Down

2 comments on commit e0d753d

@palday
Copy link
Owner Author

@palday palday commented on e0d753d Nov 13, 2023

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 created: JuliaRegistries/General/95259

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v1.2.0 -m "<description of version>" e0d753d918140370382f27a3f516648bd1513a8b
git push origin v1.2.0

Please sign in to comment.