You are here: Symbol Reference > Regress Namespace > Functions > Regress.PCRegress Function
Stats Master VCL
ContentsIndex
Example
Uses MtxExpr, Regress, StatTools, Math387;
procedure Example;
var y,b,ycalc,error: Vector;
  A,ATA: Matrix;
  mse: double;
begin
  // Load data
  A.SetIt(18,3,false,[1,  2,  1,
  2,  4,  2,
  3,  6,  4,
  4,  7,  3,
  5, 7,   2,
  6,  7,  1,
  7,  8,  1,
  8,  10, 2,
  9,  12, 4,
  10, 13, 3,
  11, 13, 2,
  12, 13, 1,
  13, 14, 1,
  14, 16, 2,
  15, 18, 4,
  16, 19, 3,
  17, 19, 2,
  18, 19, 1]);
  Y.SetIt([3,9,11,15,13,13,17,21,25,27,25,27,29,33,35,37,37,39]);
  // Perform Principal Component Regression
  PCRegress(y,A,b,ycalc,nil,1);
  // Errors
  error.Sub(ycalc,y);
end;
#include "MtxExpr.hpp"
#include "Regress.hpp"
#include "StatTools.hpp"
#include "Math387.hpp"
void __fastcall Example()
{
    sMatrix A, ATA;
    sVector y,b,ycalc,error;
    double mse;
    // Load data
    const int aLen = 54;
    double aData[aLen] = {1,  2,  1,
                2,    4,  2,
                3,    6,  4,
                4,    7,  3,
                5, 7, 2,
                6,    7,  1,
                7,    8,  1,
                8,    10, 2,
                9,    12, 4,
                10,   13, 3,
                11,   13, 2,
                12,   13, 1,
                13,   14, 1,
                14,   16, 2,
                15,   18, 4,
                16,   19, 3,
                17,   19, 2,
                18,   19, 1};

    A.SetIt(18,3,false,aData, aLen-1);

    y.SetIt(false,OPENARRAY(double,(3,9,11,15,13,13,17,21,25,27,25,27,29,33,35,37,37,39)));
    // Perform Principal Component Regression
    PCRegress(y,A,b,ycalc,NULL,1);
    // Errors
    error->Sub(ycalc,y);
}
Copyright (c) 1999-2025 by Dew Research. All rights reserved.