From 8a71b645f65c18360159076c0b981484340b48d2 Mon Sep 17 00:00:00 2001 From: Dave Kleinschmidt Date: Tue, 4 Apr 2023 10:38:55 -0400 Subject: [PATCH 1/4] add tests for currently expected behavior --- test/terms.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/terms.jl b/test/terms.jl index 34eb35f8..04a6b916 100644 --- a/test/terms.jl +++ b/test/terms.jl @@ -274,4 +274,14 @@ StatsModels.apply_schema(mt::MultiTerm, sch::StatsModels.Schema, Mod::Type) = @test_throws ArgumentError concrete_term(term(:not_there), t ) end + @testset "sort by degree in ~" begin + one, a, b = term.([1, :a, :b]) + + @test a + one == (a, one) + @test (a ~ a + one) == (a ~ one + a) + + @test a & b + one + a == (a & b, one, a) + @test (a ~ a & b + one + a) == (a ~ one + a + a & b) + end + end From 61178bb37ec560d8cf8b4ef1006110fd4bdcdd29 Mon Sep 17 00:00:00 2001 From: Dave Kleinschmidt Date: Tue, 4 Apr 2023 10:44:26 -0400 Subject: [PATCH 2/4] the fix --- src/terms.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/terms.jl b/src/terms.jl index d271541f..f9a89c17 100644 --- a/src/terms.jl +++ b/src/terms.jl @@ -414,6 +414,8 @@ Base.:*(a::TermOrTerms, b::TermOrTerms) = a + b + a&b cleanup(terms::TupleTerm) = Tuple(sort!(unique!(collect(terms)), by=degree)) cleanup(x) = x +degree(::ConstantTerm) = 0 +degree(::InterceptTerm) = 0 degree(::AbstractTerm) = 1 degree(t::InteractionTerm) = mapreduce(degree, +, t.terms) # dirty hack, move to MixedModels.jl From 780f5d364566f531664209a26abf593439ab55ab Mon Sep 17 00:00:00 2001 From: Dave Kleinschmidt Date: Tue, 4 Apr 2023 10:49:00 -0400 Subject: [PATCH 3/4] also test intercept terms too --- test/terms.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/terms.jl b/test/terms.jl index 04a6b916..b58900bc 100644 --- a/test/terms.jl +++ b/test/terms.jl @@ -276,12 +276,13 @@ StatsModels.apply_schema(mt::MultiTerm, sch::StatsModels.Schema, Mod::Type) = @testset "sort by degree in ~" begin one, a, b = term.([1, :a, :b]) + for zero_deg in [one, InterceptTerm{true}(), InterceptTerm{false}()] + @test a + zero_deg == (a, zero_deg) + @test (a ~ a + zero_deg) == (a ~ zero_deg + a) - @test a + one == (a, one) - @test (a ~ a + one) == (a ~ one + a) - - @test a & b + one + a == (a & b, one, a) - @test (a ~ a & b + one + a) == (a ~ one + a + a & b) + @test a & b + zero_deg + a == (a & b, zero_deg, a) + @test (a ~ a & b + zero_deg + a) == (a ~ zero_deg + a + a & b) + end end end From f5bfe7bb32a520ab0ca66b305d75ca835254d237 Mon Sep 17 00:00:00 2001 From: Dave Kleinschmidt Date: Tue, 4 Apr 2023 10:49:41 -0400 Subject: [PATCH 4/4] bump patch --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index c8b0abe2..f16acfa6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StatsModels" uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d" -version = "0.7.0" +version = "0.7.1" [deps] DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"