MATLAB Answers

Several regress() without looping.

4 views (last 30 days)
Rodolphe on 23 Mar 2016
Edited: John D'Errico on 23 Mar 2016
Basically, im doing regress(X,Y) on several different X, while Y remain unchanged. So far, im looping on each X but I have thousands so it's taking forever. Any ideas on how to avoid the loop? Thanks!

Answers (1)

John D'Errico
John D'Errico on 23 Mar 2016
Edited: John D'Errico on 23 Mar 2016
While it is possible to do so for a fixed X, with changing Y where you would see a speed gain, the opposite is not possible.
Yes, there are some tricks where you can create sparse block diagonal matrices, but you would not gain too much over a simple loop, and you would no longer have access to the many pieces of information that regress returns beyond the basic regression coefficients. That you could get as easily from a loop around use of the backslash operator applied to your sequence of problems.
The point is, much of the time required for regress lies in the computation of those extra stars, R^2, p values for the parameters, etc. Skip them, and all you need to do is use backslash. It will be faster, but then you don't get that information.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by