clc clear all close all %{ vlastnosti odhadu OLS pro jednorovnicovy model s nesplnenymi predpoklady y1 = a1 + a2*x1 + a3*x2 + e -konzistence -nestrannost -asymptoticka nestrannost %} a1 = 10.0; a2 = 5.0; a3 = 15.0; disp('KONZISTENCE'); maxnobs = 1000; OLS = zeros(3,maxnobs-10); disp('probihaji regrese pro konzistenci!'); tic; for i=10:maxnobs x1 = (randn(i,1)*10+6); x2 = randn(i,1)*4+3; iota = ones(i,1); y1 = zeros(i,1); evec = randn(i,1);%.*x1; %evec = 1+x1+x2+randn(i,1); %for k=2:length(evec) %autokorelace % evec(k)=0.8*evec(k-1)+randn; %end for j = 1:i y1(j,1) = iota(j,1)*a1 + x1(j,1)*a2 + x2(j,1)*a3 +evec(j,1); end; result = ols(y1,[iota x1 x2]); OLS(:,i-9) = result.beta; end; fprintf('\n Celkovy cas vypoctu pro konzistenci %6.2f sekund \n \n',toc); figure subplot(1,3,1) plot(OLS(1,:)); title('a1'); subplot(1,3,2) plot(OLS(2,:)); title('a2'); subplot(1,3,3) plot(OLS(3,:)); title('a3'); disp('NESTRANNOST'); nobs = 100; niter = 1000; disp('probihaji regrese pro nestrannost!'); tic; OLS = zeros(3,niter); evec = zeros(nobs,1); x1 = randn(nobs,1)*10+6; x2 = randn(nobs,1)*4+3; iota = ones(nobs,1); for iter = 1:niter; y1 = zeros(nobs,1); evec = randn(nobs,1);%.*x1; %evec =1+x1+x2+randn(nobs,1); %for k=2:length(evec) %autokorelace % evec(k)=0.8*evec(k-1)+randn; %end for j = 1:nobs y1(j,1) = iota(j,1)*a1 + x1(j,1)*a2 + x2(j,1)*a3 +evec(j,1); end; result = ols(y1,[iota x1 x2]); OLS(:,iter) = result.beta; end; OLSm = mean(OLS,2); fprintf('\n Celkovy cas vypoctu pro nestrannost %6.2f sekund \n \n',toc); fprintf(['\n Delka vzorku je ',num2str(nobs),'\n']); fprintf(['OLS vysledky prvni rovnice pres ', num2str(niter),' iteraci \n']); in.rnames = strvcat('Koeficient','a1','a2','a3'); in.cnames = strvcat('mean'); mprint([OLSm],in); %{ disp('ASYMPTOTICKA NESTRANNOST') niter = 50; maxnobs = 200; OLS = zeros(3,niter); OLSm = zeros(3,maxnobs-10); disp('probihaji regrese pro asymptotickou nestrannost!'); tic; for i=10:maxnobs x1 = randn(i,1); x2 = randn(i,1); iota = ones(i,1); for iter = 1:niter; y1 = zeros(i,1); evec = randn(i,1); for j = 1:i y1(j,1) = iota(j,1)*a1 + x1(j,1)*a2 + x2(j,1)*a3 +evec(j,1); end; result = ols(y1,[iota x1 x2]); OLS(:,iter) = result.beta; end; OLSm(:,i-9) = mean(OLS,2); end; fprintf('\n Celkovy cas vypoctu pro asymptotickou nestrannost %6.2f sekund \n \n',toc); figure subplot(1,3,1) plot(OLSm(1,:)); title('mean a1'); subplot(1,3,2) plot(OLSm(2,:)); title('mean a2'); subplot(1,3,3) plot(OLSm(3,:)); title('mean a3'); %}