Complete re-writing to make the function modular (the input being either J or H or Hess etc.).

time-shift
Marco Ratto 2011-05-02 11:12:39 +02:00
parent a512436295
commit c51066d76d
1 changed files with 64 additions and 132 deletions

View File

@ -1,35 +1,22 @@
function [McoH, McoJ, McoGP, PcoH, PcoJ, PcoGP, condH, condJ, condGP, eH, eJ, eGP, ind01, ind02, indnoH, indnoJ, ixnoH, ixnoJ] = identification_checks(H, JJ, gp) function [condJ, ind0, indnoJ, ixnoJ, McoJ, PcoJ, jweak, jweak_pair] = identification_checks(JJ, hess_flag)
% function [McoH, McoJ, McoGP, PcoH, PcoJ, PcoGP, condH, condJ, condGP, eH, % function [condJ, ind0, indnoJ, ixnoJ, McoJ, PcoJ, jweak, jweak_pair] = identification_checks(JJ, hess_flag)
% eJ, eGP, ind01, ind02, indnoH, indnoJ, ixnoH, ixnoJ] = identification_checks(H, JJ, gp)
% checks for identification % checks for identification
% %
% INPUTS % INPUTS
% o H [matrix] [(entries in st.sp. model solutio) x nparams] % o JJ [matrix] [output x nparams] IF hess_flag==0
% derivatives of model solution w.r.t. parameters and shocks % derivatives of output w.r.t. parameters and shocks
% o JJ [matrix] [moments x nparams] % o JJ [matrix] [nparams x nparams] IF hess_flag==1
% derivatives of moments w.r.t. parameters and shocks % information matrix
% o gp [matrix] [jacobian_entries x nparams]
% derivatives of jacobian (i.e. LRE model) w.r.t. parameters and shocks
% %
% OUTPUTS % OUTPUTS
% o McoH [array] multicollinearity coefficients in the model solution % o cond condition number of JJ
% o McoJ [array] multicollinearity coefficients in the moments % o ind0 [array] binary indicator for non-zero columns of H
% o McoGP [array] multicollinearity coefficients in the LRE model % o indnoJ [matrix] index of non-identified params
% o PcoH [matrix] pairwise correlations in the model solution % o ixnoJ number of rows in indnoJ
% o PcoJ [matrix] pairwise correlations in the moments % o Mco [array] multicollinearity coefficients
% o PcoGP [matrix] pairwise correlations in the LRE model % o Pco [matrix] pairwise correlations
% o condH condition number of H % o jweak [binary array] gives 1 if the parameter has Mco=1(with tolerance 1.e-10)
% o condJ condition number of JJ % o jweak_pair [binary matrix] gives 1 if a couple parameters has Pco=1(with tolerance 1.e-10)
% o condGP condition number of gp
% o eH eigevectors of H
% o eJ eigevectors of JJ
% o eGP eigevectors of gp
% o ind01 [array] binary indicator for non-zero columns of H
% o ind02 [array] binary indicator for non-zero columns of JJ
% o indnoH [matrix] index of non-identified params in H
% o indnoJ [matrix] index of non-identified params in JJ
% o ixnoH number of rows in ind01
% o ixnoJ number of rows in ind02
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% None % None
@ -54,145 +41,90 @@ function [McoH, McoJ, McoGP, PcoH, PcoJ, PcoGP, condH, condJ, condGP, eH, eJ, eG
% My suggestion is to have the following steps for identification check in % My suggestion is to have the following steps for identification check in
% dynare: % dynare:
% 1. check rank of H, JJ, gp at theta % 1. check rank of JJ at theta
npar = size(H,2); npar = size(JJ,2);
npar0 = size(gp,2); % shocks do not enter jacobian
indnoH = zeros(1,npar);
indnoJ = zeros(1,npar); indnoJ = zeros(1,npar);
indnoLRE = zeros(1,npar0);
% H matrix ind1 = find(vnorm(JJ)>=eps); % take non-zero columns
ind1 = find(vnorm(H)>=eps); % take non-zero columns JJ1 = JJ(:,ind1);
H1 = H(:,ind1);
[eu,e2,e1] = svd( H1, 0 );
eH = zeros(npar,npar);
% eH(ind1,:) = e1;
eH(ind1,length(find(vnorm(H)<eps))+1:end) = e1; % non-zero eigenvectors
eH(find(vnorm(H)<eps),1:length(find(vnorm(H)<eps)))=eye(length(find(vnorm(H)<eps)));
condH = cond(H1);
rankH = rank(H);
rankHH = rank(H'*H);
ind2 = find(vnorm(JJ)>=eps); % take non-zero columns
JJ1 = JJ(:,ind2);
[eu,ee2,ee1] = svd( JJ1, 0 ); [eu,ee2,ee1] = svd( JJ1, 0 );
eJ = zeros(npar,npar); condJ= cond(JJ1);
eJ(ind2,length(find(vnorm(JJ)<eps))+1:end) = ee1; % non-zero eigenvectors
eJ(find(vnorm(JJ)<eps),1:length(find(vnorm(JJ)<eps)))=eye(length(find(vnorm(JJ)<eps)));
condJ = cond(JJ1);
rankJJ = rank(JJ'*JJ);
rankJ = rank(JJ); rankJ = rank(JJ);
rankJJ = rankJ;
if hess_flag==0,
rankJJ = rank(JJ'*JJ);
end
ind3 = find(vnorm(gp)>=eps); % take non-zero columns ind0 = zeros(1,npar);
gp1 = gp(:,ind3); ind0(ind1) = 1;
covgp = gp1'*gp1;
sdgp = sqrt(diag(covgp));
sdgp = sdgp*sdgp';
[eu,ex2,ex1] = svd(gp1, 0 );
eGP = zeros(npar0,npar0);
eGP(ind3,length(find(vnorm(gp)<eps))+1:end) = ex1; % non-zero eigenvectors
eGP(find(vnorm(gp)<eps),1:length(find(vnorm(gp)<eps)))=eye(length(find(vnorm(gp)<eps)));
% condJ = cond(JJ1'*JJ1);
condGP = cond(gp1);
if hess_flag==0,
ind01 = zeros(npar,1); % find near linear dependence problems:
ind02 = zeros(npar,1); McoJ = NaN(npar,1);
ind01(ind1) = 1; for ii = 1:size(JJ1,2);
ind02(ind2) = 1; McoJ(ind1(ii),:) = cosn([JJ1(:,ii),JJ1(:,find([1:1:size(JJ1,2)]~=ii))]);
% find near linear dependence problems:
McoH = NaN(npar,1);
McoJ = NaN(npar,1);
McoGP = NaN(npar0,1);
for ii = 1:size(H1,2);
McoH(ind1(ii),:) = [cosn([H1(:,ii),H1(:,find([1:1:size(H1,2)]~=ii))])];
end
for ii = 1:size(JJ1,2);
McoJ(ind2(ii),:) = [cosn([JJ1(:,ii),JJ1(:,find([1:1:size(JJ1,2)]~=ii))])];
end
for ii = 1:size(gp1,2);
McoGP(ind3(ii),:) = [cosn([gp1(:,ii),gp1(:,find([1:1:size(gp1,2)]~=ii))])];
end
ixno = 0;
if rankH<npar || rankHH<npar || min(1-McoH)<1.e-10
% - find out which parameters are involved,
% using the vnorm and the svd of H computed before;
% disp('Some parameters are NOT identified in the model: H rank deficient')
% disp(' ')
if length(ind1)<npar,
% parameters with zero column in H
ixno = ixno + 1;
indnoH(ixno,:) = (~ismember([1:npar],ind1));
end end
e0 = [rankHH+1:length(ind1)]; else
for j=1:length(e0), deltaJ = sqrt(diag(JJ));
% linearely dependent parameters in H tildaJ = JJ./((deltaJ)*(deltaJ'));
ixno = ixno + 1; McoJ(:,1)=(1-1./diag(inv(tildaJ)));
indnoH(ixno,ind1) = (abs(e1(:,e0(j))) > 1.e-3 )'; rhoM=sqrt(1-McoJ);
end % PcoJ=inv(tildaJ);
else % rank(H)==length(theta), go to 2 PcoJ=inv(JJ);
% 2. check rank of J sd=sqrt(diag(PcoJ));
% disp('All parameters are identified at theta in the model (rank of H)') PcoJ = PcoJ./((sd)*(sd'));
% disp(' ')
end end
ixnoH=ixno;
ixno = 0;
ixnoJ = 0;
if rankJ<npar || rankJJ<npar || min(1-McoJ)<1.e-10 if rankJ<npar || rankJJ<npar || min(1-McoJ)<1.e-10
% - find out which parameters are involved % - find out which parameters are involved
% disp('Some parameters are NOT identified by the moments included in J') % disp('Some parameters are NOT identified by the moments included in J')
% disp(' ') % disp(' ')
if length(ind2)<npar, if length(ind1)<npar,
% parameters with zero column in JJ % parameters with zero column in JJ
ixno = ixno + 1; ixnoJ = ixnoJ + 1;
indnoJ(ixno,:) = (~ismember([1:npar],ind2)); indnoJ(ixnoJ,:) = (~ismember([1:npar],ind1));
end end
ee0 = [rankJJ+1:length(ind2)]; ee0 = [rankJJ+1:length(ind1)];
for j=1:length(ee0), for j=1:length(ee0),
% linearely dependent parameters in JJ % linearely dependent parameters in JJ
ixno = ixno + 1; ixnoJ = ixnoJ + 1;
indnoJ(ixno,ind2) = (abs(ee1(:,ee0(j))) > 1.e-3)'; indnoJ(ixnoJ,ind1) = (abs(ee1(:,ee0(j))) > 1.e-3)';
end end
else %rank(J)==length(theta) => else %rank(J)==length(theta) =>
% disp('All parameters are identified at theta by the moments included in J') % disp('All parameters are identified at theta by the moments included in J')
end end
ixnoJ=ixno;
% here there is no exact linear dependence, but there are several % here there is no exact linear dependence, but there are several
% near-dependencies, mostly due to strong pairwise colliniearities, which can % near-dependencies, mostly due to strong pairwise colliniearities, which can
% be checked using % be checked using
PcoH = NaN(npar,npar); jweak=zeros(1,npar);
jweak_pair=zeros(npar,npar);
if hess_flag==0,
PcoJ = NaN(npar,npar); PcoJ = NaN(npar,npar);
PcoGP = NaN(npar0,npar0);
for ii = 1:size(H1,2);
PcoH(ind1(ii),ind1(ii)) = 1;
for jj = ii+1:size(H1,2);
PcoH(ind1(ii),ind1(jj)) = [cosn([H1(:,ii),H1(:,jj)])];
PcoH(ind1(jj),ind1(ii)) = PcoH(ind1(ii),ind1(jj));
end
end
for ii = 1:size(JJ1,2); for ii = 1:size(JJ1,2);
PcoJ(ind2(ii),ind2(ii)) = 1; PcoJ(ind1(ii),ind1(ii)) = 1;
for jj = ii+1:size(JJ1,2); for jj = ii+1:size(JJ1,2);
PcoJ(ind2(ii),ind2(jj)) = [cosn([JJ1(:,ii),JJ1(:,jj)])]; PcoJ(ind1(ii),ind1(jj)) = cosn([JJ1(:,ii),JJ1(:,jj)]);
PcoJ(ind2(jj),ind2(ii)) = PcoJ(ind2(ii),ind2(jj)); PcoJ(ind1(jj),ind1(ii)) = PcoJ(ind1(ii),ind1(jj));
end end
end end
for ii = 1:size(gp1,2); for j=1:npar,
PcoGP(ind3(ii),ind3(ii)) = 1; if McoJ(j)>(1-1.e-10),
for jj = ii+1:size(gp1,2); jweak(j)=1;
PcoGP(ind3(ii),ind3(jj)) = [cosn([gp1(:,ii),gp1(:,jj)])]; [ipair, jpair] = find(PcoJ(j,j+1:end)>(1-1.e-10));
PcoGP(ind3(jj),ind3(ii)) = PcoGP(ind3(ii),ind3(jj)); for jx=1:length(jpair),
jweak_pair(j, jpair(jx)+j)=1;
jweak_pair(jpair(jx)+j, j)=1;
end
end end
end end
end
jweak_pair=dyn_vech(jweak_pair)';