How can I plot wald test statistics to show that they converge to the chi-squared distribution?
2 views (last 30 days)
Show older comments
I am using the following code --
clear
rng(12345)
%Setting up the model
n = 200;
%The model has 4 variables X1, X2, X3, X4
X1=rand(n,1); X2=rand(n,1); X3=rand(n,1); X4=rand(n,1);
X=[X1,X2,X3,X4];
beta1=-0.6; beta2=-0.5; beta3=0.1; beta4=0.05;
beta = [beta1,beta2,beta3,beta4];
A=100;
R = [0 0 1 0];
q = [0.1]; %restriction function contains hypothesis
for r=1:A
sigma = 1; epsilon = randn(n,1)*sigma;
y = beta1*X1+beta2*X2+beta3*X3+beta4*X4+epsilon; %model
b_est = X\y;
e = y - X*b_est;
sigma_est = (e'*e)/n; V=sigma_est*inv(X'*X);
M=[b_est(3,1)-0.1];
W(r) = M'*inv(R*V*R')*M
end
X=0:50;
subplot(1,2,1), plot(X,chi2pdf(X,1)), xlim([3 50]), title('Chi-squared distribution')
subplot(1,2,2), plot(W), xlim([3 50]), ylim([0 5]), title('Wald statistics')
Am I doing any mistake in the code which is why maybe it is not converging to chi-squared distribution? Any help would be appreciated. Thank you.
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!