0

In MATLAB the OLS solution to the $y = X \beta + \epsilon$ can be calculated by

(X'*X) \ (X'*y)

but it seems

X \ y is also a least squares solution.

What is the difference between the two? If any? Basically is there a point to use the first option as it is likely to be slower?

  • Please consult the duplicate. In general, provided that `X` is full rank, they will both provide the same solution. There will be differences for underdetermined systems. It is highly recommended you simply use `X \ y` as the `mrdivide` operator will internally determine the most stable way to compute the solution to the system. – rayryeng Apr 25 '17 at 18:45
  • I disagree. Look at Tomas's answer. It exactly answers what you're looking for. If there are more people that disagree, then I'll consider reopening it but I'll leave it as is. – rayryeng Apr 25 '17 at 18:49
  • @rayryeng OK. Your comment is an answer. The other question doesn't explain why there is no point to use the first option. – Cowboy Trader Apr 25 '17 at 18:50
  • Please consult Tomas's answer in the duplicate and look at the comments stream. It will show you what you're looking for. http://stackoverflow.com/a/30334802/3250829 – rayryeng Apr 25 '17 at 18:50
  • @rayryeng For full rank is there a difference in terms of performance between two options? – Cowboy Trader Apr 25 '17 at 18:55
  • Ah, well in that case no. The post-multiplication with `X'` is done internally within the ` \ ` operator. You would basically be cutting the middle man away if you did that yourself prior to using ` \ ` . I'd like to direct you to this useful question and answer that give a flowchart on what ` \ ` is doing internally... that is... deciding which method to use for solving the system: http://stackoverflow.com/questions/18553210/how-to-implement-matlabs-mldivide-a-k-a-the-backslash-operator – rayryeng Apr 25 '17 at 18:58

0 Answers0