StatsModels ArgumentError: collection must be non-empty

ERROR: LoadError: LoadError: ArgumentError: collection must be non-empty
  [1] _extrema_itr(f::typeof(identity), itr::Vector{Float64})
    @ Base ./operators.jl:483
  [2] _extrema_dims
    @ ./multidimensional.jl:1698 [inlined]
  [3] #extrema#486
    @ ./multidimensional.jl:1685 [inlined]
  [4] extrema
    @ ./multidimensional.jl:1685 [inlined]
  [5] concrete_term
    @ ~/.julia/packages/StatsModels/lqOhh/src/schema.jl:201 [inlined]
  [6] concrete_term(t::StatsModels.Term, xs::Vector{Float64}, #unused#::Nothing)
    @ StatsModels ~/.julia/packages/StatsModels/lqOhh/src/schema.jl:198
  [7] concrete_term(t::StatsModels.Term, dt::NamedTuple{(
    @ StatsModels ~/.julia/packages/StatsModels/lqOhh/src/schema.jl:184
  [8] (::StatsModels.var"#52#53"{NamedTuple{(
    @ StatsModels ./none:0
  [9] iterate
    @ ./generator.jl:47 [inlined]
 [10] Dict{StatsModels.Term, StatsModels.AbstractTerm}(kv::Base.Generator{Vector{StatsModels.Term}, StatsModels.var"#52#53"{NamedTuple{(
    @ Base ./dict.jl:103
 [11] Schema
    @ ~/.julia/packages/StatsModels/lqOhh/src/schema.jl:37 [inlined]
 [12] schema
    @ ~/.julia/packages/StatsModels/lqOhh/src/schema.jl:123 [inlined]
 [13] schema(f::StatsModels.FormulaTerm{StatsModels.Term, Tuple{StatsModels.FunctionTerm{typeof(|), var"#39#42",
    @ StatsModels ~/.julia/packages/StatsModels/lqOhh/src/schema.jl:126
 [14] LinearMixedModel(f::StatsModels.FormulaTerm{StatsModels.Term, Tuple{StatsModels.FunctionTerm{typeof(|), 
    @ MixedModels ~/.julia/packages/MixedModels/DCOiy/src/linearmixedmodel.jl:57
 [15] fit(::Type{LinearMixedModel}, f::Stats

I’m not sure if this is a MixedModels.jl question (@dmbates) or a StatsModels.jl question (@dave.f.kleinschmidt )but I’m wondering what the error means and/or how to fix it.

It looks as if something in one of the columns used in an expression in the model formula, probably a random-effects term, is not evaluated as expected. I would check those.

You can see in [14] that it is evaluating the schema for an expression with | in it and by [1] it is looking for the extrema on a vector of Float64 which turns out to be empty.

If you are unable to isolate the problem could you show the formula and the structure of the data that you are using?

Thanks. It turned out the dataframe was empty.

Since StatsModels 0.6.28 (released a few days ago) you should get a more informative error message in these situations :slight_smile: Better error messages for totally empty columns by kleinschmidt · Pull Request #248 · JuliaStats/StatsModels.jl · GitHub