Skip to content

Commit

Permalink
update mime show for RE without FE (#501)
Browse files Browse the repository at this point in the history
* update mime show for RE without FE

* NEWS entry
(cherry picked from commit 7b6dd31)
  • Loading branch information
palday committed Apr 9, 2021
1 parent 8d41758 commit 00b6329
Show file tree
Hide file tree
Showing 3 changed files with 41 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 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
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions src/mimeshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 20 additions & 1 deletion test/mime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 |
Expand Down

0 comments on commit 00b6329

Please sign in to comment.