From 7cf8287fe58b4e0f335dc7303e62e7994d76975f Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Fri, 2 Jul 2021 16:37:54 +0200 Subject: [PATCH] extract nested MatrixTerm (#23) * extract nested MatrixTerm * add tests * patch bump --- Project.toml | 4 ++-- src/typical.jl | 3 +++ test/typical.jl | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 2d7aec7..d48e2aa 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Effects" uuid = "8f03c58b-bd97-4933-a826-f71b64d2cca2" authors = ["Beacon Biosignals, Inc."] -version = "0.1.1" +version = "0.1.2" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" @@ -14,7 +14,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [compat] DataFrames = "0.22, 1.0, 1.1" GLM = "1.5.1" -MixedModels = "2, 3, 4" +MixedModels = "3.9, 4" StableRNGs = "1.0" StandardizedPredictors = "0.1" StatsBase = "0.33" diff --git a/src/typical.jl b/src/typical.jl index 7ad6341..8e17471 100644 --- a/src/typical.jl +++ b/src/typical.jl @@ -46,6 +46,9 @@ function get_matrix_term(x) x = StatsModels.collect_matrix_terms(x) x = x isa MatrixTerm ? x : first(x) x isa MatrixTerm || throw(ArgumentError("couldn't extract matrix term from $x")) + if first(x.terms) isa MatrixTerm + x = only(x.terms) + end return x end diff --git a/test/typical.jl b/test/typical.jl index 6c1a664..259f5c6 100644 --- a/test/typical.jl +++ b/test/typical.jl @@ -20,7 +20,12 @@ dat = DataFrame(; x=x, # test that we created an additional model matrix full of -0.0 @test last(XZ) isa ReMat @test !(first(XZ) isa ReMat) - mc = modelcols(get_matrix_term(rhs), dat) + + trm = first(form.rhs) + materm = get_matrix_term(rhs) + mc = modelcols(materm, dat) + # this tests that we're fully extracting the nested MatrixTerm + @test typicalterm(trm, materm, mc) isa TypicalTerm # test that the matrix term corresponds to the term we expect @test mc == first(XZ) end