YOUSEFUL / DELPHI / COMPONENTS

TAtlasPolynomial

A fitted least-squares polynomial: evaluate it anywhere and read its R squared.

Record Unit Atlas.PlotStats · Product Atlas Plot Pro

Description

Returned by TAtlasStats.PolynomialFit. The coefficients are private: they are stored for the argument scaled to -1..1 over the fitted range, which is what keeps large arguments well conditioned, so they are not the coefficients of the polynomial in X. Use Evaluate instead. A Default(TAtlasPolynomial) has not been fitted: Degree is -1 and Evaluate raises.

Members

MemberKindWhat it does
RSquaredfieldCoefficient of determination of the fit on its own data, clamped to 0..1; 1 for constant data, which is fitted exactly.
DegreemethodThe degree that was fitted (1 to 6); -1 for an unfitted record.
EvaluatemethodThe polynomial's value at X, inside or outside the fitted range.

Methods

Degree method

function Degree: Integer;

The degree that was fitted (1 to 6); -1 for an unfitted record.

Evaluate method

function Evaluate(const X: Double): Double;

The polynomial's value at X, inside or outside the fitted range. Raises EAtlasPlotError for an unfitted record or a non-finite X.

pascal
Value := Fit.Evaluate(10);

Fields

RSquared field

RSquared: Double;

Coefficient of determination of the fit on its own data, clamped to 0..1; 1 for constant data, which is fitted exactly.

Examples

Tabulate a fitted curve

Fits a cubic and samples it at eleven points.

pascal
uses
  System.SysUtils, System.Classes, System.Math, Atlas.PlotStats;

procedure Tabulate(const X, Y: TArray<Double>; Target: TStrings);
var Fit: TAtlasPolynomial; I: Integer; At: Double;
begin
  Fit := TAtlasStats.PolynomialFit(X, Y, 3);
  Target.Add(Format('degree %d, R squared %.4f', [Fit.Degree, Fit.RSquared]));
  for I := 0 to 10 do
  begin
    At := MinValue(X) + (MaxValue(X) - MinValue(X)) * I / 10;
    Target.Add(Format('%.3f -> %.3f', [At, Fit.Evaluate(At)]));
  end;
end;

TAtlasStats · TAtlasPlotAnalysis

Also in Atlas Plot Pro

TAtlasBoxPlot · TAtlasHeatMap · TAtlasPolarPlot