Skip to content

Commit

Permalink
support nested grouping variable
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Nov 7, 2023
1 parent 7a89cd3 commit cdcd7ca
Show file tree
Hide file tree
Showing 3 changed files with 31 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 <[email protected]>"]
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
27 changes: 27 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,20 @@ 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

0 comments on commit cdcd7ca

Please sign in to comment.