replicate Robust Standard Errors with formula

4 次查看(过去 30 天)
Hello, I am trying to manually calculate robust SEs for a heteroskadistic data set.
All of the formulas I have attempted generate either a 500X1 or 500X500 matrix.
How can I compare my results with the 2X1 matrix generated by WhiteSE command?
Please see below my code. All suggestions are welcomed.
Thanks in advance,
Robert
clear
n=500;
X=[1:500];
y=2*X+normrnd(0,sqrt(X.^1.8));
mdl=fitlm(X,y,'linear'); %add regression line
b=X\y; % OLS estimate
e=y-X*b; % OLS residuals
SSRb=e'*e; % SSR function at OLS estimate
%plot(X,y,'o')
plot(mdl)
plotResiduals(mdl,'fitted')
%%Unadjusted statistics
h_cov = mdl.CoefficientCovariance;
h_SE = mdl.SSE;
h_coeff = mdl.Coefficients;
%%Robust Standard Errors
[WhiteCov,WhiteSe,Whitecoeff] = hc(mdl); % White's estimates
%HCE= 1/n*(SSRb/e).*(SSRb/e.*(e.^2)).*(SSRb/e);
%HCE= 1/n*(sum((SSRb/e)).*(sum((SSRb/e.*(e.^2))).*(sum(SSRb/e));
%HCE= 1/n*(sum((SSRb/e)).*(sum((SSRb/e.*(e.^2))).*(sum(SSRb/e))));
%HCE = (SSRb/e).*SSRb'.*(diag(SSRb)).*(SSRb/e);
%HCE = (SSRb/e).*SSRb'.*(diag(e.^2)).*(SSRb/e);
HCE = (SSRb/-1).*(SSRb'.*(diag(e.^2))).*(SSRb/-1);

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by