diff --git a/Project.toml b/Project.toml index 20c609a..e06083e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JellyMe4" uuid = "19ac8677-9a15-4623-9afd-84acc6165ce7" authors = ["Phillip Alday "] -version = "1.1.1" +version = "1.2.0" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" @@ -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" diff --git a/src/formula.jl b/src/formula.jl index bdc72d6..12639a1 100644 --- a/src/formula.jl +++ b/src/formula.jl @@ -7,7 +7,7 @@ import RCall: rcopy, """ fulldummy2dummy(lhs, grp, bar="|") - + """ function _fulldummy2dummy(lhs, grp, bar="|") terms = Vector{String}(undef, length(lhs.terms)) @@ -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 diff --git a/test/lmerMod.jl b/test/lmerMod.jl index 0924417..ed29c11 100644 --- a/test/lmerMod.jl +++ b/test/lmerMod.jl @@ -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 @@ -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 @@ -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