Residuals Sum of Squares calculation of regression in C++ Eigen

I want to work out RSS of Matrix Formulation of Multiple Regression, and Y=Xb+e; Here is the code i program in C++, but error occurs. Any help will be very appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <Eigen/Dense>
#include <iostream>
#include <string>
using namespace std;
using namespace Eigen;

double getRSS(const MatrixXd& X, const MatrixXd& Y){
  return (Y.transpose()*Y-((X.transpose()*X).inverse()*X.transpose()*Y).transpose()*X.transpose()*Y).determinant();            
}

main(){
    MatrixXd Y(10,1);
    MatrixXd X1(10,2);
    MatrixXd X2(10,1);

    Y<<50,51,52,54,53,60,59,65,67,70;
    X1<<29,54
      ,39,61
      ,26,52
      ,48,70
      ,42,63
      ,64,79
      ,45,68
      ,30,65
      ,51,79
     ,44,76;
    X2<<29,39,26,48,42,64,45,30,51,44;
    double RSS=getRSS(X1,Y);
    std::cout << RSS << std::endl; 
    system("pause");
}
Topic archived. No new replies allowed.