Curve fitting is the process of calculating values from visualization coordinates and input parameters, to draw reference curves and points.
Overview
Spotfire includes a number of predefined curve fitting calculations, such as Logistic Regression curve fit and a Polynomial curve fit. The CustomFittingModel
extension point enables the creating of custom curve fit algorithms.
Curves can be added to scatter plots, bar charts, box plots and line charts. The markers in any of these visualizations can be categorized. To make curve fitting apply individually to a category, specify a combination of Color, Trellis, Shape or Line axes – the supported axes vary between visualizations. Letting the fitting model categorize over the colors results in one curve for each color.
The results of a curve fit from an external system can be imported into a table and used as pre-calculated result variables to render curves.
Tutorials and Examples
Fitting Models
Visualizations supporting curve fits are extended with a collection of fitting models. The base class for fitting models is called FittingModel
. A visualization may have multiple instances of fitting models running at the same time, and each fitting model may define a number of curves and points.
Curves and points are implemented by the document nodes ReferenceCurve
and ReferencePoint
. The FittingModels
node on a visualization have convenience methods to add the built-in curve fits to the visualization.
Adding a straight line fit to a scatter plot only requires one line of code:
scatterPlot.FittingModels.AddStraightLineFit();
Fitting to Data
The fitting model must declare the result variables it will return before fitting can be performed. By overriding the ConfigureModelCore
, names and descriptions for result values are registered using RegisterResultVariable
. All result variables have the assumed double
data type and must be assigned values of this type to avoid error. Expressions may also be set by SetCurveExpression
and SetPointExpressions
respectively.
The actual fitting operation is performed by the Fit
method. The first parameter, of FittingModelData
type, retrieves the data values. The GetRows
method returns a row cursor for iteration combined with two cursors over X and Y values for iterating over the data points used by the plot. The second parameter, of FittingModelOutput
type, provides the overloaded SetResult
method enabling the setting of registered variables.
When individual fitting is defined for an axis, the Fit
method will be called once for each category, since the fitting model instance is unaware of how the data has been categorized.