Several regression with loop and storing the output data

조회 수: 1 (최근 30일)
MandG
MandG 2017년 12월 18일
답변: Ben Drebing 2017년 12월 20일
Hi,
I have a matrix of dependent variables DATI 570x2604 (each column represents a time series), and a second matrix of regressors REG 570x10416. I want to regress the first column of DATI on the first 4 columns (1 to 4) of REG, then the second column of DATI on the second 4 columns (5 to 8) of REG. Is there a chance to run the 2604 regressions with a loop and to store the estimated coefficients t stat p value and r2 in a matrix?
I’m very new to matlab and any help would be an asset.
Thanks

답변 (1개)

Ben Drebing
Ben Drebing 2017년 12월 20일
Try this code out:
for i = 1:2604
% Get the ith column of DATI
Y = DATI(:,i);
% Get the 4i+1 th to the 4i+4 th columns of REG
X = [ones(570,1), REG(:,(4*i+1):(4*i+4))];
[b, bint,r,rint,stats] = regress(Y,X);
end
This will do the regressions that you were talking about. The outputs of the "regress" function, specifically the "stats" variable, will have the statistics that you wanted to save. You can read about which outputs are which here.

카테고리

Help CenterFile Exchange에서 Linear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by