Skip to content

Commit

Permalink
Merge cfe54ce into 72ac0e1
Browse files Browse the repository at this point in the history
  • Loading branch information
palday authored Oct 6, 2022
2 parents 72ac0e1 + cfe54ce commit bc46d31
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
MixedModels v4.7.3 Release Notes
==============================
* More informative error message for formulae lacking random effects [#651]

MixedModels v4.7.2 Release Notes
==============================
* Replace separate calls to `copyto!` and `scaleinflate!` in `updateL!` with `copyscaleinflate!` [#648]
Expand Down Expand Up @@ -370,3 +374,4 @@ Package dependencies
[#628]: https://github.com/JuliaStats/MixedModels.jl/issues/628
[#637]: https://github.com/JuliaStats/MixedModels.jl/issues/637
[#648]: https://github.com/JuliaStats/MixedModels.jl/issues/648
[#651]: https://github.com/JuliaStats/MixedModels.jl/issues/651
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.7.2"
version = "4.7.3"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
9 changes: 9 additions & 0 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ function LinearMixedModel(
)
return LinearMixedModel(f::FormulaTerm, Tables.columntable(tbl); contrasts, wts, σ)
end
const _MISSING_RE_ERROR = ArgumentError(
"Formula contains no random effects; this isn't a mixed model. Perhaps you want to use GLM.jl?",
)

function LinearMixedModel(
f::FormulaTerm, tbl::Tables.ColumnTable; contrasts=Dict{Symbol,Any}(), wts=[], σ=nothing
Expand All @@ -62,6 +65,11 @@ function LinearMixedModel(
rethrow(e)
end
form = apply_schema(f, sch, LinearMixedModel)

if form.rhs isa MatrixTerm || !any(x -> isa(x, AbstractReTerm), form.rhs)
throw(_MISSING_RE_ERROR)
end

# tbl, _ = StatsModels.missing_omit(tbl, form)

y, Xs = modelcols(form, tbl)
Expand Down Expand Up @@ -119,6 +127,7 @@ function LinearMixedModel(
push!(feterms, FeTerm(x, isa(cnames, String) ? [cnames] : collect(cnames)))
end
end
isempty(reterms) && throw(_MISSING_RE_ERROR)
return LinearMixedModel(convert(Array{T}, y), only(feterms), reterms, form, wts, σ)
end

Expand Down
18 changes: 18 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using MixedModels
using Test

using MixedModels: dataset

@testset "formula misspecification" begin
dyestuff = dataset(:dyestuff)

@test MixedModel(@formula(yield ~ 0 + (1|batch)), dyestuff) isa LinearMixedModel
@test MixedModel(@formula(yield ~ 1 + (1|batch)), dyestuff) isa LinearMixedModel
@test_throws MixedModels._MISSING_RE_ERROR MixedModel(@formula(yield ~ 0 + batch), dyestuff)
@test_throws MixedModels._MISSING_RE_ERROR MixedModel(@formula(yield ~ 1), dyestuff)

@test MixedModel(@formula(yield ~ 0 + (1|batch)), dyestuff, Poisson()) isa GeneralizedLinearMixedModel
@test MixedModel(@formula(yield ~ 1 + (1|batch)), dyestuff, Poisson()) isa GeneralizedLinearMixedModel
@test_throws MixedModels._MISSING_RE_ERROR MixedModel(@formula(yield ~ 0 + batch), dyestuff, Poisson())
@test_throws MixedModels._MISSING_RE_ERROR MixedModel(@formula(yield ~ 1), dyestuff, Poisson())
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ else
end

include("utilities.jl")
include("misc.jl")
include("pivot.jl")
include("UniformBlockDiagonal.jl")
include("linalg.jl")
Expand Down

0 comments on commit bc46d31

Please sign in to comment.