フィルターのクリア

Looping a regression for 30 different observations 10 times

2 ビュー (過去 30 日間)
Wietze Zijpp
Wietze Zijpp 2022 年 4 月 3 日
回答済み: Star Strider 2022 年 4 月 3 日
Suppose I have a total of 300 observations.
Now I would like to perform a regression over the observation 1:30 31:60 etc.
And I am intersted in the error of the regression
X = [ones(size(x)) x1 x2 x3];
[b,bint,r,rint,stats] = regress(y,X)
How do I write a for loop such that I get 300/30 = 10 values of the error of the regression?

採用された回答

Star Strider
Star Strider 2022 年 4 月 3 日
One approach —
xa = randn(300,3);
ya = randn(300,1);
forstep = 30;
for k = 1:forstep:size(xa,1)-forstep
idxrng = k:k+30;
kidx = floor(k/forstep+1);
x1 = xa(idxrng,1);
x2 = xa(idxrng,2);
x3 = xa(idxrng,3);
y = ya(idxrng);
X = [ones(size(x1)) x1 x2 x3];
[b{kidx},bint{kidx},r{kidx},rint{kidx},stats{kidx}] = regress(y,X);
end
b
b = 1×9 cell array
{4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double} {4×1 double}
bint
bint = 1×9 cell array
{4×2 double} {4×2 double} {4×2 double} {4×2 double} {4×2 double} {4×2 double} {4×2 double} {4×2 double} {4×2 double}
r
r = 1×9 cell array
{31×1 double} {31×1 double} {31×1 double} {31×1 double} {31×1 double} {31×1 double} {31×1 double} {31×1 double} {31×1 double}
... and so for the rest.
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by