olshet.m (1407B)
1 % OLSHET.m -- Least Squares procedure, with Weighted LS Het correction 2 % [u,N,K,stdest,beta,vcv,robvcv] = olshet(y,x,z,title,depv,indv,zv); 3 % 4 % z == the variables to be used in constructing sigma_i: e.g. X or X^2 5 % 6 % Runs three regressions: 8/16/96 7 % ols ==> e 8 % e^2 on z, with truncation at the 25 percentile for fitted values 9 % wls 10 11 12 function [u,N,K,stdest,beta,vcv,robvcv] = olshet(y,x,z,title,depv,indv,zv); 13 14 e=ols(y,x,['OLS: ' title],depv,indv); 15 e2 = e.^2; 16 17 u=ols(e2,z,'Estimating variances','e2',zv); 18 N=length(u); 19 ybar = 1/N*(ones(N,1)'*e2); 20 rsq = 1-(u'*u)/(e2'*e2 - N*ybar^2); 21 TR2=N*rsq; 22 P=size(z,2); 23 fprintf('TR^2: %6.2f P-Value: %5.3f\n',[TR2 1-chi2cdf(TR2,P)]);e2hat=e2-u; 24 e225=prctile(e2hat,25); % The 25th percentile 25 fprintf('The 25th percentile of the fitted e2: %8.5f\n',e225); 26 e2hat=replace(e2hat,e2hat<e225,e225); 27 28 shat=sqrt(e2hat); 29 30 ytil=y./shat; 31 xtil=div(x,shat); 32 [v,N,K,stdest,beta,vcv,robvcv] = ols(ytil,xtil,['WLS: ' title],depv,indv); 33 34 u = y-x*beta; 35 dof = N-K; 36 sigma2=u'*u/dof; 37 stdest=sqrt(sigma2); 38 ybar = 1/N*(ones(N,1)'*y); 39 rsq = 1-(u'*u)/(y'*y - N*ybar^2); 40 rbar = 1-sigma2/((y'*y - N*ybar^2)/(N-1)); 41 42 fprintf('R-Squared: %4.2f SSR: %8.4f\n',[rsq u'*u]); 43 fprintf('RBar^2: %4.2f S.E.E.: %8.4f\n',[rbar stdest]); 44 disp '============================================================================='; 45