Solutions
Curve fitting results are returned as CurveFitSolution objects. These objects store the fitted coefficients, residuals, the problem solved and the algorithm used to solve it. It also stores a return code which holds information about the success of the solver. For more information on the ReturnCode type, see SciMLBase.jl.
CurveFit.CurveFitSolution — Type
CurveFitSolution(alg, coeffs, resid, prob, retcode, original=nothing)Represents the solution to a curve fitting problem. This is a callable struct and can be used to evaluate the solution at a point. Exact evaluation mechanism depends on the algorithm used to solve the problem.
StatsAPI functions
CurveFitSolution objects can be treated as statistical models and CurveFit defines various statistics methods for the CurveFitSolution type, many of which extend StatsAPI.jl functions.
StatsAPI.residuals — Function
residuals(sol::CurveFitSolution)Return the residuals of the fitted model.
Residuals are defined as the difference between the observed data and the model predictions evaluated at the fitted coefficients.
CurveFit.mse — Function
mse(sol::CurveFitSolution)Return the mean squared error of the fit.
The mean squared error is computed as rss(sol) / dof_residual(sol).
StatsAPI.dof — Function
dof(sol::CurveFitSolution)Return the number of degrees of freedom of the model.
StatsAPI.dof_residual — Function
dof_residual(sol::CurveFitSolution)Return the residual degrees of freedom.
This is defined as nobs(sol) - dof(sol).
StatsAPI.predict — Function
predict(sol::CurveFitSolution, x = sol.prob.x)Evaluate the fitted model with new data.
If x is not provided, predictions are returned at the original data points used during fitting.
StatsAPI.coef — Function
coef(sol::CurveFitSolution)Return the fitted coefficients.
The ordering of coefficients depends on the fitting algorithm used.
StatsAPI.nobs — Function
nobs(sol::CurveFitSolution)Return the number of observations used in the fit.
StatsAPI.fitted — Function
fitted(sol::CurveFitSolution)Return the fitted values at the original data points.
StatsAPI.rss — Function
rss(sol::CurveFitSolution)Return the residual sum of squares (RSS).
This is defined as sum(abs2, residuals(sol)).
CurveFit.isconverged — Function
isconverged(sol::CurveFitSolution)Return true if the underlying solver successfully converged.
This is determined from the solver return code.
StatsAPI.vcov — Function
vcov(sol::CurveFitSolution)Return the variance–covariance matrix of the fitted coefficients.
The covariance matrix is computed using the Jacobian of the fitted model and a QR-based least squares formulation. This function is defined for solutions to both linear and nonlinear problems.
StatsAPI.stderror — Function
stderror(sol::CurveFitSolution; rtol = NaN, atol = 0)Return the standard errors of the fitted coefficients.
Standard errors are computed as the square roots of the diagonal elements of the variance–covariance matrix.
CurveFit.margin_error — Function
margin_error(sol::CurveFitSolution, alpha = 0.05; rtol::Real = NaN, atol::Real = 0)Returns the margin of error of the fitted coefficients, computed as stderror(sol) * t where t is the critical value of the t-distribution for `1
- alpha / 2`.
StatsAPI.confint — Function
confint(sol::CurveFitSolution; level = 0.95, rtol = NaN, atol = 0)Return confidence intervals for the fitted parameters.
The confidence intervals are returned as a vector of (lower, upper) tuples, computed as coef(sol) ± margin_error(sol).