This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
fitting [Tue Feb 22 13:26:11 2011] Alexander |
fitting [Mon Jun 4 14:15:05 2018] 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 a Fit Plot, select x and y columns in table, then select '' | ||
- | ' | + | ===== Creating a Fit Plot ===== |
+ | Nonlinear least squares data fitting (nonlinear regression) can be performed using Fit Plot. | ||
+ | To create a Fit Plot, select your X and Y columns in Table, then select '' | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== MagicPlot has been verified with NIST Datasets ==== | ||
+ | National Institute of Standards and Technology (NIST) has created Statistical Reference Datasets Project which includes [[http:// | ||
+ | |||
+ | ===== Fitting Methodology ===== | ||
+ | ' | ||
+ | Fit procedure iteratively varies | ||
To fit the data, implement these steps: | To fit the data, implement these steps: | ||
- | - Create a Fit Plot, specify | + | - Create a Fit Plot, specify |
- 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 '' |
- | ===== Further reading | + | ==== Further reading ==== |
This manual does not completely cover the complex nonlinear fitting methodology. We recommend you to take a look at this book: | This manual does not completely cover the complex nonlinear fitting methodology. We recommend you to take a look at this book: | ||
- | * H. Motulsky and A. Christopoulos, | + | * H. Motulsky and A. Christopoulos, |
+ | |||
+ | {{: | ||
===== Fit Function is a Sum of Fit Curves ===== | ===== Fit Function is a Sum of Fit Curves ===== | ||
- | MagicPlot considers fit function as a **sum** of Fit Curves. Ordinarily in peaks fitting each Fit Curve corresponds to one peak in experimental data. There is a number of predefined Fit Curves (Line, Parabola, Gauss, Lorentz, etc.) You can also specify | + | MagicPlot considers fit function as a **sum** of Fit Curves. Ordinarily in peaks fitting each Fit Curve corresponds to one peak in experimental data. Click the '' |
+ | |||
+ | Fit Plot window contains the list of Fit Curves. Each Fit Curve in the list has three checkboxes: | ||
+ | |||
+ | {{: | ||
- | Fit Plot window contains the list of Fit Curves. Each Fit Curve in the list has three checkboxes: '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
* '' | * '' | ||
Below the Fit Curves list is a parameters table which shows names, values, and descriptions of parameters relating to selected Fit Curve. | Below the Fit Curves list is a parameters table which shows names, values, and descriptions of parameters relating to selected Fit Curve. | ||
- | ===== Copying Fit Curves from One Fit Plot to Another ===== | + | ==== Fitting by Sum and Fitting |
- | You can copy and paste Fit Curves in curves table as usual. Use context menu in curves table or press '' | + | MagicPlot allows two alternatives buttons to run the fit: |
+ | * '' | ||
+ | * '' | ||
- | ===== Setting Initial Values of Parameters ===== | + | ==== Copying and Pasting Fit Curves |
- | Nonlinear fitting assumes that certain initial values of parameters are set before fitting. This procedure is very easy if you use predefined | + | You can copy and paste Fit Curves |
- | Initial | + | * The copy of Fit Curves with the same parameters |
+ | * A link to the source Fit Curves will be inserted if you paste Fit Curves | ||
- | ===== Parameter Locking ===== | + | ==== Fit Curves Reordering |
- | You can lock parameter(s) to prevent varying this parameter during fit and to prevent its changing due to setting initial values | + | You can reorder Fit Curves |
- | ===== Fit Intervals | + | ===== Setting Initial Values of Parameters |
- | You can set the x intervals of the data. Data points outside these intervals are not used to compute the minimizing residual sum of squares | + | Nonlinear fitting assumes that certain initial values of parameters are set before fitting. This procedure is very easy if you use Fit Curves |
- | Select '' | + | {{:moving_curves.png? |
- | * Double click on 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 | + | |
- | | {{:interval_context_menu2.png|Interval context menu}} | {{: | + | ==== Adjusting Parameters with Mouse Wheel ==== |
+ | You can adjust Parameters in table using mouse wheel scrolling when mouse cursor is on the desired parameter: Hold Ctrl key (Cmd key on Mac) and scroll. If Shift key is also pressed the parameter step for one wheel ' | ||
- | ===== Baseline Fitting and Extraction | + | ===== Guessing Peaks ===== |
- | Fit Interval is also usable when baseline | + | If you are fitting |
- | The most appropriate curve type for baseline fitting is [[spline|spline]]. | + | ===== Parameter Locking ===== |
+ | You can lock (fix) parameter(s) to prevent varying this parameter(s) during fit and to prevent its changing due to setting initial values by mouse dragging (for built-in functions). Set the checkbox in '' | ||
- | Note that if you execute one of data processing algorithms (integration, | + | {{: |
- | ===== ' | + | ===== Parameters Joining |
- | The ' | + | MagicPlot allows joining (sometimes referred |
- | It is 'Data-Baseline' | + | ===== Weighting of Data Points Using Y Errors ===== |
+ | MagicPlot allows data points weighting with Y error data. You can specify Y error data in Fit Plot properties dialog. If no Y error data are specified weighting is not used. | ||
- | Use ' | + | Weights are calculated |
- | ===== Viewing the Difference between Data and Fit Sum Function (Residual) ===== | + | Weights must be positive |
- | MagicPlot offers two different ways to view the difference between data and Fit Sum function: | + | |
- | * You can set '' | + | |
- | or | + | |
- | * You can press and hold '' | + | |
- | ===== Fit One Curve ===== | + | ===== Specifying |
- | You can also use MagicPlot to fit the data with single selected Fit Curve by pressing '' | + | You can set the X intervals of the data which will be used for fitting. Data points outside these intervals are not used to compute |
- | Because of using individual data interval this method is useful for baseline fitting. In order to fit baseline specify | + | Select '' |
+ | * Double click on interval | ||
+ | * Drag the interval border to move it. If intervals | ||
+ | * Use context menu on the plot to create, delete | ||
- | ===== Joining the Parameters of Fit Curves ===== | + | **Note:** Data intervals from '' |
- | MagicPlot allows coupling of fit parameters. See [[joining]] | + | |
- | ===== Fitting Algorithm ===== | + | {{: |
- | MagicPlot uses iterative [[wp> | + | |
- | Fit procedure iteratively varies | + | ===== Baseline Fitting and Extraction ===== |
+ | Fit Interval is also usable when baseline fitting. Before baseline fitting you can specify | ||
- | < | + | Note that if you use data processing |
- | here: | + | ===== ' |
- | * // | + | The ' |
- | * //N// is total number of points, | + | |
- | * //f//(//x, β< | + | |
- | * //p// is the number of fit parameters // | + | |
- | * // | + | |
- | < | + | Use ' |
- | + | ||
- | 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: | + | |
- | + | ||
- | < | + | |
- | + | ||
- | To start minimization, | + | |
- | + | ||
- | ==== Fit Procedure Stop Criteria ==== | + | |
- | After each iteration except the first MagicPlot evaluates //deviation decrement D//: | + | |
- | + | ||
- | <m>D = delim{|} {{chi^2}_{curr. iter.} / {chi^2}_{prev. iter.} – 1} {|}</ | + | |
- | + | ||
- | Deviation decrement shows how the residual sum of squares (< | + | |
- | + | ||
- | The iterative fit procedure stops on 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 | + | ===== Viewing |
+ | Residual means here the difference between initial data, baseline function | ||
+ | * Press and hold the '' | ||
+ | * You can either set '' | ||
- | ===== Fit Progress Window | + | ===== Fitting |
+ | To execute the fit click the '' | ||
MagicPlot indicates fit process with a special window. Fitting curves are periodically updated on plot while fitting so you can see how fit converges. | MagicPlot indicates fit process with a special window. Fitting curves are periodically updated on plot while fitting so you can see how fit converges. | ||
- | {{: | + | {{: |
MagicPlot shows current iteration number and deviation decrement with two progress bars while fit is performed. The fit process stops when one of these progress bars reaches the end. | MagicPlot shows current iteration number and deviation decrement with two progress bars while fit is performed. The fit process stops when one of these progress bars reaches the end. | ||
Line 126: | Line 123: | ||
* '' | * '' | ||
- | ===== Weighting of y data ===== | + | ===== Fitting One Curve ===== |
- | MagicPlot | + | You can use MagicPlot |
- | * If standard //y// errors are **not** specified: all // | + | |
- | * If standard //y// errors // | + | |
- | + | ||
- | < | + | |
- | + | ||
- | here //C// is normalizing coefficient (to make the sum of // | + | |
- | + | ||
- | < | + | |
- | + | ||
- | In '' | + | |
- | * 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. | + | |
- | + | ||
- | ===== Undoing | + | |
- | You can undo fit and undo changing initial parameters as usual using Undo function. It is a handy feature when experimenting with different models and initial parameters (e.g. peaks positions). | + | |
+ | Because of using individual data interval this method is useful for baseline fitting. In order to fit baseline specify the intervals which does not contain signal (peaks) and contain only noise. | ||
+ | {{: | ||
- | ===== Formulas | + | ===== Why My Fit is Not Converged? |
- | In the table below you can find the formulas which MagicPlot uses to calculate | + | In some cases the fit procedure may fail to find the optimal parameters values. The actual mathematical reason for this error is impossibility to invert the matrix α calculated from partial derivatives of fit function with respect |
- | Because | + | === The origin |
+ | * Fit is not converged through one or more parameters: | ||
+ | * Mutual dependency exists between some parameters. The algorithm cannot resolve which parameter to vary. | ||
+ | * Fit function is ill-conditioned: | ||
+ | * Numeric overflow | ||
- | ^ Parameter Name ^ Symbol | + | === Try one of the following: |
- | ^ Original Data and Fit Model Properties | + | |
- | | Number | + | |
- | | 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 // | + | |
- | | Residual Standard Deviation | + | |
- | | [[wp> | + | |
- | | Adjusted // | + | |
- | | Covariance Matrix of Parameters // | + | |
- | | Standard Deviation of Parameters // | + | |
- | | Correlation Matrix of Parameters // | + | |
===== See Also ===== | ===== See Also ===== | ||
+ | * [[fit_formulas]] | ||
* [[custom_fit_equation]] | * [[custom_fit_equation]] | ||
* [[spline]] | * [[spline]] | ||
Line 177: | Line 151: | ||
* [[guess_peaks]] | * [[guess_peaks]] | ||
* [[fit_equations]] | * [[fit_equations]] | ||
- | * [[transform_xy]] | ||
* [[interval_statistics]] | * [[interval_statistics]] | ||
+ | * [[table_from_curves]] |