You are here: Symbol Reference > RegModels Namespace > Functions > RegModels.PowerFit Function
Stats Master VCL
ContentsIndex
PreviousUpNext
RegModels.PowerFit Function

Fits simple exponential equation to data.

Pascal
procedure PowerFit(const B: TVec; const X: TVec; const Y: TVec; const Weights: TVec = nil);
Parameters 
Description 
Returns regression coefficients for power function. 
Vector of independent variable. 
Vector of dependent variable. 
Weights 
Weights (optional). Weights are used only if they are set. 

The routine fits equations to data by minimizing the sum of squared residuals. The observed values obey the following equation: 

 

 

In the following example we generate some data. Then we fit power function to this data and retreive it's regression coefficients.

Uses MathExpr, MtxVecTee, Series, RegModels;
procedure Example(Series1: TLineSeries);
var Y,YHat,B,X: Vector;
begin
  X.Size(100);
  Y.Size(X);
  X.Ramp(-5,0.05); // X = (-5, -4.95, ...-0.05)
  Y.RandGauss(3.5,0.12); // populate sample data
  PowerFit(B,X,Y); // calculate coefficients
  // evaluate y by using calculated coefficients
  PowerEval(B,X,YHat);
  DrawValues(X,Y,Series1); // draw original data
  DrawValues(X,YHat,Series2); // draw fitted data
end;
#include "Math387.hpp"
#include "RegModels.hpp"
#include "MtxExpr.hpp"
#include "MtxVecTee.hpp"
void __fastcall Example(TLineSeries* Series1, TLineSeries* Series2);
{
  sVector X,Y;
  sVector B, YHat;
  X.Size(100,false);
  Y.Size(X);
  X.Ramp(-5.0, 0.1); // x= -5.0, -4.9, ..., +4.9
  Y.RandGauss(3.5, 0.12); // sample data
  PowerFit(B,X,Y,NULL); // calculate coefficients
  // evaluate y by using calculated coefficients
  PowerEval(B,X, YHat);
  DrawValues(X,Y,Series1,false); // draw original data
  DrawValues(X,YHat,Series2,false); // draw fitted data
}
Examples on GitHub
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!