Skip to content

Commit

Permalink
extract nested MatrixTerm (#23)
Browse files Browse the repository at this point in the history
* extract nested MatrixTerm

* add tests

* patch bump
  • Loading branch information
palday committed Jul 2, 2021
1 parent 35e884c commit 7cf8287
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/typical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion test/typical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 7cf8287

@palday
Copy link
Member Author

@palday palday commented on 7cf8287 Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/40093

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 7cf8287fe58b4e0f335dc7303e62e7994d76975f
git push origin v0.1.2

Please sign in to comment.