Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions src/MixedModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export @formula,
issingular,
leverage,
levels,
lmm,
logdet,
loglikelihood,
lowerbd,
Expand Down
15 changes: 13 additions & 2 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,21 @@ function StatsAPI.fit(::Type{LinearMixedModel},
σ=nothing,
amalgamate=true,
kwargs...)
lmm = LinearMixedModel(f, tbl; contrasts, wts, σ, amalgamate)
return fit!(lmm; kwargs...)
lmod = LinearMixedModel(f, tbl; contrasts, wts, σ, amalgamate)
return fit!(lmod; kwargs...)
end

"""
lmm(f::FormulaTerm, tbl; kwargs...)
lmm(
f::FormulaTerm, tbl;
wts=[], contrasts=Dict{Symbol,Any}(), σ=nothing, amalgamate=true,
kwargs...)

Aliases for the fit(LinearMixedModel, ...) functions
"""
lmm(args...; kwargs...) = fit(LinearMixedModel, args...; kwargs...)

function _offseterr()
return throw(
ArgumentError(
Expand Down
4 changes: 2 additions & 2 deletions src/predict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ function _predict(m::MixedModel{T}, newdata, β; new_re_levels) where {T}
),
)
end
lmm = LinearMixedModel(f, newdata; contrasts=contr)
lmod = LinearMixedModel(f, newdata; contrasts=contr)
ytemp =
new_re_levels == :missing ? convert(Vector{Union{T,Missing}}, ytemp) : ytemp

ytemp, lmm
ytemp, lmod
end

pivotmatch = pivot(mnew)[pivot(m)]
Expand Down
21 changes: 20 additions & 1 deletion test/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@ using MixedModels
using Suppressor
using Test

@testset "linear" begin
@testset "linear, and lmm wrapper" begin
m1 = fit(MixedModel, @formula(yield ~ 1 + (1|batch)), MixedModels.dataset(:dyestuff); progress=false)
@test first(m1.θ) ≈ 0.7525806757718846 rtol=1.0e-5
m2 = lmm(@formula(yield ~ 1 + (1|batch)), MixedModels.dataset(:dyestuff); progress=false)
@test isa(m2, LinearMixedModel)
@test first(m2.θ) ≈ 0.7525806757718846 rtol=1.0e-5
@test deviance(m1) ≈ deviance(m2) #TODO: maybe add an `rtol`?
@test isa(lmm(@formula(yield ~ 1 + (1|batch)), MixedModels.dataset(:dyestuff); progress=false, REML = true), LinearMixedModel)

# example from https://github.com/JuliaStats/MixedModels.jl/issues/194
# copied from tetst/pls.jl
data = (
a = [1.55945122,0.004391538,0.005554163,-0.173029772,4.586284429,0.259493671,-0.091735715,5.546487603,0.457734831,-0.030169602],
b = [0.24520519,0.080624178,0.228083467,0.2471453,0.398994279,0.037213859,0.102144973,0.241380251,0.206570975,0.15980803],
c = PooledArray(["H","F","K","P","P","P","D","M","I","D"]),
w1 = [20,40,35,12,29,25,65,105,30,75],
w2 = [0.04587156,0.091743119,0.080275229,0.027522936,0.066513761,0.05733945,0.149082569,0.240825688,0.068807339,0.172018349],
)
m2 = lmm(@formula(a ~ 1 + b + (1|c)), data; wts = data.w1, progress=false)
@test m2.θ ≈ [0.295181729258352] atol = 1.e-4
@test stderror(m2) ≈ [0.9640167, 3.6309696] atol = 1.e-4
@test vcov(m2) ≈ [0.9293282 -2.557527; -2.5575267 13.183940] atol = 1.e-4
end

@testset "generalized" begin
Expand Down
Loading