Curve Fitting

Curve fitting allows for powerful analysis of imported datasets by finding the parameters of a mathematical model that best describes the data. The following topics are covered in this page:

Fitting Data

To start curve fitting on a dataset, press the three vertical dots on the item you want to fit and choose Curve Fitting. This opens the Curve Fitting dialog. The fit and its confidence band are previewed live as parameters are adjusted.

An equation to fit against is chosen from the dropdown. The following predefined equations are available, with their formula shown as a subtitle:

Linear

a·x + b

Quadratic

a·x² + b·x + c

Exponential

a·exp(b·x)

Power Law

a·x^b

Logarithmic

a·log(x) + b

Sigmoid Logistic

L / (1 + exp(-k·(x - b)))

Gaussian

a·exp(-(x - μ)² / (2·σ²))

Custom

Enter any equation using x as the independent variable. Any other variable names that are not functions (such as sin(x) or exp(x)) are automatically detected and treated as free parameters to be fitted.

Once a satisfactory fit is found, press Add Fit to Data to add the resulting curve as a new equation in the project, with the fitted parameter values substituted into the expression.

Bounds

Each free parameter detected in the equation is shown in the sidebar with three fields: an initial guess, a minimum bound, and a maximum bound. The initial guess is the starting value used by the algorithm. Using a good initial guess close to the expected value will help the fit converge. The bounds constrain the range of values the parameter is allowed to take.

The bounds fields default to -inf and inf, meaning no constraints are applied. To restrict a parameter, enter the desired minimum and maximum values.

Note that bounds fields are only shown when an algorithm that supports them is selected. When using Levenberg-Marquardt, bounds are hidden as that algorithm does not support them. See Fitting Algorithmsfor details.

Results

After a successful fit the results panel shows two sections: Parameters and Statistics.

The Parameters section lists each fitted parameter with its value. If a confidence level other than None is selected, a margin is shown next to each value in the form ± error, where the error is the standard deviation of that parameter multiplied by the selected confidence factor. So for a confidence level of 1σ the error is equal to the standard deviation, and for 2σ and 3σ the error is equal to twice and three times the standard deviation respectively. The confidence level can be set from the primary menu:

  • None: no margin shown.

  • 1σ: 68% Confidence

  • 2σ: 95% Confidence

  • 3σ: 99.7% Confidence

The corresponding confidence band is also drawn as a shaded region around the fitted curve.

The Statistics section shows two goodness-of-fit measures: R² and RMSE.

For a linear fit, R² measures how what proportion of the variation can be explained by the model. A value of 1 means the model explains all variation perfectly, while a value of 0 means it explains none. Note that for non-linear fits, the R² loses its physical meaning of what proportion of the variance is explained. It can still be somewhat useful to assess the goodness-of-fit, but the value itself becomes somewhat arbitrary.

RMSE (Root Mean Square Error) measures the typical size of the residuals (the differences between the data points and the fitted curve) in the same units as the Y data. Unlike R², RMSE gives an absolute sense of how far off the predictions are on average, which makes it useful when the physical magnitude of the error matters.

Note that both statistics reflect only how well the data agrees with the chosen model, not whether the model is physically correct. Factors such as systematic measurement errors and correlations between parameters are not accounted for. This is an inherent limitation of curve fitting, and a common source of misleading uncertainty estimates even in published scientific work.

Residuals

The residuals plot can be shown by enabling Show Residuals from within the primary menu. This displays a second plot below the main one showing the difference between each data point and the fitted curve at that x-value. A dashed line at zero is shown for reference.

A good fit will show residuals scattered randomly around zero with no visible pattern. A systematic pattern in the residuals, such as a curve or a trend suggests that the chosen model may not be appropriate for the data.

Error Messages

If the fit cannot be completed, an error message is shown in the results panel instead of the parameter values. The following errors can occur:

Invalid equation

The equation contains a syntax error or uses unsupported variables. Check that the expression is valid.

Constraint error

The initial guess does not lie within the specified bounds, or the minimum bound is not smaller than the maximum. Ensure that Lower < Initial < Upper for each parameter.

Domain error

The equation is not valid over the range of the data, for example due to a logarithm of a negative number or a division by zero.

Fit failed: max iterations reached

The algorithm did not converge within the allowed number of iterations. Try adjusting the initial guesses to be closer to the expected values, or choose a different algorithm.

Matrix error

The data is insufficient for the chosen model. This can happen for example when there are fewer data points than free parameters, or if the data does not constrain the model well enough to determine a unique solution.

Confidence band error

The covariance matrix is unstable, so the confidence band cannot be computed reliably.

Fitting Algorithms

Three fitting algorithms are available, selectable from the primary menu under Optimization Method:

Levenberg-Marquardt

A widely used algorithm that performs efficiently for most problems. Does not support parameter bounds, the minimum and maximum fields are hidden when this method is selected.

Trust Region Reflective

Handles bounds well and performs reliably across a wide range of problems. A good default choice for most use cases.

Dogbox

Uses rectangular trust regions and is well suited to smaller problems where bounds are required.