StatsBase Fit function

Hi there :slight_smile:

I鈥檓 trying to figure out how the fit function in StatsBase was programmed. I鈥檓 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 StatsBase.jl/statmodels.jl at 08d4b77a4b42ef8cadb67b98da65e7fbd9959e0b 路 JuliaStats/StatsBase.jl 路 GitHub 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:

鈥淔it a statistical model.
鈥溾濃
fit(model::StatisticalModel, args鈥) = error(鈥渇it is not defined for $(typeof(model)).鈥)"

I can鈥檛 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.

3 Likes