MagicPlot Manual

Plotting and nonlinear fitting software

User Tools

Site Tools


This is an old revision of the document!

Fitting Algorithm and Computational Formulas

MagicPlot uses iterative Levenberg–Marquardt nonlinear least squares curve fitting algorithm which is widely used in most software.

Fit procedure iteratively varies the parameters βk of fit function f(x, β1, …, βp) to minimize the residual sum of squares (RSS, χ2):

chi^2 = sum{i=1}{N}{w_i(y_i – f(x_i, beta_1, ..., beta_p))^2} right min


  • xi and yi are the data points,
  • N is total number of points,
  • f(x, β1,…,βp) is the fit function which depends on value of x and fit parameters βk,
  • p is the number of fit parameters βk,
  • wi are normalized y data weighting coefficients for each point yi:

sum{i=1}{N}{w_i} = 1

Calculation of the new guess of parameters on each fit iteration is based on the fit function partial derivatives for current values of fit parameters and for each x value:

{partial f}/{partial beta_m}(x_i, beta_1, ..., beta_p)

To start minimization, you have to provide an initial guess for the parameters.

Weighting of Data Points Using Y Errors

MagicPlot can use weighting of y values based on y errors si:

  • If standard y errors are not specified: all wi=1
  • If standard y errors si are specified:

w_i=C 1/{{s_i}^2}

here C is normalizing coefficient (to make the sum of wi be equal to one):


In Fit Plot Properties dialog (Plot Data tab) you can set one of the following methods to evaluate standard y errors si:

  • Get y errors from table column(s),
  • Percent of data for every point,
  • Fixed value or Standard deviation — do not use in weighting because in this case the error values are the same for all data points.

Fit Procedure Stop Criteria

After each iteration except the first MagicPlot evaluates deviation decrement D:

D = delim{|} {{chi^2}_{curr. iter.} / {chi^2}_{prev. iter.} – 1} {|}

Deviation decrement shows how the residual sum of squares (RSS) on current iteration relatively differs from that on the previous iteration.

The iterative fit procedure stops on one of two conditions:

  • If the deviation decrements D for two last iterations is less than minimum allowable deviation decrement, which is 10-9 by default

or (and)

  • If the number of iterations exceeds maximum number of iterations, which is 100 by default

You can change the minimum allowable deviation decrement and maximum number of iterations in Fitting tab of MagicPlot Preferences.


In the table below you can find the formulas which MagicPlot uses to calculate fit parameters and values in Fit Report tab.

Because of some confusion in the names of the parameters in different sources (books and software), we also give many different names of same parameter in note column.

Parameter Name Symbol Formula Note
Original Data and Fit Model Properties
Number of used data points N This is the number of data points inside specified Fit Interval.
Fit parameters β1,…,βp For peak-like functions (Gauss, Lorentz) these parameters are amplitude, position and half width at half maximum.
Number of fit function parameters β p This is the total number of parameters of all fit curves which are summarized to fit.
Degrees of freedom nu N–p
Estimated mean of data overline{y} 1/N sum{i=1}{N}{y_i}
Estimated variance of data s^2 1/{N–1} sum{i=1}{N}{(y_i – overline{y})^2} Not used by fit algorithm, only for comparison.
Data total sum of squares, TSS TSS sum{i=1}{N}{w_i(y_i – overline{y})^2} TSS is also called sum of squares about the mean and acronym SST is also used.
Fit Result
Residual sum of squares, RSS chi^2 sum{i=1}{N}{w_i(y_i – f(x_i,beta_1,...,beta_p))^2} This value is minimized during the fit to find the optimal fit function parameters.
RSS is also called the sum of squared residuals (SSR), the error sum of squares (ESS), the sum of squares due to error (SSE).
Reduced χ2 {{chi^2}_{red.}} {chi^2}/nu = {chi^2}/{N–p} The advantage of the reduced chi-squared is that it already normalizes for the number of data points and model (fit function) complexity.
Reduced χ2 is also called mean square error (MSE) or the residual mean square.
Residual Standard Deviation s sqrt({chi^2}_{red.}) Standard deviation is also called root mean square of the error (Root MSE)
Coefficient of determination R^2 1 – {chi^2}/TSS R2 will be equal to one if fit is perfect, and to zero otherwise. This is a biased estimate of the population R2, and will never decrease if additional fit parameters (fit curves) are added, even if they are irrelevant.
Adjusted R2 overline{R}^2 1 – {N–1}/{N–p–1}(1–R^2) Adjusted R2 (or degrees of freedom adjusted R-square) is a slightly modified version of R2, designed to penalize for the excess number of fit parameters (fit curves) which do not add to the explanatory power of the regression. This statistic is always smaller than R2, can decrease as you add new fit curves, and even be negative for poorly fitting models
Covariance Matrix of Parameters βk Sigma {chi^2}/{N–p} alpha^{–1} Here α is the matrix of partial derivatives of fit function with respect to parameters βm and βn which is used for fitting:
alpha_{m,n}=sum{i=1}{N}{w_i {{partial f}/{partial beta_m}(x_i, beta_1, ..., beta_p) {partial f}/{partial beta_n}}{(x_i, beta_1, ..., beta_p)}}
Standard Deviation of Parameters βk,
std. dev.
s_k sqrt{Sigma_{k,k}}
Correlation Matrix of Parameters βk C C_{i,j}=Sigma_{i,j} / {s_i s_j}

See Also

fit_formulas.1298580777.txt.gz · Last modified: Sun Nov 8 12:20:32 2015 (external edit)