From 00b6329e54527c9f51f78dde6d437ebcc1a4773f Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Fri, 9 Apr 2021 18:05:12 +0000 Subject: [PATCH] update mime show for RE without FE (#501) * update mime show for RE without FE * NEWS entry (cherry picked from commit 7b6dd314fe933117080f45390e5768806eb689e3) --- NEWS.md | 5 +++++ src/mimeshow.jl | 16 ++++++++++++++++ test/mime.jl | 21 ++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index c55d32ca4..cf61c84d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +MixedModels v3.5.1 Release Notes +======================== +* Fix MIME show methods for models with random-effects not corresponding to a fixed effect [#501]. + MixedModels v3.5.0 Release Notes ======================== * The Progressbar for `parametricbootstrap` and `replicate` is not displayed @@ -170,3 +174,4 @@ Package dependencies [#484]: https://github.com/JuliaStats/MixedModels.jl/issues/484 [#493]: https://github.com/JuliaStats/MixedModels.jl/issues/493 [#495]: https://github.com/JuliaStats/MixedModels.jl/issues/495 +[#501]: https://github.com/JuliaStats/MixedModels.jl/issues/501 diff --git a/src/mimeshow.jl b/src/mimeshow.jl index c9430d813..901119dad 100644 --- a/src/mimeshow.jl +++ b/src/mimeshow.jl @@ -141,6 +141,22 @@ function _markdown(m::MixedModel) push!(rows, newrow) end + re_without_fe = setdiff(mapfoldl(x -> Set(getproperty(x, :cnames)), ∪ , m.reterms), coefnames(m)) + + for bname in re_without_fe + newrow = [bname, "", "", "", ""] + bname = Symbol(bname) + + for (j, sig) in enumerate(m.σs) + if bname in keys(sig) + push!(newrow, Ryu.writefixed(getproperty(sig, bname),digits)) + else + push!(newrow, " ") + end + end + push!(rows, newrow) + end + if dispersion_parameter(m) newrow = [_dname(m), Ryu.writefixed(dispersion(m),digits), "", "", ""] for rr in fnames(m) diff --git a/test/mime.jl b/test/mime.jl index 2075a6192..e53bdd613 100644 --- a/test/mime.jl +++ b/test/mime.jl @@ -13,12 +13,19 @@ include("modelcache.jl") gm3 = GeneralizedLinearMixedModel(only(gfms[:verbagg]), dataset(:verbagg), Bernoulli()) pirls!(setβθ!(gm3, βθ)) -fm0θ = [ 1.1656121258575225] +fm0θ = [1.1656121258575225] fm0 = updateL!(setθ!(first(models(:sleepstudy)), fm0θ)) fm1θ = [0.9292213288149662, 0.018168393450877257, 0.22264486671069741] fm1 = updateL!(setθ!(last(models(:sleepstudy)), fm1θ)) +fmreθ = [0.32352483854887326, 0.4715395478019364, 0.0, + 0.43705610601403755, 0.016565641868150047, 0.17732248078617097] +# this is a junk model, but it stresses parts of the display code +fmre = LinearMixedModel(@formula(rt_trunc ~ 1+(0+spkr|subj)+(1+load|item)), MixedModels.dataset(:kb07)) +updateL!(setθ!(fmre, fmreθ)) +fmre.optsum.feval = 1 + lrt = likelihoodratiotest(fm0, fm1) @testset "markdown" begin @@ -43,6 +50,18 @@ lrt = likelihoodratiotest(fm0, fm1) """ end + @testset "re without fe" begin + @test sprint(show, mime, fmre) == """ +| | Est. | SE | z | p | σ_subj | σ_item | +|:----------- | ---------:| -------:| -----:| ------:| --------:| --------:| +| (Intercept) | 2092.3713 | 76.9426 | 27.19 | <1e-99 | | 349.7858 | +| spkr: old | | | | | 377.3837 | | +| spkr: new | | | | | 258.9242 | | +| load: yes | | | | | | 142.5331 | +| Residual | 800.3224 | | | | | | +""" + end + @testset "glmm" begin @test sprint(show, mime, gm3) in (""" | | Est. | SE | z | p | σ_subj | σ_item |