StatsBase Fit function

Hi there :slight_smile:

I’m trying to figure out how the fit function in StatsBase was programmed. I’m curious to see what method was used and how the tolerance is managed. I already looked in the documentation Abstraction for Statistical Models · StatsBase.jl and found myself inside the Github of the package https://github.com/JuliaStats/StatsBase.jl/blob/08d4b77a4b42ef8cadb67b98da65e7fbd9959e0b/src/statmodels.jl only to find that the fit function is called using a function called fit jajaja. I mean, when I look up the fit function, this comes up:

“Fit a statistical model.
“””
fit(model::StatisticalModel, args…) = error(“fit is not defined for $(typeof(model)).”)"

I can’t find the use or programming of the fit function anywhere else in this documentation nor in the StatsModels documentation. This function came along with Julia or am I missing something?

Thank you in advance :slight_smile:

try @which and then you can @edit it.

julia> @which fit(Histogram, rand(100))
fit(::Type{Histogram}, args...; kwargs...) in StatsBase at C:\Users\woclass\.julia\packages\StatsBase\Q76Ni\src\hist.jl:383

julia> @which fit(ZScoreTransform, rand(100))
fit(::Type{ZScoreTransform}, X::AbstractVector{var"#s258"} where var"#s258"<:Real; dims, center, scale) in StatsBase at C:\Users\woclass\.julia\packages\StatsBase\Q76Ni\src\transformations.jl:130

julia> @which fit(UnitRangeTransform, rand(100))
fit(::Type{UnitRangeTransform}, X::AbstractVector{var"#s130"} where var"#s130"<:Real; dims, unit) in StatsBase at C:\Users\woclass\.julia\packages\StatsBase\Q76Ni\src\transformations.jl:287

fit(model::StatisticalModel, args...) = error("fit is not defined for $(typeof(model)).")

The definition here is more like a fallback method.
If the input param type does not have a fit function defined on it will throw an error.

4 Likes