[Quantproject-developers] QuantProject/b1_ADT/Econometrics LinearRegression.cs, 1.1, 1.2
Brought to you by:
glauco_1
|
From: Glauco S. <gla...@us...> - 2011-01-06 18:31:26
|
Update of /cvsroot/quantproject/QuantProject/b1_ADT/Econometrics In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv12057/b1_ADT/Econometrics Modified Files: LinearRegression.cs Log Message: Computes a Linear Regression with covariance matrix and ANOVA (ANalysis Of VAriance) Index: LinearRegression.cs =================================================================== RCS file: /cvsroot/quantproject/QuantProject/b1_ADT/Econometrics/LinearRegression.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LinearRegression.cs 27 Mar 2010 17:06:57 -0000 1.1 --- LinearRegression.cs 6 Jan 2011 18:31:18 -0000 1.2 *************** *** 3,7 **** LinearRegression.cs ! Copyright (C) 2010 Glauco Siliprandi --- 3,7 ---- LinearRegression.cs ! Copyright (C) 2011 Glauco Siliprandi *************** *** 28,36 **** { /// <summary> ! /// Computes a Linear Regression /// </summary> [Serializable] public class LinearRegression : ILinearRegression { private double sumOfSquareResiduals; private double centeredTotalSumOfSquares; --- 28,38 ---- { /// <summary> ! /// Computes a Linear Regression with covariance matrix ! /// and ANOVA (ANalysis Of VAriance) /// </summary> [Serializable] public class LinearRegression : ILinearRegression { + private double[,] covarianceMatrix; // (XTransposeX)^-1 private double sumOfSquareResiduals; private double centeredTotalSumOfSquares; *************** *** 81,97 **** return xTransposeX; } ! private double[] getXtransposeY( double[] y , double[,] X ) ! { ! int n = y.Length; ! int k = X.GetLength( 1 ); ! double[] xTransposeY = new double[ k ]; ! for( int j = 0 ; j < k ; j++ ) ! { ! xTransposeY[ j ] = 0; ! for( int t = 0 ; t < n ; t++ ) ! xTransposeY[ j ] += X[ t , j ] * y[ t ]; ! } ! return xTransposeY; ! } #region computeRSquare --- 83,99 ---- return xTransposeX; } ! // private double[] getXtransposeY( double[] y , double[,] X ) ! // { ! // int n = y.Length; ! // int k = X.GetLength( 1 ); ! // double[] xTransposeY = new double[ k ]; ! // for( int j = 0 ; j < k ; j++ ) ! // { ! // xTransposeY[ j ] = 0; ! // for( int t = 0 ; t < n ; t++ ) ! // xTransposeY[ j ] += X[ t , j ] * y[ t ]; ! // } ! // return xTransposeY; ! // } #region computeRSquare *************** *** 158,164 **** this.runRegression_checkParameters( regressand , regressors ); double[,] xTransposeX = this.getXtransposeX( regressors ); ! double[] xTransposeY = this.getXtransposeY( regressand , regressors ); ! this.estimatedCoefficients = LinearSystemSolver.FindSolution( ! xTransposeX , xTransposeY ); this.computeCenteredRSquare( regressand , regressors ); } --- 160,168 ---- this.runRegression_checkParameters( regressand , regressors ); double[,] xTransposeX = this.getXtransposeX( regressors ); ! this.covarianceMatrix = PositiveDefiniteMatrix.GetInverse( xTransposeX ); ! double[,] xTransposeXInverseXTranspose = ! Matrix.TransposeTheSecondMatrixAndMultiply( this.covarianceMatrix , regressors ); ! // double[] xTransposeY = this.getXtransposeY( regressand , regressors ); ! this.estimatedCoefficients = Matrix.Multiply( xTransposeXInverseXTranspose , regressand ); this.computeCenteredRSquare( regressand , regressors ); } |