Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nested grouping variable #71

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading