API Reference

Start with Quickstart for a first fit or the Statistics Reference for the derivations behind each method.

Choose An Entry Point

Data and sampling modelEntry pointModel contractResult
Numeric $x$ and $y$ with Gaussian uncertaintiesfit_modelmodel(x, p) -> y_hatFitResult
Independent observations with a custom distributionfit_likelihood_modelmodel(x, p) and logprob(y, y_hat, p)LikelihoodFitResult
Events described by an upstream distributionfit_distributionmake_distribution(p) -> Distribution; with using BuildConstructors, an AbstractConstructor can replace the factory (see fit_distribution)LikelihoodFitResult
Binned events described by an upstream distributionfit_distributionSame factory with edges, counts; a normalized distribution requires total_count, an ExtendedMixtureModel (DistributionsHEP) fits its component yields insteadLikelihoodFitResult
Independent countsfit_poisson_modelmodel(x, p) -> expected_countsLikelihoodFitResult
Histogram with expected bin countsfit_histogram_modelexpected_counts(edges, p) -> muLikelihoodFitResult
Histogram from a normalized densityfit_histogram_densitypdf(x, p) -> densityLikelihoodFitResult
Independent unbinned observationsfit_unbinned_modelpdf(x, p) -> densityLikelihoodFitResult
Unbinned events with a parameter-dependent ratefit_extended_unbinned_modelrate(x, p) -> event_rateLikelihoodFitResult
Observations addressed by non-numeric indicesfit_indexed_modelmodel(indices, p) -> y_hatLikelihoodFitResult
Several datasets sharing parametersfit_multi_modelone model_i(x_i, p_i) per datasetLikelihoodFitResult
A custom scalar objectivefit_customobjective(p) -> scalarLikelihoodFitResult

Typical minimal calls. p0 is required everywhere, nobs for fit_custom, and exactly one of logprob/error for fit_likelihood_model; the uncertainty keywords shown are optional but recommended, and total_count shows its default:

Entry pointMinimal call
fit_modelfit_model(model, x, y; p0=[...], sigma_y=[...])
fit_likelihood_modelfit_likelihood_model(model, x, y; p0=[...], logprob=logprob)
fit_distributionfit_distribution(make_distribution, observations; p0=[...])
fit_poisson_modelfit_poisson_model(expected_counts, x, counts; p0=[...])
fit_histogram_modelfit_histogram_model(expected_per_bin, edges, counts; p0=[...])
fit_histogram_densityfit_histogram_density(pdf, edges, counts; p0=[...], total_count=sum(counts))
fit_unbinned_modelfit_unbinned_model(pdf, observations; p0=[...])
fit_extended_unbinned_modelfit_extended_unbinned_model(rate, observations, (a, b); p0=[...])
fit_indexed_modelfit_indexed_model(model, indices, y; p0=[...], cov_y=C)
fit_multi_modelfit_multi_model(models, xs, ys; p0=[...], sigma_y=sigma_sets)
fit_customfit_custom(cost; p0=[...], nobs=n)

Complete analyses are in the Gallery.

For reusable low-level workflows, construct FitProblem or LikelihoodFitProblem and call fit, which extends the StatsAPI.fit generic.

Common Conventions

Parameters And Model Functions

p0 fixes the parameter order. Indices in bounds, fixed values, constraints, profiles, and contours are one-based into that vector.

The allocating model contract is:

model(x, p) -> vector with length(y)

For allocation-sensitive fits, use:

model!(out, x, p)
jacobian!(J, x, p)  # optional

and pass inplace=true; ScientificFitting validates that the callbacks fill every output. On automatic-differentiation paths, p, out, and J may contain non-Float64 scalar types; mutating functions must not hard-code Float64 buffers.

Input observations and starting values are copied to Float64 storage; models must return finite values wherever the solver evaluates them.

Parameter Control

fit_model and the likelihood wrappers accept:

KeywordMeaning
p0Required complete starting vector.
bounds=(lower, upper)Componentwise closed bounds; use +/-Inf for an open side.
fixed_parametersRemove parameters from the optimizer with FixedParameter, i => value, or equivalent named tuples.
parameter_priorsIndependent normalized Gaussian or split-normal terms.
parameter_constraintsCorrelated Gaussian terms on selected parameters.
constraintsGeneral nonlinear constraints; ineq(p) <= 0 and eq(p) == 0.

A FixedParameter uncertainty is report metadata, never an objective term; see FixedParameter and Fixed Parameters And Bounds.

Solver Control

KeywordDefaultContract
solvernothingnothing selects the backend automatically (see Backend Design). Explicit choices: OptimizationSolver(algorithm), NativeMinuitSolver(), or a shorthand :lbfgs, :ipnewton, :nelder_mead.
maxiters500 for fit_model, 1000 for likelihood wrappersPositive per-candidate budget: iterations for LsqFit/Optim, objective calls for NLopt/NativeMinuit.
tolnothing → default_fit_tolerancePositive solver-specific stopping tolerance, not a statistical error: 1e-10 for LsqFit/Optimization (1e-6 with derivatives=:finite), EDM 0.1 for NativeMinuit; see Solver Adapters.
derivatives:auto:auto or :finite; finite differencing for models that cannot evaluate dual numbers, see FitProblem.
initial_guessesnothingAdditional complete starting vectors.
multistart1Total candidate budget including p0. Explicit initial_guesses are always tried, even at the default; values above 1 + length(initial_guesses) add deterministic generated candidates (bound midpoints and quartiles, or scaled p0).

fit_model additionally accepts:

KeywordDefaultContract
cost:auto:chi2 or full :gaussian_likelihood on the $-2\log L$ scale; :auto uses the latter for parameter-dependent covariance.
scale_covariance:auto:auto, :always, or :never; see Parameter Covariance.
jacobiannothingAnalytic model Jacobian, allocating or in-place according to inplace.
x_derivativenothingFunction (x, p) -> dy_dx returning the model derivative $\partial f/\partial x$ at every observation (one value per point); replaces the default per-point AD path for x-uncertainty propagation.

The likelihood wrappers accept parameter_covariance (:auto, :hessian, :none) in place of scale_covariance; see Fitting.

Automatic backend routing is specified in Backend Design; result.backend records the choice.

Reference Sections

NeedReference
Fit inputs, uncertainty objects, constraints, likelihoods, and solver behaviorFitting
Result fields, covariance, profiles, contours, diagnostics, and reportsResults And Diagnostics
Optional Makie boundary, fit figures, annotations, and visual contractsFit Plotting
Residual, pull, profile, contour, and profile-matrix figuresDiagnostic Plotting