You are here: Symbol Reference > Dew.Stats Namespace > Regress Class > Regress Methods > NLinRegress Method > NLinRegress Method (TVec, TVec, TRegressFun, TDeriveProc, TVec, TOptMethod, TOptStopReason, TVec, TVec, boolean, Integer, TSample, TSample, TStrings)
Dew Stats for .NET
Contents
C# Example

The following example uses data from NIST study involving circular interference transmittance. The response variable is transmittance, and the predictor variable is wavelength. First we setup the regression function Eckerle4 with three regression parameters (b0,b1,b2). Then we setup data and specify initial estimate for regression parameters (see below):

using Dew.Math;
using Dew.Math.Tee;
using Dew.Stats.Units;
using Dew.Stats;
namespace Dew.Examples
{

  // function definition
  private double Eckerle4(TVec B, double x)
  {
    double sqrterm = (x-B[2])/B[1])*(x-B[2])/B[1]);
    return B[0]/B[1] * Exp(-0.5*(sqrterm));
  }

  private void Example()
  {
    Vector x = new Vector(0);
    Vector y = new Vector(0);
    Vector b = new Vector(0);
    Vector yhat = new Vector(0);
    TOptStopReason StopReason;

    x.SetIt(false,new double[] {400.0, 405.0, 410.0, 415.0,
                 420.0, 425.0, 430.0, 435.0,
                 436.5, 438.0, 439.5, 441.0,
                 442.5, 444.0, 445.5, 447.0,
                 448.5, 450.0, 451.5, 453.0,
                 454.5, 456.0, 457.5, 459.0,
                 460.5, 462.0, 463.5, 465.0,
                 470.0, 475.0, 480.0, 485.0,
                 490.0, 495.0, 500.0});
    y.SetIt(false,new double[] {0.0001575, 0.0001699, 0.0002350, 0.0003102,
                 0.0004917, 0.0008710, 0.0017418, 0.0046400,
                 0.0065895, 0.0097302, 0.0149002, 0.0237310,
                 0.0401683, 0.0712559, 0.1264458, 0.2073413,
                 0.2902366, 0.3445623, 0.3698049, 0.3668534,
                 0.3106727, 0.2078154, 0.1164354, 0.0616764,
                 0.0337200, 0.0194023, 0.0117831, 0.0074357,
                 0.0022732, 0.0008800, 0.0004579, 0.0002345,
                 0.0001586, 0.0001143, 0.0000710});
    b.SetIt(false,new douible[] {1.0, 10.0, 500.0}); // initial estimates
    Regress.NLinRegress(x,y,Eckerle4,null,b,optMarquardt, out StopReason,
              null,yhat,false,300,1e-8,1e-10);
    TeeChart.DrawValues(x,y,Series1,false); // draw data
    TeeChart.DrawValues(x,yhat,Series2,false); // draw fitted value
  }
}
Copyright (c) 1999-2010 by Dew Research. All rights reserved.