# StatsBase Fit function

**URL:** <https://discourse.julialang.org/t/statsbase-fit-function/71234>\
**Category:** Internals & Design\
**Tags:** package, statistics, regression\
**Created:** [November 9, 2021, 11:49pm UTC](https://discourse.julialang.org/t/statsbase-fit-function/71234 "2021-11-09T23:49:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![valperez](https://avatars.discourse-cdn.com/v4/letter/v/e79b87/32.png) [@valperez](https://discourse.julialang.org/u/valperez)\
**Post date:** [November 9, 2021, 11:49pm UTC](https://discourse.julialang.org/t/statsbase-fit-function/71234/1 "2021-11-09T23:49:49Z")

</div>

Hi there 🙂

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](https://juliastats.org/StatsBase.jl/stable/statmodels/) and found myself inside the Github of the package [https://github.com/JuliaStats/StatsBase.jl/blob/08d4b77a4b42ef8cadb67b98da65e7fbd9959e0b/src/statmodels.jl](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 🙂

---

<div class="post-metadata">

**Author:** ![woclass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woclass/32/212699_2.png) [@woclass](https://discourse.julialang.org/u/woclass)\
**Post date:** [November 10, 2021, 5:13am UTC](https://discourse.julialang.org/t/statsbase-fit-function/71234/2 "2021-11-10T05:13:20Z")

</div>

try `@which` and then you can `@edit` it.

```julia
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

```

* * *

```julia
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.
