% RANK_TEST.M            05-31-2011          code by: Filippo Ferroni
% This function performs the rank test for identification derived in
% Proposition 2-S (SINGULAR CASE) of Komunjer and Ng (2011). The ranks are computed for a
% range of tolerance levels.

function table0 = rank_test_comb(Delta_0,n_theta,n_x,n_eps,n_y,tol0)

Delta_L    = Delta_0(:,1:n_theta);
Delta_T    = Delta_0(:,n_theta+1:n_theta+n_x^2);
Delta_U    = Delta_0(:,n_theta+n_x^2+1:end);
table0     = [];
tol        = tol0;
n_required = n_theta+n_x^2+n_eps^2;
n_actual   = rank(Delta_0,tol);
pass_order = (n_theta <= (n_y*n_x + n_eps*(n_x+n_y-n_eps) + n_eps*(n_eps+1)/2));
pass_rank  = (n_actual == n_required);
table0     = [table0; tol rank(Delta_L,tol)  rank(Delta_T,tol)  rank(Delta_U,tol)  ...
	          rank([Delta_L Delta_T],tol)  rank([Delta_L Delta_U],tol)  ...
	          rank(Delta_0,tol) pass_rank];




