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

better compatibility with RegressionFormulae.jl #677

Merged
merged 2 commits into from
Apr 14, 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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
MixedModels v4.12.0 Release Notes
==============================
* The pirated method `Base.:/(a::AbstractTerm, b::AbstractTerm)` is no longer defined. This does not impact the use of `/` as a nesting term in `@formula` within MixedModels, only the programmatic runtime construction of formula, e.g. `term(:a) / term(:b)`. If you require `Base.:/`, then [`RegressionFormulae.jl`](https://github.com/kleinschmidt/RegressionFormulae.jl) provides this method. (Avoiding method redefinition when using `RegressionFormulae.jl` is the motivating reason for this change.) [#677]

MixedModels v4.11.0 Release Notes
==============================
* `raneftables` returns a `NamedTuple` where the names are the grouping factor names and the values are some `Tables.jl`-compatible type. Currently this type is a `DictTable` from `TypedTables.jl`. [#634]
Expand Down Expand Up @@ -412,3 +416,4 @@ Package dependencies
[#667]: https://github.com/JuliaStats/MixedModels.jl/issues/667
[#674]: https://github.com/JuliaStats/MixedModels.jl/issues/674
[#676]: https://github.com/JuliaStats/MixedModels.jl/issues/676
[#677]: https://github.com/JuliaStats/MixedModels.jl/issues/677
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MixedModels"
uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316"
author = ["Phillip Alday <me@phillipalday.com>", "Douglas Bates <dmbates@gmail.com>", "Jose Bayoan Santiago Calderon <jbs3hp@virginia.edu>"]
version = "4.11.0"
version = "4.12.0"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
6 changes: 4 additions & 2 deletions src/randomeffectsterm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ function _ranef_refs(
return refs, uniques
end

# TODO: split this off into a RegressionFormula package?
Base.:/(a::AbstractTerm, b::AbstractTerm) = a + a & b
# TODO: remove all of this and either
# - require users to use RegressionFormulae.jl
# - add a dependency on RegressionFormulae.jl

function StatsModels.apply_schema(
t::FunctionTerm{typeof(/)}, sch::StatsModels.FullRank, Mod::Type{<:MixedModel}
)
Expand Down
27 changes: 3 additions & 24 deletions test/FactorReTerm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,31 +245,11 @@ end
@test modelcols(f2.rhs, d2) == [ones(20) d2.b .== :Y (d2.b .== :X).*d2.a (d2.b .== :Y).*d2.a]
@test coefnames(f2.rhs) == ["(Intercept)", "b: Y", "b: X & a", "b: Y & a"]

# runtime
fr2 = term(1) + term(:b) / term(:a)
@test length(fr2) == 3
@test fr2[1] isa ConstantTerm
@test fr2[2] isa Term
@test fr2[3] isa InteractionTerm
frf2 = apply_schema(term(0) ~ fr2, schema(d2), MixedModel)
@test modelcols(frf2.rhs, d2) == [ones(20) d2.b .== :Y (d2.b .== :X).*d2.a (d2.b .== :Y).*d2.a]
@test coefnames(frf2.rhs) == ["(Intercept)", "b: Y", "b: X & a", "b: Y & a"]

# check promotion
f3 = apply_schema(@formula(0 ~ 0 + b/a), schema(d2), MixedModel)
@test modelcols(f3.rhs, d2) == [d2.b .== :X d2.b .== :Y (d2.b .== :X).*d2.a (d2.b .== :Y).*d2.a]
@test coefnames(f3.rhs) == ["b: X", "b: Y", "b: X & a", "b: Y & a"]

# runtime:
fr3 = term(0) + term(:b) / term(:a)
@test length(fr3) == 3
@test fr3[1] isa ConstantTerm
@test fr3[2] isa Term
@test fr3[3] isa InteractionTerm
ffr3 = apply_schema(term(0) ~ fr3, schema(d2), MixedModel)
@test modelcols(ffr3.rhs, d2) == [d2.b .== :X d2.b .== :Y (d2.b .== :X).*d2.a (d2.b .== :Y).*d2.a]
@test coefnames(ffr3.rhs) == ["b: X", "b: Y", "b: X & a", "b: Y & a"]

# errors for continuous grouping
@test_throws ArgumentError apply_schema(@formula(0 ~ 1 + a/b), schema(d2), MixedModel)

Expand All @@ -280,12 +260,11 @@ end
psts = dataset("pastes")
m = fit(MixedModel, @formula(strength ~ 1 + (1|batch/cask)), psts; progress=false)
m2 = fit(MixedModel, @formula(strength ~ 1 + (1|batch) + (1|batch&cask)), psts; progress=false)
mr = fit(MixedModel, term(:strength) ~ term(1) + (term(1)|term(:batch)/term(:cask)), psts; progress=false)
m2r = fit(MixedModel, term(:strength) ~ term(1) + (term(1)|term(:batch)) + (term(1)|term(:batch)&term(:cask)), psts; progress=false)

@test fnames(m) == fnames(m2) == fnames(mr) == fnames(m2r) == (Symbol("batch & cask"), :batch)
@test m.λ == m2.λ == mr.λ == m2r.λ
@test deviance(m) == deviance(m2) == deviance(mr) == deviance(m2r)
@test fnames(m) == fnames(m2) == fnames(m2r) == (Symbol("batch & cask"), :batch)
@test m.λ == m2.λ == m2r.λ
@test deviance(m) == deviance(m2) == deviance(m2r)
end

@testset "multiple terms with same grouping" begin
Expand Down