Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BACKPORT: mimeshow RE without FE #502

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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
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 = "3.5.0"
version = "3.5.1"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
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