Skip to content

Show method broken for model with no predictors #621

@andreasnoack

Description

@andreasnoack

See below for the error when trying to show

nullmod = lm(@formula(Result~1), d)
. I think the solution is actually to adjust coefnames in StatsModels because

julia> coefnames(formula(mod).rhs)
2-element Vector{String}:
 "(Intercept)"
 "Treatment"

julia> coefnames(formula(nullmod).rhs)
"(Intercept)"

which the is root cause here. See JuliaStats/StatsModels.jl#112

Error message:

julia> nullmod
LinearModel

Result ~ 1

Error showing value of type LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredQR{Float64, LinearAlgebra.QRPivoted}}:

SYSTEM (REPL): showing an error caused an error
ERROR: 1-element ExceptionStack:
MethodError: no method matching StatsBase.CoefTable(::Matrix{Float64}, ::Vector{String}, ::String, ::Int64, ::Int64)
The type `StatsBase.CoefTable` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  StatsBase.CoefTable(::Matrix, ::Vector, ::Vector, ::Int64, ::Int64)
   @ StatsBase ~/.julia/packages/StatsBase/5D4Dh/src/statmodels.jl:23
  StatsBase.CoefTable(::Vector, ::Vector, ::Vector, ::Int64, ::Int64)
   @ StatsBase ~/.julia/packages/StatsBase/5D4Dh/src/statmodels.jl:10
  StatsBase.CoefTable(::Matrix, ::Vector, ::Vector, ::Int64)
   @ StatsBase ~/.julia/packages/StatsBase/5D4Dh/src/statmodels.jl:23
  ...

Stacktrace:
  [1] coeftable(mm::LinearModel{GLM.LmResp{Vector{…}}, GLM.DensePredQR{Float64, LinearAlgebra.QRPivoted}}; level::Float64)
    @ GLM ~/.julia/dev/GLM/src/lm.jl:247
  [2] coeftable
    @ ~/.julia/dev/GLM/src/lm.jl:233 [inlined]
  [3] show(io::IOContext{REPL.LimitIO{…}}, obj::LinearModel{GLM.LmResp{…}, GLM.DensePredQR{…}})
    @ GLM ~/.julia/dev/GLM/src/linpred.jl:288
  [4] show(io::IOContext{REPL.LimitIO{…}}, ::MIME{Symbol("text/plain")}, x::LinearModel{GLM.LmResp{…}, GLM.DensePredQR{…}})
    @ Base.Multimedia ./multimedia.jl:47
  [5] show_repl(io::IO, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:548
  [6] show_limited(io::IO, mime::MIME, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:517
  [7] (::REPL.var"#display##0#display##1"{REPL.REPLDisplay{}, MIME{}, Base.RefValue{}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:540
  [8] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:833
  [9] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:526
 [10] display
    @ ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:546 [inlined]
 [11] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [12] (::REPL.var"#print_response##2#print_response##3")()
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:590
 [13] repl_backend_loop(backend::REPL.REPLBackend, get_module::Function)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:445
 [14] start_repl_backend(backend::REPL.REPLBackend, consumer::Any; get_module::Function)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:427
 [15] start_repl_backend
    @ ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:424 [inlined]
 [16] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool, backend::Any)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:653
 [17] run_repl(repl::REPL.AbstractREPL, consumer::Any)
    @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:639
 [18] run_std_repl(REPL::Module, quiet::Bool, banner::Symbol, history_file::Bool)
    @ Base ./client.jl:478
 [19] run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool)
    @ Base ./client.jl:499
 [20] repl_main
    @ ./client.jl:586 [inlined]
 [21] _start()
    @ Base ./client.jl:561
Stacktrace:
 [1] print_response(errio::IO, response::Any, backend::Union{…}, show_value::Bool, have_color::Bool, specialdisplay::Union{…})
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:599
 [2] (::REPL.var"#print_response##0#print_response##1"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:558
 [3] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:833
 [4] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:556
 [5] (::REPL.var"#do_respond#73"{})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1192
 [6] run_interface(terminal::Base.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
   @ REPL.LineEdit ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/LineEdit.jl:2854
 [7] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:1663
 [8] (::REPL.var"#61#62"{REPL.LineEditREPL, REPL.REPLBackendRef})()
   @ REPL ~/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/REPL/src/REPL.jl:650
Some type information was truncated. Use `show(err)` to see complete types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions