Dew Stats Master .NET
PowerFit Routine
Summary
Fits simple exponential equation to data.

Unit
RegModels

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

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

Categories
Linearizable regression models
 See Also 
PowerDeriv 
PowerEval 

Example 1

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.Values,X,YHat); DrawValues(X,Y,Series1); // draw original data DrawValues(X,YHat,Series2); // draw fitted data end;
#include "Math387.hpp" #include "RegModels.hpp" #include "MathExpr.hpp" #include "MtxVecTee.hpp" void __fastcall Example(TLineSeries* Series1, TLineSeries* Series2); { Vector X,Y; Vector 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->Values,X, YHat); DrawValues(X,Y,Series1,false); // draw original data DrawValues(X,YHat,Series2,false); // draw fitted data }
using Dew.Math; using Dew.Stats.Units; namespace Dew.Examples { private void Example(Steema.TeeChart.Styles.Point series1, Steema.TeeChart.Styles.Point series 2) { Vector X = new Vector(100,false); Vector Y = new Vector(0); Vector YHat = new Vector(0); X.Ramp(-5.0, 0.1); // x= -5.0, -4.9, ..., +4.9 Y.Size(X); Y.RandGauss(3.5,0.1"); // sample data RegModels.PowerFit(B,X,Y,null); // calculate coefficients // evaluate y RegModels.PowerEval(B.Values, X, YHat); MtxVecTee.DrawValues(X,Y,series1,false); // original data MtxVecTee.DrawValueS(X,YHat,series2,false); // fitted data } }


Copyright 2008 Dew Research
http://www.dewresearch.com