フィルターのクリア

loop for OLS using fitlm

2 ビュー (過去 30 日間)
Alexis Villacis
Alexis Villacis 2018 年 12 月 18 日
回答済み: Felipe Valenzuela Soto 2019 年 4 月 11 日
I am trying to estimate standar errors of my betas using bootstraping. I am using fitlm.
My Y and x are two vectors of dimensions 202x1. How can I program the loop to save the betas in a matrix? I should have 2 betas for each of the 1000 models.
My code is as follows:
%Get Initial values
OLS=fitlm(x,Y)
%save residuals
res=OLS.Residuals.Raw;
%generate y hat
ypred=predict(OLS1,x)
%bootstrap 1000 draws of the residuals with replacement
resboot=res(randi(202,202,1000))
%generate 1000 new draws of Y
yboot=ypred+resboot
% Do the fits
for i = 1:1000
mdl= fitlm(x,yboot(:,i));
end

回答 (1 件)

Felipe Valenzuela Soto
Felipe Valenzuela Soto 2019 年 4 月 11 日
Hi Alexis,
Maybe you already solve it, but i think you should first create two zeros vector of 202x1 to asign the estimated betas and residuals from the loop using the fitlm function. I have used this method in my codes for yield curve term structure estimation, more related to financial application. I hope it works for you.
beta = zeros(size(X,1),1);
residuals = zeros(size(X,1),numel(X));
%loop
for i = 1:size(X,1)
EstOLS = fitlm(X, Y','Intercept", false); %Or true in you want
beta (i ; :) = EstOLS.Coefficients.Estimate';
residuals(i ; :) = EstOLS.Residuals.Raw';
end
Good luck!
Felipe Valenzuela.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by