title: Eigen OLS vs python statsmodel.api.OLS
body: <p>I need to calculate the slope,intercept of the line for a regression between 2 vectors with data. So i made a prototype with python below code:</p>
  <pre><code>A = [1,2,5,7,14,17,19]
  b = [2,14,6,7,13,27,29]
  
  A = sm.add_constant(A)
  results = sm.OLS(A, b).fit()
  
  print(&quot;results: &quot;, results.params)
  </code></pre>
  <blockquote>
  <p>output: [0.04841897 0.64278656]</p>
  </blockquote>
  <p>Now I need to replicate this using <code>Eigen</code> lib in <code>C++</code> and as I understood, I need to pass a <code>1</code> column in the matrix of <code>A</code>. If I do so, I get totally different results for the regression than if I just use no second column or a <code>0</code> column. <code>C++</code> code below:</p>
  <pre><code>Eigen::VectorXd A(7);
  Eigen::VectorXd b(7);
  
  A &lt;&lt; 1,2,5,7,14,17,19;
  b &lt;&lt; 2,14,6,7,13,27,29;
  
  MatrixXd new_A(A.rows(), 2);
  VectorXd d = VectorXd::Constant(A.rows(), 1);
  new_A &lt;&lt; A, d;
  
  Eigen::MatrixXd res = new_A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b);
  
  cout &lt;&lt; &quot; slope: &quot; &lt;&lt; res.coeff(0, 0) &lt;&lt; &quot; intercept: &quot; &lt;&lt; res.coeff(1, 0) &lt;&lt; endl;
  cout &lt;&lt; &quot;dbl check: &quot; &lt;&lt; (new_A.transpose() * new_A).ldlt().solve(new_A.transpose() * b) &lt;&lt; endl;
  </code></pre>
  <blockquote>
  <p>output with '1' column added to new_A -&gt;  slope: 1.21644 intercept:
  2.70444 output with '0' or no column added -&gt; slope: 0.642787 intercept: 0</p>
  </blockquote>
  <p>How to get same results in <code>C++</code>? Which one is the right one, I seem to trust more the python one since I get the same when I use 0 column.</p>
  <p>thank you,</p>
  <p>Merlin</p>