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

ModelMatrix(@formula(0~1), (x = 1:4, y = 5:8)) fails #269

Open
behinger opened this issue Jan 19, 2023 · 1 comment
Open

ModelMatrix(@formula(0~1), (x = 1:4, y = 5:8)) fails #269

behinger opened this issue Jan 19, 2023 · 1 comment

Comments

@behinger
Copy link

I expected this to return a "empty" ModelMatrix (it is not really empty, as I wanted to get only the intercept via modelmatrix(mf)

MWE

df = (x = 1:4,)
mf = ModelFrame(@formula(x ~ 1 ), df) # works
mf = ModelFrame(@formula(0 ~ 1 +x ), df) # works
mf = ModelFrame(@formula(0 ~ 1 ), df) # throws error

The following error is thrown.

ERROR: ArgumentError: collection must be non-empty
Stacktrace:
 [1] first(itr::NamedTuple{(), Tuple{}})
   @ Base ./abstractarray.jl:425
 [2] missing_omit(d::NamedTuple{(), Tuple{}})
   @ StatsModels ~/.julia/packages/StatsModels/fK0P3/src/modelframe.jl:57
 [3] missing_omit(data::NamedTuple{(:x,), Tuple{UnitRange{Int64}}}, formula::FormulaTerm{ConstantTerm{Int64}, ConstantTerm{Int64}})
   @ StatsModels ~/.julia/packages/StatsModels/fK0P3/src/modelframe.jl:70
 [4] ModelFrame(f::FormulaTerm{ConstantTerm{Int64}, ConstantTerm{Int64}}, data::NamedTuple{(:x,), Tuple{UnitRange{Int64}}}; model::Type{StatisticalModel}, contrasts::Dict{Symbol, Any})
   @ StatsModels ~/.julia/packages/StatsModels/fK0P3/src/modelframe.jl:81
 [5] ModelFrame(f::FormulaTerm{ConstantTerm{Int64}, ConstantTerm{Int64}}, data::NamedTuple{(:x,), Tuple{UnitRange{Int64}}})
   @ StatsModels ~/.julia/packages/StatsModels/fK0P3/src/modelframe.jl:73
 [6] top-level scope
   @ REPL[175]:1
@kleinschmidt
Copy link
Member

Thanks for the report, definitely not an edge case I'd anticipated 😁 I think it's a pretty straightforward fix to add a check that d is non-empty in missing_omit(d) (and return it as-is if it is) if you'd like to make a PR!

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

No branches or pull requests

2 participants