Generalized Nonlinear Non-analytic Chi-Square Fitting

Performs chi-square fit with uncertainty estimation when measurement errors are known.
6.5K Downloads
Updated 1 Sep 2009

View License

fitChiSquare is a generalized chi-square fitting routine for any model function when data measurement errors are known; it returns the model parameters and their uncertainties at the delta chi-square = 1 boundary (68% confidence interval). It also returns the chi-square and degrees of freedom (dof) of the fit. The goodness-of-fit may be estimated by comparing chi-square/dof to 1 (<1 is a good fit; >>1 indicates a poor fit). Alternatively, it returns the fit and measurement errors when the model is known - see ErrorUnknown option.

Type "help fitChiSquare" or see the header for usage.

This function calculates the data variance from reported measurement errors, then calculates the chi-square fit. Then the function finds the projection of the delta chi^2 = 1 contour onto each parameter. In the case that the parameter uncertainties are normally distributed, the delta chi^2 = 1 method gives the 68% confidence limit for the parameters. Monte Carlo or investigations of many data sets should be used to confirm the parameter uncertainties are normally distributed.

Note that when used solely as a model fitter, fitChiSquare will generally run more slowly than fminsearch or lsqnonlin. If you are only interested in data optimization, it is recommended that you use one of the built-in functions.

If one encounters the following error message:

Unexpected termination flag 0 in non-estimating variable
minimization during uncertainty estimation

this is because the non-varying parameter minimization routine has encountered its iteration or evaluation limit. Raise UncOptions.MaxFunEvals or UncOptions.MaxIter and try again.

Note: If the user can not use lsqnonlin (i.e., the optimization toolbox is not installed), the program will use the built-in function fminsearch instead. This may reduce the robustness of the calculation.

References:
1. W.H. Press, B.P. Flannery, S.A. Teukolsky, W.T. Vetterling. Numerical Recipes; The Art of Scientific Computing. (Cambridge University Press: Cambridge). 1986.
2. P.R. Bevington, D.K. Robinson. Data Reduction and Error Analysis for the Physical Sciences. (McGraw-Hill: New York). 1992.

Cite As

Nathaniel Brahms (2026). Generalized Nonlinear Non-analytic Chi-Square Fitting (https://www.mathworks.com/matlabcentral/fileexchange/9592-generalized-nonlinear-non-analytic-chi-square-fitting), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
1.1.0.0

Minor bug fix, support for 4-parameter syntax.

1.0.0.0

Minor bug fix.