﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
565	Error in RSS calculus in LinReg  function	Christian Paz	Víctor de Buen Remiro	"When we run the following code, it is expected that the RSS value given by the Estimate and the LinReg function take the same value. Instead, LinReg returns 11.4009263094 and Estimate returns (the correct value) 0.2280185256.

This error may lead to incorrect decisions based on RSS measure. We think that it is calculated as the square of sigma, it is (n-p) * sigma (n: number of data, p: number of parameters).


//////////////////////////////////////////////////////////////////////////////
// Simulated data y = alfa+beta X+e
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// Using LinReg RSS (residual square sum ) is grown!
//////////////////////////////////////////////////////////////////////////////

Real n=50;  //lenght of the simulated sample
Real alfa=1;
Real beta=2;
Real Sigma=0.5;
Matrix X1 = SetCol(NCopy(n, 1));
Matrix X2 = Rand(n,1,0,1);
Matrix X =X1|X2; //explanatory Matrix
Matrix Y  = RProd(X1, alfa)+RProd(X2, beta)
	    + Gaussian(n, 1, 0, Sigma); //response Matrix

Set  Resp=LinReg(Y,X);
//////////////////////////////////////////////////////////////////////////////
// Using Estimate is fine!
//////////////////////////////////////////////////////////////////////////////

Serie Yr = SetSer(MatSet(Y),y2005m02,Mensual);
Serie Const = CalInd(C,Mensual);
Serie Xr = SetSer(MatSet(X2),y2005m02,Mensual);

Set Input_1 = SetOfSet(
InputDef(0.1, Const),
InputDef(0.1, Xr)
);

Set SetAR     = SetOfReal(1,1); //Parte AR de ModelDef
Set SetMA     = SetOfReal(1,1); //Parte MA de ModelDef
Polyn Diferen = 1;


Set Model1 = ModelDef(
  Yr,        	//Serie Output,
  1,            //Real  FstTransfor,
  0,            //Real  SndTransfor,
  12,           //Real  Period,
  0,            //Real  Constant,
  Diferen, 	//Polyn Dif,
  SetAR,   	//Set   AR,
  SetMA,   	//Set   MA,
  Input_1,  	//Set   Input,
  Copy(Empty)   //Set   NonLinInput
);

Set Resp2       = Estimate(Model1);"	defect	closed	highest		Math	1.1.6	blocker	fixed		
