How can I compute multivariate regression residuals?
Show older comments
I am running a loop to obtain residuals from a number of regressions. I have got 1939 y values(dependent variables). I need a series of residuals for each. I use the following code.
for i=1:1939
stats= regstats(y(:,i),x,'linear', {'beta', 'r'});
end
However, I get only one column of residuals when I checked the stats. I doubt the residuals overwrite on only one column after each regression. Any ideas to solve this problem? Thanks.
Accepted Answer
More Answers (1)
dpb
on 8 Oct 2018
You really have 1939 different regressions or 1939 observations?
Whichever, you get only one (the last) result the way the code is written because you overwrite the stats structure every pass through the loop.
stats(i)=regstats(y(:,i),x,'linear', {'beta', 'r'});
1 Comment
dpb
on 8 Oct 2018
[BA Answer moved to Comment -- dpb]
Thank you for your answer. Your code works:
for i=1:1939
stats(i)= regstats(y(:,i),f,'linear', {'beta', 'r'}); a(:,i)=stats(i).r;
end
Yes, weird but I really have 1939 regressions and number of observations is 252.
Categories
Find more on Resampling Techniques in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!