Skip to content

Commit

Permalink
Merge 5312171 into 8ae74f7
Browse files Browse the repository at this point in the history
  • Loading branch information
palday authored Apr 14, 2023
2 parents 8ae74f7 + 5312171 commit 160ed17
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
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 <[email protected]>", "Douglas Bates <[email protected]>", "Jose Bayoan Santiago Calderon <[email protected]>"]
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

0 comments on commit 160ed17

Please sign in to comment.