You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Took me quite a while to figure out what exactly was happening here (realised something weird was happening when running model = fit(LinearModel, @formula(date_numeric ~ num), df_test); in the REPL worked, but didn't work when I didn't suppress the display (i.e., when I removed the semicolon).
The text was updated successfully, but these errors were encountered:
The problem is that variables with eltype Any are treated as categorical. You get the same error by wrapping num in a CategoricalArray. So the underlying problem is that coeftable fails for a model with zero residual degrees of freedom. See #458.
I agree with the OP that the error message could be improved here. Here is another case, which I just found when reading data from an Excel sheet with XLSX.readtable (it parses everything as Any by default).
julia> d = DataFrame(Y = Any[1,2,3], X = Any[3,2,1])
3×2 DataFrame
Row │ Y X
│ Any Any
─────┼──────────
1 │ 1 3
2 │ 2 2
3 │ 3 1
julia> lm(@formula(Y ~ X), d)
ERROR: MethodError: no method matching fit(::Type{LinearModel}, ::Matrix{Float64}, ::Matrix{Float64}, ::Nothing)
Closest candidates are:
fit(::StatisticalModel, ::Any...) at /Users/74097/.julia/packages/StatsBase/IPydo/src/statmodels.jl:178
fit(::Type{StatsBase.Histogram}, ::Any...; kwargs...) at /Users/74097/.julia/packages/StatsBase/IPydo/src/hist.jl:383
fit(::Type{LinearModel}, ::AbstractMatrix{var"#s49"} where var"#s49"<:Real, ::AbstractVector{var"#s50"} where var"#s50"<:Real, ::Union{Nothing, Bool}; wts, dropcollinear) at /Users/74097/.julia/packages/GLM/hDWc9/src/lm.jl:156
can we not check for the element type of each column and show a warning if we find Any?
The linear model is failing somewhere in
show
(I guess) if you give itDataFrame
s with typeAny
. MWE:Took me quite a while to figure out what exactly was happening here (realised something weird was happening when running
model = fit(LinearModel, @formula(date_numeric ~ num), df_test);
in the REPL worked, but didn't work when I didn't suppress the display (i.e., when I removed the semicolon).The text was updated successfully, but these errors were encountered: