This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
fitting [Mon Oct 25 23:59:10 2010] Alexander |
fitting [Tue Apr 7 17:12:13 2020] Alexander |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Nonlinear Curve Fitting: Fit Plot ====== | ====== Nonlinear Curve Fitting: Fit Plot ====== | ||
- | Nonlinear least squares data fitting can be performed using Fit Plot. | ||
- | To create Fit Plot select x and y columns in table, then select '' | ||
- | 'Nonlinear' means here that analytical | + | ===== Creating a Fit Plot ===== |
+ | Nonlinear | ||
+ | To create | ||
- | To fit the data you must implement these steps: | + | {{: |
- | - Create Fit Plot, specify | + | |
+ | ==== MagicPlot has been verified with NIST Datasets ==== | ||
+ | National Institute of Standards and Technology (NIST) has created the Statistical Reference Datasets Project which includes [[http:// | ||
+ | |||
+ | ===== Fitting Methodology ===== | ||
+ | ' | ||
+ | Fit procedure iteratively varies the parameters of the fit function to minimize the residual sum of squares. The nonlinear fitting algorithm needs the user to set the initial values of fit parameters. | ||
+ | |||
+ | To fit the data, implement these steps: | ||
+ | - Create | ||
- Specify fit function by adding Fit Curves | - Specify fit function by adding Fit Curves | ||
- Specify initial values of fit parameters (drag curves or enter accurate values) | - Specify initial values of fit parameters (drag curves or enter accurate values) | ||
- | - Specify used x data interval | + | - Specify used X data interval |
- Run fitting | - Run fitting | ||
- | {{: | + | You can undo fit and also undo changing initial parameters as any other action using '' |
- | ===== Fit Function is a Sum of Fit Curves ===== | + | ==== Further reading |
- | MagicPlot considers fit function as a **sum** of Fit Curves. Ordinarily in peaks fitting each Fit Curve corresponds | + | This manual does not completely cover the complex nonlinear fitting methodology. We recommend you to take a look at this book: |
- | Fit Plot window contains the list of Fit Curves. Each Fit Curve in the list has 3 check boxes: '' | + | * H. Motulsky and A. Christopoulos, //Fitting Models to Biological Data Using Linear and Nonlinear Regression: A Practical Guide to Curve Fitting, 2004.// |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | Below the Fit Curves list is parameters table which shows parameters names, values, descriptions of the selected Fit Curve. | + | {{: |
- | ===== Coping | + | ===== Fit Function is a Sum of Fit Curves |
- | You can copy and paste Fit Curves in curves table as usual. Use context menu in curves table or press '' | + | MagicPlot considers fit function as a **sum** of Fit Curves. Ordinarily |
- | ===== Setting Initial Values | + | Fit Plot window contains the list of Fit Curves. |
- | Nonlinear fitting assumes that certain initial values of parameters are set before fitting. This procedure is just easy if you use predefined | + | |
- | Initial parameters values for each Fit Curve can also be set in parameters | + | {{: |
- | ===== Parameter Locking ===== | + | * '' |
- | You can lock parameter(s) | + | * '' |
+ | * '' | ||
- | ===== Fit Intervals ===== | + | Below the Fit Curves list, is a parameters table which shows names, values, and descriptions |
- | You can set the x intervals | + | |
- | Select | + | ==== Fitting by Sum and Fitting One Curve ==== |
- | * Double click on interval to split it | + | MagicPlot allows two alternatives buttons to run the fit: |
- | * Drag the interval border to move it. If intervals intersect, intervals | + | * '' |
- | * Use context menu on the plot to create, delete and split intervals | + | * '' |
- | | {{: | + | ==== Copying and Pasting Fit Curves ==== |
+ | You can copy and paste Fit Curves from one Fit Plot to another Fit Plot or Figure. You can also paste the copied Fit Curves to the same Fit Plot to create a copy. | ||
- | ===== Baseline Fitting and Extraction ===== | + | * The copy of Fit Curves with the same parameters |
- | Fit Interval is also usable when baseline fitting. Before baseline fitting you can specify | + | * A link to the source Fit Curves will be inserted if you paste Fit Curves in a Figure. |
- | Note that if you execute one of data processing algorithms (integration, | + | ==== Fit Curves Reordering ==== |
+ | You can reorder Fit Curves by dragging them in the table. The data curve is always drawn the first and fit sum is drawn the last. | ||
- | ===== ' | + | ===== Setting Initial Values of Parameters |
- | The ' | + | Nonlinear fitting assumes that certain initial values of parameters are set before fitting. This procedure |
- | It is ' | + | {{: |
- | Use ' | + | ==== Adjusting Parameters with Mouse Wheel ==== |
+ | You can adjust Parameters | ||
- | ===== Fit One Curve ===== | + | ===== Guessing Peaks ===== |
- | You can also use MagicPlot | + | If you are fitting a spectrum with multiple peaks, |
- | ===== Joining the Parameters of Fit Curves | + | ===== Parameter Locking |
- | In some cases you may want to fit the data with two Gauss or Lorentz peaks with the same width but different positions | + | You can lock (fix) parameter(s) |
- | To join parameters | + | {{: |
- | Joined parameters are showed with blue color (instead of black) in parameters | + | ===== Parameters Joining ===== |
+ | MagicPlot allows joining | ||
- | ===== Fitting Algorithm | + | ===== Weighting of Data Points Using Y Errors |
- | MagicPlot | + | MagicPlot |
- | Fit procedure iteratively varies the parameters // | + | Weights are calculated as '' |
- | < | + | Weights must be positive and finite for all points so the Y error values must be positive and non-zero |
- | here: | + | ===== Specifying Fit Intervals ===== |
- | * // | + | You can set the X intervals of the data which will be used for fitting. Data points |
- | * //N// is total number | + | |
- | * //f//(//x, β< | + | |
- | * //p// is the number of fit parameters // | + | |
- | * // | + | |
- | < | + | Select '' |
+ | * Double click on the interval to split it | ||
+ | * Drag the interval border to move it. If intervals intersect, they will be merged | ||
+ | * Use context menu on the plot to create, delete and split intervals | ||
- | The calculation of the new guess of parameters on each fit iteration is based on the fit function partial derivatives | + | **Note:** Data intervals from the '' |
- | <m>{partial f}/{partial beta_m}(x_i, beta_1, ..., beta_p)</ | + | {{: |
- | To start minimization, you have to provide an initial guess for the parameters. | + | ===== Baseline Fitting and Extraction ===== |
+ | Fit Interval is also usable when baseline fitting. Before baseline fitting, you can specify the interval which does not contain any signal points and contains baseline only. Set '' | ||
- | ==== Fit Procedure Stop Criteria ==== | + | Note that if you use data processing (integration, |
- | After each iteration except | + | |
- | < | + | ===== ' |
+ | The ' | ||
- | Deviation decrement shows how the residual sum of squares (< | + | Use 'Data-Baseline' |
- | + | ||
- | The iterative fit procedure stops on the one of two conditions: | + | |
- | * If the deviation decrement //D// is less than minimum allowable deviation decrement, which is 10< | + | |
- | 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 | + | |
- | + | ||
- | ==== Fit progress window ==== | + | |
- | + | ||
- | MagicPlot indicates fit process | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | MagicPlot shows current iteration number and deviation decrement by two progress bars while fit is performed. The fit process stops when one of this progress bars reaches the end. | + | |
- | Two buttons are located on fit progress window: | + | ===== Viewing the Residual Plot ===== |
- | * '' | + | Residual means here the difference between initial data, baseline function and Fit Sum function. MagicPlot offers two different ways to view the residual: |
- | * '' | + | * Press and hold the '' |
+ | * You can either set '' | ||
- | ===== Weighting of y data ===== | + | ===== Fitting |
- | MagicPlot can use weighting | + | To execute the fit click the '' |
- | * If standard //y// errors are **not** specified: all // | + | |
- | * If standard //y// errors // | + | |
- | < | + | MagicPlot indicates the fit process with a special window. Fitting curves are periodically updated on the plot while fitting so you can see how fit converges. |
- | here //C// is normalizing coefficient (to make the sum of // | + | {{:fit_progress.png? |
- | < | + | MagicPlot shows the current iteration number and deviation decrement with two progress bars while the fit is performed. The fit process stops when one of these progress bars reaches the end. |
- | In '' | + | You can see two buttons on fit progress window: |
- | * 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 | + | |
- | ===== Standard Deviation of Fit Parameters | + | ===== Fitting One Curve ===== |
- | The standard deviations (//std. dev.//) of fit parameters // | + | You can use MagicPlot to fit the data with single selected Fit Curve by pressing '' |
- | < | + | Because of using individual data interval this method is useful for baseline fitting. In order to fit baseline specify the intervals which do not contain signal (peaks) and contain only noise. |
- | here α is the matrix of partial derivatives of fit function by parameters // | + | {{:fit_one_curve.png? |
- | < | + | ===== Why My Fit is Not Converged? ===== |
+ | In some cases, the fit procedure may fail to find the optimal parameters values. The actual mathematical reason for this error is the impossibility to invert the matrix α calculated from partial derivatives of the fit function with respect to fit parameters. This inverted matrix is used to compute the new values of parameters for the next step of fit (like gradient descent). In most cases, this error occurs when the matrix α is ill-conditioned or nearly singular and the inverse cannot be calculated accurately enough with used floating-point arithmetic. | ||
- | ===== Formulas ===== | + | === The origin of this error may be: === |
- | In the table below you can find the formulas | + | * Fit is not converged through one or more parameters: some parameters were taking unrealistically great values during iterations. There is no local minimum of residual sum of squares near the initial values of these parameters. MagicPlot highlights |
+ | * Mutual dependency exists between some parameters. The algorithm cannot resolve | ||
+ | * Fit function is ill-conditioned: | ||
+ | * Numeric overflow (or underflow) when calculating fit function with initial parameter | ||
- | Because | + | === Try one of the following: === |
+ | * Specify more accurate initial values | ||
+ | * Simplify the fit function | ||
+ | * Lock some parameters. | ||
- | ^ Parameter Name ^ Symbol | + | ===== See Also ===== |
- | ^ Original Data and Fit Model Properties | + | |
- | | Number of used data points | + | |
- | | Fit parameters | + | |
- | | Number of fit function parameters //β// | < | + | |
- | | [[wp> | + | |
- | | Estimated mean of data | < | + | |
- | | Estimated variance of data | < | + | |
- | | Data total sum of squares, TSS | TSS | < | + | |
- | ^ Fit Result | + | |
- | | Residual sum of squares, < | + | |
- | | Reduced // | + | |
- | | Standard deviation of the model | //s// | < | + | |
- | | [[wp> | + | |
- | | Adjusted // | + |