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

Error in predict() with just a constant term #557

Open
RobertGregg opened this issue May 3, 2024 · 1 comment
Open

Error in predict() with just a constant term #557

RobertGregg opened this issue May 3, 2024 · 1 comment

Comments

@RobertGregg
Copy link

using GLM
using DataFrames

df1 = DataFrame(y = rand(10))
df2 = DataFrame(y = rand(10))

model = lm(@formula(y~1),df1)

y = predict(model,df2)

Gives the following error:
ERROR: ArgumentError: collection must be non-empty

I realize this is a weird edge case, but I think it should just return mean(df1.y) for each prediction.

@andreasnoack
Copy link
Member

In addition, also the show method is broken in this case

julia> model
LinearModel

y ~ 1

Error showing value of type LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}:
ERROR: MethodError: no method matching StatsBase.CoefTable(::Matrix{Float64}, ::Vector{String}, ::String, ::Int64, ::Int64)

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

Stacktrace:
  [1] coeftable(mm::LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}}; level::Float64)
    @ GLM ~/.julia/dev/GLM/src/lm.jl:257
  [2] coeftable
    @ ~/.julia/dev/GLM/src/lm.jl:243 [inlined]
  [3] show(io::IOContext{Base.TTY}, obj::LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}, Vector{Int64}}}})
    @ GLM ~/.julia/dev/GLM/src/linpred.jl:324
  [4] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, x::LinearModel{GLM.LmResp{Vector{…}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{…}}})
    @ Base.Multimedia ./multimedia.jl:47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants