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

More helpful errors #483

Open
ParadaCarleton opened this issue Apr 29, 2022 · 1 comment
Open

More helpful errors #483

ParadaCarleton opened this issue Apr 29, 2022 · 1 comment

Comments

@ParadaCarleton
Copy link

ParadaCarleton commented Apr 29, 2022

julia> model = glm(@formula(y~x), data)
ERROR: MethodError: no method matching fit(::Type{GeneralizedLinearModel}, ::Matrix{Float64}, ::Vector{Float64})
Closest candidates are:
  fit(::Type{M}, ::AbstractMatrix{<:AbstractFloat}, ::AbstractVector{<:Real}, ::Distributions.UnivariateDistribution) where M<:GLM.AbstractGLM at ~/.julia/packages/GLM/DgddX/src/glmfit.jl:471
  fit(::Type{M}, ::AbstractMatrix{<:AbstractFloat}, ::AbstractVector{<:Real}, ::Distributions.UnivariateDistribution, ::Link; dofit, wts, offset, fitargs...) where M<:GLM.AbstractGLM at ~/.julia/packages/GLM/DgddX/src/glmfit.jl:471
  fit(::Type{M}, ::AbstractMatrix, ::AbstractVector, ::Distributions.UnivariateDistribution) where M<:GLM.AbstractGLM at ~/.julia/packages/GLM/DgddX/src/glmfit.jl:495

The error here was caused by forgetting to add a distribution. However, it might not be immediately clear to a user that the problem is a missing argument for glm (not fit). We could improve this by throwing an error saying glm requires a distribution.

model = glm(@formula(y~x), data, Normal)
ERROR: MethodError: no method matching fit(::Type{GeneralizedLinearModel}, ::Matrix{Float64}, ::Vector{Float64}, ::Type{Normal})
Closest candidates are:
  fit(::Type{StatsBase.Histogram}, ::Any...; kwargs...) at ~/.julia/packages/StatsBase/pJqvO/src/hist.jl:383
  fit(::Type{T}, ::FormulaTerm, ::Any, ::Any...; contrasts, kwargs...) where T<:RegressionModel at ~/.julia/packages/StatsModels/57Kc9/src/statsmodel.jl:78
  fit(::Type{T}, ::FormulaTerm, ::Any, ::Any...; contrasts, kwargs...) where T<:StatisticalModel at ~/.julia/packages/StatsModels/57Kc9/src/statsmodel.jl:78

Passing a type rather than a distribution caused the error here, but this is also not clear for a new user.

@nalimilan
Copy link
Member

Yeah the signature of glm should be made stricter, to match that of fit. Would you make a PR?

Having a method that throws an error if a type is passed rather than an instance for the distribution could make sense. We could almost allow passing either...

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

No branches or pull requests

3 participants