diff --git a/GSA_distrib/4.0.3/GSA.zip b/GSA_distrib/4.0.3/GSA.zip deleted file mode 100644 index 77d88674d..000000000 Binary files a/GSA_distrib/4.0.3/GSA.zip and /dev/null differ diff --git a/GSA_distrib/4.0.3/LPTAU.m b/GSA_distrib/4.0.3/LPTAU.m deleted file mode 100644 index 7427de885..000000000 --- a/GSA_distrib/4.0.3/LPTAU.m +++ /dev/null @@ -1,512 +0,0 @@ -function VECTOR = LPTAU(I, N) -% -% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN -% KELDYSH INSTITUTE OF APPLIED MATHEMATICS -% RUSSIAN ACADEMY OF SCIENCES -% -% QUASIRANDOM SEQUENCE GENERATORS -% ------------------------------- -% -% 28.11.1991 -% -% NOTE TO THE USER BY the NEA Data Bank: -% This quasi random number generator has been made available to -% you on condition that its identity is preserved when used -% in computer programs. If its use leads to scientific publication -% of results you should cite it in the references, in addition -% no commercial use should be made unless agreed upon with the -% main author (Prof. I.M. Sobol') -% -% ABSTRACT -% ........ -% -% POINTS BELONGING TO LP-TAU SEQUENCES UNIFORMLY DISTRIBUTED IN THE -% N-DIMENSIONAL UNIT CUBE ARE OFTEN USED IN NUMERICAL MATHEMATICS: -% -% - AS NODES FOR MULTIDIMENSIONAL INTEGRATION; -% - AS SEARCHING POINTS IN GLOBAL OPTIMIZATION; -% - AS TRIAL POINTS IN MULTI-CRITERIA DECISION MAKING; -% - AS QUASIRANDOM POINTS FOR QUASI-MONTECARLO ALGORITHMS; -% - ETC. -% -% THIS SUBROUTINE CONTAINS THE ALGORITHM FOR FAST GENERATION OF -% LP-TAU SEQUENCES THAT ARE SUITABLE FOR MULTI-PROCESSOR COMPUTATIONS. -% THE DIMENSIONS N.LE.51, THE NUMBER OF POINTS N.LT.2**30. -% THE PROGRAMMING LANGUAGE IS FORTRAN-77. THIS SUBROUTINE IS AVAILABLE -% ALSO IN %-LANGUAGE. -% THE REPORT DESCRIBING THE ALGORITHM CONTAINS THE DESCRIPTION OF THE -% ALGORITHM AND CERTAIN IMPORTANT PROPERTIES OF LP-TAU SEQUENCES AND -% THEIR GENERALIZATIONS ARE DISCUSSED. -% -% REFERENCE: -% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN -% KELDYSH INSTITUTE OF APPLIED MATHEMATICS -% RUSSIAN ACADEMY OF SCIENCES -% -% QUASIRANDOM SEQUENCE GENERATORS -% MOSCOW 1992, IPM ZAK. NO.30 (100 COPIES) -% -% ------------------------------------------------------------------------ -% -% INPUT PARAMETERS: -% -% I - NUMBER OF THE POINT (I=(0,2**30-1)), -% N - DIMENSION OF THE POINT (0MAXNUM) | (N>MAXDIM)), - disp('LP-TAU CALL FAILED') - disp(' PRESS TO EXIT LPTAU') - pause - return -end -if ((PRVNUM+1==I) & (N<=PRVDIM)), - % - % RECURRENT GENERATION OF THE POINT - % - % - % SEARCH POSITION OF THE RIGHTMOST "1" - % IN THE BINARY REPRESENTATION OF I - % - L=0; - POS=0; - while L1e-010); - % If we deal with groups we can only estimate the new mu* - % measure since factors in the same groups can move in - % opposite direction and the definition of the standard - % Morris mu cannopt be applied. - % In the new version the elementary effect is defined with - % the absolute value. - %SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3)); - SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); - else - Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:)); - % If no groups --> we compute both the original and - % modified measure - if Delta(j) > 0 %=> +Delta - SAmeas(Change_factor(j,i),i) = (Single_OutValues(j+1) - Single_OutValues(j) )/Delt; %(2/3); - else %=> -Delta - SAmeas(Change_factor(j,i),i) = (Single_OutValues(j) - Single_OutValues(j+1) )/Delt; %(2/3); - end - end - end %for j=1:sizea - - end %for i=1:r - - if NumGroups ~ 0 - SAmeas = SAmeas'; - end - - % Compute Mu AbsMu and StDev - if any(any(isnan(SAmeas))) - for j=1:NumFact, - SAm = SAmeas(j,:); - SAm = SAm(find(~isnan(SAm))); - rr=length(SAm); - AbsMu(j,1) = sum(abs(SAm),2)/rr; - if NumGroups == 0 - Mu(j,1) = sum(SAm,2)/rr; - StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5; - end - end - else - AbsMu = sum(abs(SAmeas),2)/r; - if NumGroups == 0 - Mu = sum(SAmeas,2)/r; - StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5; - end - end - - % Define the output Matrix - if we have groups we cannot define the old - % measure mu, only mu* makes sense - if NumGroups > 0 - OutMatrix = [OutMatrix; AbsMu]; - else - OutMatrix = [OutMatrix; AbsMu, Mu, StDev]; - end -end % For Each Output diff --git a/GSA_distrib/4.0.3/Sampling_Function_2.m b/GSA_distrib/4.0.3/Sampling_Function_2.m deleted file mode 100644 index ccd3a87f9..000000000 --- a/GSA_distrib/4.0.3/Sampling_Function_2.m +++ /dev/null @@ -1,174 +0,0 @@ -function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -% Inputs: k (1,1) := number of factors examined or number of groups examined. -% In case the groups are chosen the number of factors is stores in NumFact and -% sizea becomes the number of created groups. -% NumFact (1,1) := number of factors examined in the case when groups are chosen -% r (1,1) := sample size -% p (1,1) := number of intervals considered in [0, 1] -% UB(sizea,1) := Upper Bound for each factor -% LB(sizea,1) := Lower Bound for each factor -% GroupNumber(1,1) := Number of groups (eventually 0) -% GroupMat(NumFact,GroupNumber):= Matrix which describes the chosen groups. Each column represents a group and its elements -% are set to 1 in correspondence of the factors that belong to the fixed group. All -% the other elements are zero. -% Local Variables: -% sizeb (1,1) := sizea+1 -% sizec (1,1) := 1 -% randmult (sizea,1) := vector of random +1 and -1 -% perm_e(1,sizea) := vector of sizea random permutated indeces -% fact(sizea) := vector containing the factor varied within each traj -% DDo(sizea,sizea) := D* in Morris, 1991 -% A(sizeb,sizea) := Jk+1,k in Morris, 1991 -% B(sizeb,sizea) := B in Morris, 1991 -% Po(sizea,sizea) := P* in Morris, 1991 -% Bo(sizeb,sizea) := B* in Morris, 1991 -% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991 -% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory) -% In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory -% of k step in the parameter space and it provides a single elementary -% effect per factor -% MyInt() -% Fact(sizea,1) := for each loop vector indicating which factor or group of factors has been changed -% in each step of the trajectory -% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design -% for single factor analysis, while it constitutes an intermediate step for the group analysis. -% -% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices -% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors -% -% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine -% follows the following steps: -% 1- Creation of P0 and DD0 matrices defined in Morris for the groups. This means that the dimensions of these -% 2 matrices are (GroupNumber,GroupNumber). -% 2- Creation of AuxMat matrix with (GroupNumber+1,GroupNumber) elements. -% 3- Definition of GroupB0 starting from AuxMat, GroupMat and P0. -% 4- The final B0 for groups is obtained as [ones(sizeb,1)*x0' + GroupB0]. The P0 permutation is present in GroupB0 -% and it's not necessary to permute the matrix (ones(sizeb,1)*x0') because it's already randomly created. -% Reference: -% A. Saltelli, K. Chan, E.M. Scott, "Sensitivity Analysis" on page 68 ss -% -% F. Campolongo, J. Cariboni, JRC - IPSC Ispra, Varese, IT -% Last Update: 15 November 2005 by J.Cariboni -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -% Parameters and initialisation of the output matrix -sizea = k; -Delta = p/(2*p-2); -%Delta = 1/3 -NumFact = sizea; -GroupNumber = size(GroupMat,2); - -if GroupNumber ~ 0; - sizea = size(GroupMat,2); -end - -sizeb = sizea + 1; -sizec = 1; -Outmatrix = []; -OutFact = []; - -% For each i generate a trajectory -for i=1:r - - % Construct DD0 - OLD VERSION - it does not need communication toolbox - % RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0). - % Note that DD0 tells if the factor have to be increased or ddecreased - % by Delta. - randmult = ones(k,1); - v = rand(k,1); - randmult (find(v < 0.5))=-1; - randmult = repmat(randmult,1,k); - DD0 = randmult .* eye(k); - - % Construct DD0 - NEW VERSION - it needs communication toolbox - % randsrc(m) generates an m-by-m matrix, each of whose entries independently takes the value -1 with probability 1/2, - % and 1 with probability 1/2. - % DD0 = randsrc(NumFact) .* eye(NumFact); - - % Construct B (lower triangular) - B = ones(sizeb,sizea); - for j = 1:sizea - B(1:j,j)=0; - end - - % Construct A0, A - A0 = ones(sizeb,1); - A = ones(sizeb,NumFact); - - % Construct the permutation matrix P0. In each column of P0 one randomly chosen element equals 1 - % while all the others equal zero. - % P0 tells the order in which order factors are changed in each - % trajectory. P0 is created as it follows: - % 1) All the elements of P0 are set equal to zero ==> P0 = zeros (sizea, sizea); - % 2) The function randperm create a random permutation of integer 1:sizea, without repetitions ==> perm_e; - % 3) In each column of P0 the element indicated in perm_e is set equal to one. - % Note that P0 is then used reading it by rows. - P0 = zeros (sizea, sizea); - perm_e = randperm(sizea); % RANDPERM(n) is a random permutation of the integers from 1 to n. - for j = 1:sizea - P0(perm_e(j),j) = 1; - end - - % When groups are present the random permutation is done only on B. The effect is the same since - % the added part (A0*x0') is completely random. - if GroupNumber ~ 0 - B = B * (GroupMat*P0')'; - end - - % Compute AuxMat both for single factors and groups analysis. For Single factors analysis - % AuxMat is added to (A0*X0) and then permutated through P0. When groups are active AuxMat is - % used to build GroupB0. AuxMat is created considering DD0. If the element on DD0 diagonal - % is 1 then AuxMat will start with zero and add Delta. If the element on DD0 diagonal is -1 - % then DD0 will start Delta and goes to zero. - AuxMat = Delta*0.5*((2*B - A) * DD0 + A); - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube - % [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta] - MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors - - % OLD VERSION - it needs communication toolbox - % w = randint(NumFact,1,[1,size(MyInt,2)]); - - % NEW VERSION - construct a version of random integers - % 1) create a vector of random integers - % 2) divide [0,1] into the needed steps - % 3) check in which interval the random numbers fall - % 4) generate the corresponding integer - v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1) - IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2) - DiffAuxVec = IntUsed - v; % 3) - - for ii = 1:size(DiffAuxVec,1) - w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4) - end - x0 = MyInt(1,w)'; % Define x0 - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a - % trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors) - if GroupNumber ~ 0 - B0 = (A0*x0' + AuxMat); - else - B0 = (A0*x0' + AuxMat)*P0; - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % c --> Compute values in the original intervals - % B0 has values x(i,j) in [0, 1/(p -1), 2/(p -1), ... , 1]. - % To obtain values in the original intervals [LB, UB] we compute - % LB(j) + x(i,j)*(UB(j)-LB(j)) - In = repmat(LB,1,sizeb)' + B0 .* repmat((UB-LB),1,sizeb)'; - - % Create the Factor vector. Each component of this vector indicate which factor or group of factor - % has been changed in each step of the trajectory. - for j=1:sizea - Fact(1,j) = find(P0(j,:)); - end - Fact(1,sizea+1) = 0; - - Outmatrix = [Outmatrix; In]; - OutFact = [OutFact; Fact']; - -end \ No newline at end of file diff --git a/GSA_distrib/4.0.3/beta_inv.m b/GSA_distrib/4.0.3/beta_inv.m deleted file mode 100644 index d3c95836d..000000000 --- a/GSA_distrib/4.0.3/beta_inv.m +++ /dev/null @@ -1,38 +0,0 @@ -function x = beta_inv(p, a, b) -% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution -%-------------------------------------------------------------- -% USAGE: x = beta_inv(p,a,b) -% where: p = vector of probabilities -% a = beta distribution parameter, a = scalar -% b = beta distribution parameter b = scalar -% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1)) -%-------------------------------------------------------------- -% RETURNS: x at each element of p for the beta(a,b) distribution -%-------------------------------------------------------------- -% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd -%-------------------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to -% match the format of the econometrics toolbox - -if (nargin ~= 3) - error('Wrong # of arguments to beta_inv'); -end - -if any(any((a<=0)|(b<=0))) - error('beta_inv parameter a or b is nonpositive'); -end -if any(any(abs(2*p-1)>1)) - error('beta_inv: A probability should be 0<=p<=1'); -end - -x = a ./ (a+b); -dx = 1; -while any(any(abs(dx)>256*eps*max(x,1))) - dx = (betainc(x,a,b) - p) ./ beta_pdf(x,a,b); - x = x - dx; - x = x + (dx - x) / 2 .* (x<0); -end - \ No newline at end of file diff --git a/GSA_distrib/4.0.3/beta_pdf.m b/GSA_distrib/4.0.3/beta_pdf.m deleted file mode 100644 index 8412fbdce..000000000 --- a/GSA_distrib/4.0.3/beta_pdf.m +++ /dev/null @@ -1,32 +0,0 @@ -function pdf = beta_pdf(x, a, b) -% PURPOSE: pdf of the beta(a,b) distribution -%-------------------------------------------------------------- -% USAGE: pdf = beta_pdf(x,a,b) -% where: x = vector of components -% a = beta distribution parameter, a = scalar -% b = beta distribution parameter b = scalar -% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1)) -%-------------------------------------------------------------- -% RETURNS: pdf at each element of x of the beta(a,b) distribution -%-------------------------------------------------------------- -% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd -%-------------------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to -% match the format of the econometrics toolbox - - -if (nargin ~=3) - error('Wrong # of arguments to beta_pdf'); -end - -if any(any((a<=0)|(b<=0))) - error('Parameter a or b is nonpositive'); -end - -I = find((x<0)|(x>1)); - -pdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b); -pdf(I) = 0*I; diff --git a/GSA_distrib/4.0.3/cumplot.m b/GSA_distrib/4.0.3/cumplot.m deleted file mode 100644 index a700d3784..000000000 --- a/GSA_distrib/4.0.3/cumplot.m +++ /dev/null @@ -1,14 +0,0 @@ -function h = cumplot(x); -%function h =cumplot(x) -% Copyright (C) 2005 Marco Ratto - - -n=length(x); -x=[-inf; sort(x); Inf]; -y=[0:n n]./n; -h0 = stairs(x,y); -grid on, - -if nargout, - h=h0; -end diff --git a/GSA_distrib/4.0.3/dat_fil_.m b/GSA_distrib/4.0.3/dat_fil_.m deleted file mode 100644 index 0b3ac8f8e..000000000 --- a/GSA_distrib/4.0.3/dat_fil_.m +++ /dev/null @@ -1,30 +0,0 @@ -function c = dat_fil_(data_file); -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -try - eval(data_file); -catch - load(data_file); -end -clear data_file; - -a=who; - -for j=1:length(a) - eval(['c.',a{j},'=',a{j},';']); -end \ No newline at end of file diff --git a/GSA_distrib/4.0.3/dynare_MC.m b/GSA_distrib/4.0.3/dynare_MC.m deleted file mode 100644 index 26a8135ea..000000000 --- a/GSA_distrib/4.0.3/dynare_MC.m +++ /dev/null @@ -1,142 +0,0 @@ -function dynare_MC(var_list_,OutDir) -% -% Adapted by M. Ratto from dynare_estimation.m and posteriorsmoother.m -% (dynare_estimation.m and posteriorsmoother.m are part of DYNARE, -% copyright M. Juillard) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ options_ oo_ estim_params_ -global bayestopt_ - -if options_.filtered_vars ~= 0 & options_.filter_step_ahead == 0 - options_.filter_step_ahead = 1; -end -if options_.filter_step_ahead ~= 0 - options_.nk = max(options_.filter_step_ahead); -else - options_.nk = 0; -end - - -nvx = estim_params_.nvx; -nvn = estim_params_.nvn; -ncx = estim_params_.ncx; -ncn = estim_params_.ncn; -np = estim_params_.np ; -npar = nvx+nvn+ncx+ncn+np; - -if isempty(options_.datafile) - error('ESTIMATION: datafile option is missing') -end - -if isempty(options_.varobs) - error('ESTIMATION: VAROBS is missing') -end - -%% Read and demean data -rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); - -options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1); -gend = options_.nobs; - -rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); -if options_.loglinear == 1 & ~options_.logdata - rawdata = log(rawdata); -end -if options_.prefilter == 1 - bayestopt_.mean_varobs = mean(rawdata,1); - data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs); -else - data = transpose(rawdata); -end - -if ~isreal(rawdata) - error(['There are complex values in the data. Probably a wrong' ... - ' transformation']) -end - -offset = npar-np; -fname_=M_.fname; - -options_ = set_default_option(options_,'opt_gsa',1); -options_gsa_ = options_.opt_gsa; - -if options_gsa_.pprior, - namfile=[fname_,'_prior']; -else - namfile=[fname_,'_mc']; -end -load([OutDir,'\',namfile],'lpmat', 'lpmat0', 'istable') -% load(options_.mode_file) -%% -%% -%% -x=[lpmat0(istable,:) lpmat(istable,:)]; -clear lpmat lpmat0 istable %iunstable egg yys T -B = size(x,1); -[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(x(1,:)',gend,data); -n1=size(atT,1); - -nfil=B/40; -stock_smooth = zeros(M_.endo_nbr,gend,40); -stock_filter = zeros(M_.endo_nbr,gend+1,40); -stock_ys = zeros(40, M_.endo_nbr); -logpo2=zeros(B,1); -%% -h = waitbar(0,'MC smoother ...'); -delete([OutDir,'\',namfile,'_*.mat']) -ib=0; -ifil=0; -opt_gsa=options_.opt_gsa; -for b=1:B - ib=ib+1; - deep = x(b,:)'; - set_all_parameters(deep); - dr = resol(oo_.steady_state,0); - %deep(1:offset) = xparam1(1:offset); - logpo2(b,1) = DsgeLikelihood(deep,gend,data); - if opt_gsa.lik_only==0, - [atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(deep,gend,data); - stock_smooth(:,:,ib)=atT(1:M_.endo_nbr,:); -% stock_filter(:,:,ib)=filtered_state_vector(1:M_.endo_nbr,:); - stock_filter(:,:,ib)=aK(1,1:M_.endo_nbr,:); - stock_ys(ib,:)=ys'; - if ib==40, - ib=0; - ifil=ifil+1; - save([OutDir,'\',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys') - stock_smooth = zeros(M_.endo_nbr,gend,40); - stock_filter = zeros(M_.endo_nbr,gend+1,40); - stock_ys = zeros(40, M_.endo_nbr); - end - end - waitbar(b/B,h,['MC smoother ...',num2str(b),'/',num2str(B)]); -end -close(h) -if opt_gsa.lik_only==0, -if ib>0, - ifil=ifil+1; - stock_smooth = stock_smooth(:,:,1:ib); - stock_filter = stock_filter(:,:,1:ib); - stock_ys = stock_ys(1:ib,:); - save([OutDir,'\',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys') -end -end -stock_gend=gend; -stock_data=data; -save([OutDir,'\',namfile],'x','logpo2','stock_gend','stock_data','-append') diff --git a/GSA_distrib/4.0.3/filt_mc_.m b/GSA_distrib/4.0.3/filt_mc_.m deleted file mode 100644 index 41d5e7ae8..000000000 --- a/GSA_distrib/4.0.3/filt_mc_.m +++ /dev/null @@ -1,708 +0,0 @@ -function [rmse_MC, ixx] = filt_mc_(OutDir) -% function [rmse_MC, ixx] = filt_mc_(OutDir) -% copyright Marco Ratto 2006 -% inputs (from opt_gsa structure) -% vvarvecm = options_gsa_.var_rmse; -% loadSA = options_gsa_.load_rmse; -% pfilt = options_gsa_.pfilt_rmse; -% alpha = options_gsa_.alpha_rmse; -% alpha2 = options_gsa_.alpha2_rmse; -% istart = options_gsa_.istart_rmse; -% alphaPC = 0.5; -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global bayestopt_ estim_params_ M_ options_ oo_ - -options_gsa_=options_.opt_gsa; -vvarvecm = options_gsa_.var_rmse; -loadSA = options_gsa_.load_rmse; -pfilt = options_gsa_.pfilt_rmse; -alpha = options_gsa_.alpha_rmse; -alpha2 = options_gsa_.alpha2_rmse; -istart = options_gsa_.istart_rmse; -alphaPC = 0.5; - -fname_ = M_.fname; -lgy_ = M_.endo_names; -dr_ = oo_.dr; - -disp(' ') -disp(' ') -disp('Starting sensitivity analysis') -disp('for the fit of EACH observed series ...') -disp(' ') -disp('Deleting old SA figures...') -a=dir([OutDir,'\*.*']); -tmp1='0'; -if options_.opt_gsa.ppost, - tmp=['_rmse_post']; -else - if options_.opt_gsa.pprior - tmp=['_rmse_prior']; - else - tmp=['_rmse_mc']; - end - if options_gsa_.lik_only, - tmp1 = [tmp,'_post_SA']; - tmp = [tmp,'_lik_SA']; - end -end -for j=1:length(a), - if strmatch([fname_,tmp],a(j).name), - disp(a(j).name) - delete([OutDir,'\',a(j).name]) - end, - if strmatch([fname_,tmp1],a(j).name), - disp(a(j).name) - delete([OutDir,'\',a(j).name]) - end, -end -disp('done !') - - -nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn; -npar=estim_params_.np; -if ~isempty(options_.mode_file), - load(options_.mode_file,'xparam1'), -end -if options_.opt_gsa.ppost, - c=load([fname_,'_mean'],'xparam1'); - xparam1_mean=c.xparam1; - clear c -elseif ~isempty(options_.mode_file) & ~isempty(ls([fname_,'_mean.mat'])) - c=load([fname_,'_mean'],'xparam1'); - xparam1_mean=c.xparam1; - clear c -end - -if options_.opt_gsa.ppost, - fnamtmp=[fname_,'_post']; - DirectoryName = CheckPath('metropolis'); -else - if options_.opt_gsa.pprior - fnamtmp=[fname_,'_prior']; - else - fnamtmp=[fname_,'_mc']; - end -end -if ~loadSA, - if exist('xparam1','var') - set_all_parameters(xparam1); - steady_; - ys_mode=oo_.steady_state; - end - if exist('xparam1_mean','var') - set_all_parameters(xparam1_mean); - steady_; - ys_mean=oo_.steady_state; - end -% eval(options_.datafile) - obs = dat_fil_(options_.datafile); - if ~options_.opt_gsa.ppost - load([OutDir,'\',fnamtmp],'x','logpo2','stock_gend','stock_data'); - logpo2=-logpo2; - else - %load([DirectoryName '/' M_.fname '_data.mat']); - [stock_gend, stock_data] = read_data; - filfilt = dir([DirectoryName '/' M_.fname '_filter*.mat']); - filparam = dir([DirectoryName '/' M_.fname '_param*.mat']); - x=[]; - logpo2=[]; - sto_ys=[]; - for j=1:length(filparam), - %load([DirectoryName '/' M_.fname '_param',int2str(j),'.mat']); - if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name)) - load([DirectoryName '/' filparam(j).name]); - x=[x; stock]; - logpo2=[logpo2; stock_logpo]; - sto_ys=[sto_ys; stock_ys]; - clear stock stock_logpo stock_ys; - end - end - end - nruns=size(x,1); - nfilt=floor(pfilt*nruns); - if options_.opt_gsa.ppost | (options_.opt_gsa.ppost==0 & options_.opt_gsa.lik_only==0) - disp(' ') - disp('Computing RMSE''s...') - fobs = options_.first_obs; - nobs=options_.nobs; - for i=1:size(vvarvecm,1), - vj=deblank(vvarvecm(i,:)); - eval(['vobs =obs.',vj,'(fobs:fobs-1+nobs);']) - if options_.prefilter == 1 - %eval([vj,'=',vj,'-bayestopt_.mean_varobs(i);']) - %eval([vj,'=',vj,'-mean(',vj,',1);']) - vobs = vobs-mean(vobs,1); - end - - jxj = strmatch(vj,lgy_(dr_.order_var,:),'exact'); - js = strmatch(vj,lgy_,'exact'); - if exist('xparam1','var') -% if isfield(oo_,'FilteredVariables') -% eval(['rmse_mode(i) = sqrt(mean((vobs(istart:end)-oo_.steady_state(js)-oo_.FilteredVariables.',vj,'(istart:end-1)).^2));']) -% else - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,stock_gend,stock_data); - y0 = squeeze(aK(1,jxj,:)) + ... - kron(ys_mode(js,:),ones(size(aK,3),1)); -% y0 = ahat(jxj,:)' + ... -% kron(ys_mode(js,:),ones(size(ahat,2),1)); - rmse_mode(i) = sqrt(mean((vobs(istart:end)-y0(istart:length(vobs))).^2)); -% end - end - y0=zeros(nobs+1,nruns); - if options_.opt_gsa.ppost - %y0=zeros(nobs+max(options_.filter_step_ahead),nruns); - nbb=0; - for j=1:length(filfilt), - load([DirectoryName '/' M_.fname '_filter_step_ahead',num2str(j),'.mat']); - nb = size(stock,4); -% y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,:,:)) + ... -% kron(sto_ys(nbb+1:nbb+nb,js)',ones(size(stock,3),1)); - y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,1:nobs+1,:)) + ... - kron(sto_ys(nbb+1:nbb+nb,js)',ones(nobs+1,1)); - %y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock; - nbb=nbb+nb; - clear stock; - end - else - filfilt=ls([OutDir,'\',fnamtmp,'_*.mat']); - nbb=0; - for j=1:size(filfilt,1), - load([OutDir,'\',fnamtmp,'_',num2str(j),'.mat'],'stock_filter','stock_ys'); - nb = size(stock_filter,3); - y0(:,nbb+1:nbb+nb) = squeeze(stock_filter(jxj,:,:)) + ... - kron(stock_ys(:,js)',ones(nobs+1,1)); - %y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock; - nbb=nbb+nb; - clear stock_filter; - end - -% y0 = squeeze(stock_filter(:,jxj,:)) + ... -% kron(stock_ys(js,:),ones(size(stock_filter,1),1)); - end - y0M=mean(y0,2); - for j=1:nruns, - rmse_MC(j,i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1,j)).^2)); - end - if exist('xparam1_mean','var') - %eval(['rmse_pmean(i) = sqrt(mean((',vj,'(fobs-1+istart:fobs-1+nobs)-y0M(istart:end-1)).^2));']) - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,stock_gend,stock_data); - y0 = squeeze(aK(1,jxj,:)) + ... - kron(ys_mean(js,:),ones(size(aK,3),1)); -% y0 = ahat(jxj,:)' + ... -% kron(ys_mean(js,:),ones(size(ahat,2),1)); - rmse_pmean(i) = sqrt(mean((vobs(istart:end)-y0(istart:length(vobs))).^2)); - end - end - clear stock_filter; - end - for j=1:nruns, - lnprior(j,1) = priordens(x(j,:),bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4); - end - likelihood=logpo2(:)-lnprior(:); - disp('... done!') - - if options_.opt_gsa.ppost - save([OutDir,'\',fnamtmp], 'x', 'logpo2', 'likelihood', 'rmse_MC', 'rmse_mode','rmse_pmean') - else - if options_.opt_gsa.lik_only - save([OutDir,'\',fnamtmp], 'likelihood', '-append') - else - save([OutDir,'\',fnamtmp], 'likelihood', 'rmse_MC','-append') - if exist('xparam1_mean','var') - save([OutDir,'\',fnamtmp], 'rmse_pmean','-append') - end - if exist('xparam1','var') - save([OutDir,'\',fnamtmp], 'rmse_mode','-append') - end - end - end -else - if options_.opt_gsa.lik_only & options_.opt_gsa.ppost==0 - load([OutDir,'\',fnamtmp],'x','logpo2','likelihood'); - else - load([OutDir,'\',fnamtmp],'x','logpo2','likelihood','rmse_MC','rmse_mode','rmse_pmean'); - end - lnprior=logpo2(:)-likelihood(:); - nruns=size(x,1); - nfilt=floor(pfilt*nruns); -end -% smirnov tests -nfilt0=nfilt*ones(size(vvarvecm,1),1); -logpo2=logpo2(:); -if ~options_.opt_gsa.ppost - [dum, ipost]=sort(-logpo2); - [dum, ilik]=sort(-likelihood); -end -if ~options_.opt_gsa.ppost & options_.opt_gsa.lik_only - if options_.opt_gsa.pprior - anam='rmse_prior_post'; - else - anam='rmse_mc_post'; - end - stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ipost(1:nfilt),:),alpha2,anam, OutDir); - if options_.opt_gsa.pprior - anam='rmse_prior_lik'; - else - anam='rmse_mc_lik'; - end - stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ilik(1:nfilt),:),alpha2,anam, OutDir); -else - for i=1:size(vvarvecm,1), - [dum, ixx(:,i)]=sort(rmse_MC(:,i)); - if options_.opt_gsa.ppost, - %nfilt0(i)=length(find(rmse_MC(:,i)0.0001 ); -vvarvecm=vvarvecm(ivar,:); -rmse_MC=rmse_MC(:,ivar); - -disp(' ') -% if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior, - disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ]) -% else -% disp(['Sample filtered the best RMSE''s smaller than RMSE at the posterior mean ...' ]) -% end -% figure, boxplot(rmse_MC) -% set(gca,'xticklabel',vvarvecm) -% saveas(gcf,[fname_,'_SA_RMSE']) - -disp(' ') -disp(' ') -disp('RMSE ranges after filtering:') -if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior, - disp([' best ',num2str(pfilt*100),'% filtered remaining 90%']) - disp([' min max min max posterior mode']) -else - disp([' best filtered remaining ']) - disp([' min max min max posterior mean']) -end -for j=1:size(vvarvecm,1), - disp([vvarvecm(j,:), sprintf('%15.5g',[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - max(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - rmse_txt(j)])]) - % disp([vvarvecm(j,:), sprintf('%15.5g',[min(logpo2(ixx(1:nfilt,j))) ... - % max(logpo2(ixx(1:nfilt,j))) ... - % min(logpo2(ixx(nfilt+1:end,j))) ... - % max(logpo2(ixx(nfilt+1:end,j)))])]) -end - -SP=zeros(npar+nshock,size(vvarvecm,1)); -for j=1:size(vvarvecm,1), - ns=find(PP(:,j)1),:); -snam=param_names(find(nsp>0),:); -% snam0=bayestopt_.name(find(nsp==0)); -% snam1=bayestopt_.name(find(nsp==1)); -% snam2=bayestopt_.name(find(nsp>1)); -% snam=bayestopt_.name(find(nsp>0)); -nsnam=(find(nsp>1)); - -disp(' ') -disp(' ') -disp('These parameters do not affect significantly the fit of ANY observed series:') -disp(snam0) -disp(' ') -disp('These parameters affect ONE single observed series:') -disp(snam1) -disp(' ') -disp('These parameters affect MORE THAN ONE observed series: trade off exists!') -disp(snam2) - - -%pnam=bayestopt_.name(end-estim_params_.np+1:end); -pnam=bayestopt_.name; - -% plot trade-offs -a00=jet(size(vvarvecm,1)); -for ix=1:ceil(length(nsnam)/5), - figure, - for j=1+5*(ix-1):min(size(snam2,1),5*ix), - subplot(2,3,j-5*(ix-1)) - %h0=cumplot(x(:,nsnam(j)+nshock)); - h0=cumplot(x(:,nsnam(j))); - set(h0,'color',[0 0 0]) - hold on, - np=find(SP(nsnam(j),:)); - %a0=jet(nsp(nsnam(j))); - a0=a00(np,:); - for i=1:nsp(nsnam(j)), %size(vvarvecm,1), - %h0=cumplot(x(ixx(1:nfilt,np(i)),nsnam(j)+nshock)); - h0=cumplot(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j))); - set(h0,'color',a0(i,:)) - end - ydum=get(gca,'ylim'); - %xdum=xparam1(nshock+nsnam(j)); - if exist('xparam1') - xdum=xparam1(nsnam(j)); - h1=plot([xdum xdum],ydum); - set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - end - xlabel('') - title([pnam{nsnam(j)}],'interpreter','none') - end - %subplot(3,2,6) - h0=legend(str2mat('base',vvarvecm(np,:)),0); - set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none') - %h0=legend({'base',vnam{np}}',0); - %set(findobj(get(h0,'children'),'type','text'),'interpreter','none') - if options_.opt_gsa.ppost - saveas(gcf,[OutDir,'\',fname_,'_rmse_post_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_' int2str(ix)]); - eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_' int2str(ix)]); - else - if options_.opt_gsa.pprior - saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_' int2str(ix)]); - eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_' int2str(ix)]); - else - saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_' int2str(ix)]); - eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_' int2str(ix)]); - end - end -end -close all - -for j=1:size(SP,2), - nsx(j)=length(find(SP(:,j))); -end - -number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two. -bandwidth = 0; % Rule of thumb optimal bandwidth parameter. -kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton. -%kernel_function = 'uniform'; % Gaussian kernel for Fast Fourrier Transform approximaton. - -for ix=1:ceil(length(nsnam)/5), - figure, - for j=1+5*(ix-1):min(size(snam2,1),5*ix), - subplot(2,3,j-5*(ix-1)) - optimal_bandwidth = mh_optimal_bandwidth(x(:,nsnam(j)),size(x,1),bandwidth,kernel_function); - [x1,f1] = kernel_density_estimate(x(:,nsnam(j)),number_of_grid_points,... - size(x,1),optimal_bandwidth,kernel_function); - h0 = plot(x1, f1,'k'); - hold on, - np=find(SP(nsnam(j),:)); - %a0=jet(nsp(nsnam(j))); - a0=a00(np,:); - for i=1:nsp(nsnam(j)), %size(vvarvecm,1), - optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),nfilt,bandwidth,kernel_function); - [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),number_of_grid_points,... - nfilt,optimal_bandwidth,kernel_function); - h0 = plot(x1, f1); - set(h0,'color',a0(i,:)) - end - ydum=get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]); - if exist('xparam1') - %xdum=xparam1(nshock+nsnam(j)); - xdum=xparam1(nsnam(j)); - h1=plot([xdum xdum],[0 ydum(2)]); - set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - end - xlabel('') - title([pnam{nsnam(j)}],'interpreter','none') - end - h0=legend(str2mat('base',vvarvecm(np,:)),0); - set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none') - %h0=legend({'base',vnam{np}}',0); - %set(findobj(get(h0,'children'),'type','text'),'interpreter','none') - if options_.opt_gsa.ppost - saveas(gcf,[OutDir,'\',fname_,'_rmse_post_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_post_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '\' fname_ '_rmse_post_dens_' int2str(ix)]); - else - if options_.opt_gsa.pprior - saveas(gcf,[OutDir,'\',fname_,'_rmse_prior_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_prior_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '\' fname_ '_rmse_prior_dens_' int2str(ix)]); - else - saveas(gcf,[OutDir,'\',fname_,'_rmse_mc_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '\' fname_ '_rmse_mc_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '\' fname_ '_rmse_mc_dens_' int2str(ix)]); - end - end -end -close all - -% for j=1:size(SP,2), -% nfig=0; -% np=find(SP(:,j)); -% for i=1:nsx(j), %size(vvarvecm,1), -% if mod(i,12)==1, -% nfig=nfig+1; -% %figure('name',['Sensitivity of fit of ',vnam{j}]), -% figure('name',['Sensitivity of fit of ',deblank(vvarvecm(j,:)),' ',num2str(nfig)]), -% end -% -% subplot(3,4,i-12*(nfig-1)) -% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt,j),np(i)),nfilt,bandwidth,kernel_function); -% [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt,j),np(i)),number_of_grid_points,... -% optimal_bandwidth,kernel_function); -% plot(x1, f1,':k','linewidth',2) -% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(nfilt+1:end,j),np(i)),nruns-nfilt,bandwidth,kernel_function); -% [x1,f1] = kernel_density_estimate(x(ixx(nfilt+1:end,j),np(i)),number_of_grid_points,... -% optimal_bandwidth,kernel_function); -% hold on, plot(x1, f1,'k','linewidth',2) -% ydum=get(gca,'ylim'); -% %xdum=xparam1(nshock+np(i)); -% xdum=xparam1(np(i)); -% h1=plot([xdum xdum],ydum); -% set(h1,'color',[0.85 0.85 0.85],'linewidth',2) -% %xdum1=mean(x(ixx(1:nfilt,j),np(i)+nshock)); -% xdum1=mean(x(ixx(1:nfilt,j),np(i))); -% h2=plot([xdum1 xdum1],ydum); -% set(h2,'color',[0 1 0],'linewidth',2) -% % h0=cumplot(x(nfilt+1:end,np(i)+nshock)); -% % set(h0,'color',[1 1 1]) -% % hold on, -% % h0=cumplot(x(ixx(1:nfilt,j),np(i)+nshock)); -% % set(h0,'linestyle',':','color',[1 1 1]) -% %title([pnam{np(i)}]) -% title([pnam{np(i)},'. K-S prob ', num2str(PP(np(i),j))],'interpreter','none') -% xlabel('') -% if mod(i,12)==0 | i==nsx(j), -% saveas(gcf,[fname_,'_rmse_',deblank(vvarvecm(j,:)),'_',int2str(nfig)]) -% close(gcf) -% end -% end -% end - - -disp(' ') -disp(' ') -disp('Sensitivity table (significance and direction):') -vav=char(zeros(1, size(param_names,2)+3 )); -ibl = 12-size(vvarvecm,2); -for j=1:size(vvarvecm,1), - vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)]; -end -disp(vav) -for j=1:npar+nshock, %estim_params_.np, - %disp([param_names(j,:), sprintf('%8.5g',SP(j,:))]) - disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))]) - disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))]) -end - - -disp(' ') -disp(' ') -disp('Starting bivariate analysis:') - -for i=1:size(vvarvecm,1) - if options_.opt_gsa.ppost - fnam = ['rmse_post_',deblank(vvarvecm(i,:))]; - else - if options_.opt_gsa.pprior - fnam = ['rmse_prior_',deblank(vvarvecm(i,:))]; - else - fnam = ['rmse_mc_',deblank(vvarvecm(i,:))]; - end - end - stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,fnam, OutDir); - - % [pc,latent,explained] = pcacov(c0); - % %figure, bar([explained cumsum(explained)]) - % ifig=0; - % j2=0; - % for j=1:npar+nshock, - % i2=find(abs(pc(:,j))>alphaPC); - % if ~isempty(i2), - % j2=j2+1; - % if mod(j2,12)==1, - % ifig=ifig+1; - % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), - % end - % subplot(3,4,j2-(ifig-1)*12) - % bar(pc(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) - % end - % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, - % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) - % end - % end - % close all -end - -end \ No newline at end of file diff --git a/GSA_distrib/4.0.3/gamm_cdf.m b/GSA_distrib/4.0.3/gamm_cdf.m deleted file mode 100644 index a11d0962a..000000000 --- a/GSA_distrib/4.0.3/gamm_cdf.m +++ /dev/null @@ -1,27 +0,0 @@ -function cdf = gamm_cdf (x, a) -% PURPOSE: returns the cdf at x of the gamma(a) distribution -%--------------------------------------------------- -% USAGE: cdf = gamm_cdf(x,a) -% where: x = a vector -% a = a scalar gamma(a) -%--------------------------------------------------- -% RETURNS: -% a vector of cdf at each element of x of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_inv -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg - -if nargin ~= 2 -error('Wrong # of arguments to gamm_cdf'); -end; - -if any(any(a<=0)) - error('gamm_cdf: parameter a is wrong') -end - -cdf = gammainc(x,a); -I0 = find(x<0); -cdf(I0) = zeros(size(I0)); diff --git a/GSA_distrib/4.0.3/gamm_inv.m b/GSA_distrib/4.0.3/gamm_inv.m deleted file mode 100644 index 3bede95ba..000000000 --- a/GSA_distrib/4.0.3/gamm_inv.m +++ /dev/null @@ -1,50 +0,0 @@ -function x = gamm_inv(p,a,b) -% PURPOSE: returns the inverse of the cdf at p of the gamma(a,b) distribution -%--------------------------------------------------- -% USAGE: x = gamm_inv(p,a) -% where: p = a vector of probabilities -% a = a scalar parameter gamma(a) -% b = scaling factor for gamma -%--------------------------------------------------- -% RETURNS: -% a vector x of the quantile at each element of p of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_cdf -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to fit the format -% of the econometrics toolbox - - if (nargin < 2 | isempty(b)) - b=1; - end - - if (nargin > 3) - error('Wrong # of arguments to gamm_inv'); - end - - -if any(any(abs(2*p-1)>1)) - error('gamm_inv: a probability should be 0<=p<=1') -end -if any(any(a<=0)) - error('gamma_inv: parameter a is wrong') -end - -x = max(a-1,0.1); -dx = 1; -while any(any(abs(dx)>256*eps*max(x,1))) - dx = (gamm_cdf(x,a) - p) ./ gamm_pdf(x,a); - x = x - dx; - x = x + (dx - x) / 2 .* (x<0); -end - -I0 = find(p==0); -x(I0) = zeros(size(I0)); -I1 = find(p==1); -x(I1) = zeros(size(I0)) + Inf; - - -x=x.*b; diff --git a/GSA_distrib/4.0.3/gamm_pdf.m b/GSA_distrib/4.0.3/gamm_pdf.m deleted file mode 100644 index 86f4ffb1d..000000000 --- a/GSA_distrib/4.0.3/gamm_pdf.m +++ /dev/null @@ -1,27 +0,0 @@ -function f = gamm_pdf (x, a) -% PURPOSE: returns the pdf at x of the gamma(a) distribution -%--------------------------------------------------- -% USAGE: pdf = gamm_pdf(x,a) -% where: x = a vector -% a = a scalar for gamma(a) -%--------------------------------------------------- -% RETURNS: -% a vector of pdf at each element of x of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_cdf, gamm_rnd, gamm_inv -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg - -if nargin ~= 2 -error('Wrong # of arguments to gamm_cdf'); -end; - -if any(any(a<=0)) - error('gamm_pdf: parameter a is wrong') -end - -f = x .^ (a-1) .* exp(-x) ./ gamma(a); -I0 = find(x<0); -f(I0) = zeros(size(I0)); diff --git a/GSA_distrib/4.0.3/ghx2transition.m b/GSA_distrib/4.0.3/ghx2transition.m deleted file mode 100644 index 2f10a5f3b..000000000 --- a/GSA_distrib/4.0.3/ghx2transition.m +++ /dev/null @@ -1,41 +0,0 @@ -function [A,B] = ghx2transition(mm,iv,ic,aux) -% [A,B] = ghx2transition(mm,iv,ic,aux) -% -% Adapted by M. Ratto from kalman_transition_matrix.m -% (kalman_transition_matrix.m is part of DYNARE, copyright M. Juillard) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ - - [nr1, nc1] = size(mm); - ghx = mm(:, [1:(nc1-M_.exo_nbr)]); - ghu = mm(:, [(nc1-M_.exo_nbr+1):end] ); - n_iv = length(iv); - n_ir1 = size(aux,1); - nr = n_iv + n_ir1; - - A = zeros(nr,nr); - B = zeros(nr,M_.exo_nbr); - - i_n_iv = 1:n_iv; - A(i_n_iv,ic) = ghx(iv,:); - if n_ir1 > 0 - A(n_iv+1:end,:) = sparse(aux(:,1),aux(:,2),ones(n_ir1,1),n_ir1,nr); - end - - B(i_n_iv,:) = ghu(iv,:); diff --git a/GSA_distrib/4.0.3/log_trans_.m b/GSA_distrib/4.0.3/log_trans_.m deleted file mode 100644 index b0ff26ddf..000000000 --- a/GSA_distrib/4.0.3/log_trans_.m +++ /dev/null @@ -1,54 +0,0 @@ -function [yy, xdir, isig, lam]=log_trans_(y0,xdir0) - -if nargin==1, - xdir0=''; -end -f=inline('skewness(log(y+lam))','lam','y'); -isig=1; -if ~(max(y0)<0 | min(y0)>0) - if skewness(y0)<0, - isig=-1; - y0=-y0; - end - n=hist(y0,10); - if n(1)>20*n(end), - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))0 - %yy=log(y0); - xdir=[xdir0,'_log']; - end - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))1.e-10, -% j0=j0+1; -% y1=ones(size(lpmat,1),1)*NaN; -% y1(istable,1)=y0; -% yt(:,j0)=y1; -% end -% end -% end -% yt = yt(:,j0); - -if opt_gsa.morris==1, - %OutputDir = CheckPath('GSA\SCREEN'); - SAMorris = []; - for i=1:size(vdec,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv); - end - SAvdec = squeeze(SAMorris(:,1,:))'; - save([OutputDirectoryName,'\',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') - - figure, -% boxplot(SAvdec,'whis',10,'symbol','r.') - myboxplot(SAvdec,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('All variance decomposition') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_vdec']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_vdec']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_vdec']); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['EET variance decomposition observed variables']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_vdec==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAvdec(iv,:),[],'.',[],3) - else - plot(SAvdec(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_vdec_varobs_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_vdec_varobs_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_vdec_varobs_',int2str(ifig)]); - end - end - - ifig = 0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['EET variance decomposition shocks']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ic_vdec==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAvdec(iv,:),[],'.',[],3) - else - plot(SAvdec(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_vdec_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_vdec_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_vdec_exo_',int2str(ifig)]); - end - end - - - SAMorris = []; - for i=1:size(cc,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], cc(:,i),nliv); - end - SAcc = squeeze(SAMorris(:,1,:))'; - save([OutputDirectoryName,'\',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc','-append') - - figure, -% boxplot(SAcc,'whis',10,'symbol','r.') - myboxplot(SAcc,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('EET All cross-correlation matrix') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_cc']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_cc']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_cc']); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['EET cross-correlations']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_cc==j); - iv = [iv; find(ic_cc==j)]; - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAcc(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAcc(iv,:),[],'.',[],3) - else - plot(SAcc(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_cc_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_cc_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_cc_',int2str(ifig)]); - end - end - - - SAMorris = []; - for i=1:size(ac,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], ac(:,i),nliv); - end - %end - SAac = squeeze(SAMorris(:,1,:))'; - save([OutputDirectoryName,'\',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac','-append') - - figure, -% boxplot(SAac,'whis',10,'symbol','r.') - myboxplot(SAac,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('EET All auto-correlations') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_ac']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_ac']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_ac']); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['EET auto-correlations']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_ac==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAac(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAac(iv,:),[],'.',[],3) - else - plot(SAac(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_ac_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_ac_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_ac_',int2str(ifig)]); - end - end - - js=0; - %for j=1:size(tadj,1), - SAMorris = []; - for i=1:size(tadj,2), - js=js+1; - [SAmeas, SAMorris(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], tadj(:,i),nliv); - end - %end - SAM = squeeze(SAMorris(nshock+1:end,1,:)); - for j=1:js, - SAtadj(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); - end - SAtadj = SAtadj'; - save([OutputDirectoryName,'\',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj','-append') - - js=0; - SAMorris = []; - for i=1:size(iff,2), - js=js+1; - [SAmeas, SAMorriss(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], iff(:,i),nliv); - end - SAM = squeeze(SAMorriss(nshock+1:end,1,:)); - for j=1:js, - SAIF(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); - end - SAIF = SAIF'; - save([OutputDirectoryName,'\',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if','-append') - - figure, - %bar(SAtadj), -% boxplot(SAtadj,'whis',10,'symbol','r.') - myboxplot(SAtadj,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('All half-life') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_tadj']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_tadj']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_tadj']); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['EET speed of adjustment observed variables']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_tadj==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAtadj(iv,:),[],'.',[],3) - else - plot(SAtadj(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_tadj_varobs_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_tadj_varobs_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_tadj_varobs_',int2str(ifig)]); - end - end - - ifig = 0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['EET speed of adjustment shocks']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ic_tadj==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAtadj(iv,:),[],'.',[],3) - else - plot(SAtadj(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_tadj_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_tadj_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_tadj_exo_',int2str(ifig)]); - end - end - - figure, - %bar(SAIF), -% boxplot(SAIF,'whis',10,'symbol','r.') - myboxplot(SAIF,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - ylabel('Elementary Effects') - title('Steady state gains (impact factors)') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_gain']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_gain']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_gain']); - %figure, bar(SAIF'), title('All Gain Relationships') - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['EET steady state gain observed series']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_if==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAIF(iv,:),'whis',10,'symbol','r.'); - myboxplot(SAIF(iv,:),[],'.',[],10) - else - plot(SAIF(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_gain_varobs_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_gain_varobs_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_gain_varobs_',int2str(ifig)]); - end - end - - ifig = 0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['EET steady state gain shocks']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ic_if==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAIF(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAIF(iv,:),[],'.',[],3) - else - plot(SAIF(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_gain_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_gain_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_gain_exo_',int2str(ifig)]); - end - end - - - SAMorris = []; - for j=1:j0, - [SAmeas, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv); - end - - SAM = squeeze(SAMorris(nshock+1:end,1,:)); - for j=1:j0 - SAnorm(:,j)=SAM(:,j)./max(SAM(:,j)); - irex(j)=length(find(SAnorm(:,j)>0.01)); - end - [dum, irel]=sort(irex); - - SAMmu = squeeze(SAMorris(:,2,:)); - for j=1:j0 - SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j)); % normalised w.r.t. mu* - end - SAMsig = squeeze(SAMorris(:,3,:)); - for j=1:j0 - SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j)); - end - - figure, %bar(SAnorm(:,irel)) -% boxplot(SAnorm','whis',10,'symbol','r.') - myboxplot(SAnorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('Elementary effects parameters') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_par']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_par']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_par']); - - figure, %bar(SAmunorm(:,irel)) -% boxplot(SAmunorm','whis',10,'symbol','r.') - myboxplot(SAmunorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - set(gca,'ylim',[-1 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('\mu parameters') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morrismu_par']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morrismu_par']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morrismu_par']); - figure, %bar(SAsignorm(:,irel)) -% boxplot(SAsignorm','whis',10,'symbol','r.') - myboxplot(SAsignorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('\sigma parameters') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_morrissig_par']) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morrissig_par']); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morrissig_par']); - - % figure, bar(SAnorm(:,irel)') - % set(gca,'xtick',[1:j0]) - % set(gca,'xlim',[0.5 j0+0.5]) - % title('Elementary effects relationships') - % saveas(gcf,[OutputDirectoryName,'\',fname_,'_morris_redform']) - % eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_morris_redform']); - % eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_morris_redform']); - -elseif opt_gsa.morris==2, - np=estim_params_.np; - na=(4*np+1)*opt_gsa.Nsam; - for j=1:j0, - [idex(j,:), yd(j,:)] = spop_ide(lpmat, yt(:,j), opt_gsa.Nsam, 5-1); - end - iok=find(~isnan(yt(1:opt_gsa.Nsam,1))); - yr=NaN*ones(size(lpmat,1),j0); - for j=1:j0, - ys(j,:)=yd(j,:)./max(yd(j,:)); - [dum, is]=sort(yt(iok,j)); - yr(iok(is),j)=[1:length(iok)]'./length(iok); - yr(istable(length(iok)+1:end),j) = interp1(yt(iok,j),yr(iok,j),yt(istable(length(iok)+1:end),j),'','extrap'); - ineg=find(yr(:,j)<0); - if any(ineg), - [dum, is]=sort(yr(ineg,j)); - yr(ineg(is),j)=-[length(ineg):-1:1]./length(iok); - - end - [idex_r(j,:), yd_r(j,:)] = spop_ide(lpmat, yr(:,j), opt_gsa.Nsam, 5-1); - ys_r(j,:)=yd_r(j,:)./max(yd_r(j,:)); - - end, - figure, bar((idex.*ys)./opt_gsa.Nsam), title('Relationships') - figure, bar((idex.*ys)'./opt_gsa.Nsam), title('Parameters') - figure, bar((idex_r.*ys_r)./opt_gsa.Nsam), title('Relationships rank') - figure, bar((idex_r.*ys_r)'./opt_gsa.Nsam), title('Parameters rank') - [v0,d0]=eig(corrcoef(yt(iok,:))); - ee=diag(d0); - ee=ee([end:-1:1])./j0; - i0=length(find(ee>0.01)); - v0=v0(:,[end:-1:1]); - for j=1:i0, - [idex_pc(j,:), yd_pc(j,:)] = spop_ide(lpmat, yt*v0(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:i0, - ys_pc(j,:)=yd_pc(j,:)./max(yd_pc(j,:)); - end, - figure, bar((idex_pc.*ys_pc)./opt_gsa.Nsam), title('Relationships PCA') - figure, bar((idex_pc.*ys_pc)'./opt_gsa.Nsam), title('Parameters PCA') - - [vr,dr]=eig(corrcoef(yr(iok,:))); - er=diag(dr); - er=er([end:-1:1])./j0; - ir0=length(find(er>0.01)); - vr=vr(:,[end:-1:1]); - for j=1:ir0, - [idex_pcr(j,:), yd_pcr(j,:)] = spop_ide(lpmat, yr*vr(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:ir0, - ys_pcr(j,:)=yd_pcr(j,:)./max(yd_pcr(j,:)); - end, - figure, bar((idex_pcr.*ys_pcr)./opt_gsa.Nsam), title('Relationships rank PCA') - figure, bar((idex_pcr.*ys_pcr)'./opt_gsa.Nsam), title('Parameters rank PCA') -else, - - if itrans==0, - fsuffix = ''; - elseif itrans==1, - fsuffix = '_log'; - else - fsuffix = '_rank'; - end - - imap=[1:npT]; - - x0=[lpmat0(istable,:), lpmat(istable,:)]; - nrun=length(istable); - nest=min(250,nrun); - nfit=min(1000,nrun); - try - EET=load([OutputDirectoryName,'\SCREEN\',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec'); - catch - EET=[]; - end - - SAvdec=zeros(size(vdec,2),npT); - - for j=1:size(vdec,2), - if itrans==0, - y0 = vdec(istable,j); - elseif itrans==1, - y0 = log_trans_(vdec(istable,j)); - else - y0 = trank(vdec(istable,j)); - end - if ~isempty(EET), -% imap=find(EET.SAvdec(j,:)); -% [dum, isort]=sort(-EET.SAvdec(j,:)); - imap=find(EET.SAvdec(j,:) >= (0.1.*max(EET.SAvdec(j,:))) ); - end - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); - if nfit>nest, - gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... - -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); - end - - SAvdec(j,imap)=gsa_(j).si; - imap_vdec{j}=imap; - end - save([OutputDirectoryName,'\',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec') - - figure, -% boxplot(SAvdec,'whis',10,'symbol','r.') - myboxplot(SAvdec,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Main effects variance decomposition ',fsuffix],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_vdec',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_vdec',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_vdec',fsuffix]); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['Main effects observed variance decomposition ',fsuffix]); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_vdec==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAvdec(iv,:),'whis',10,'symbol','r.'); - myboxplot(SAvdec(iv,:),[],'.',[],10) - else - plot(SAvdec(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_vdec',fsuffix,'_varobs_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); - end - end - - ifig = 0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['Main effects shocks variance decomposition ',fsuffix]); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ic_vdec==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAvdec(iv,:),[],'.',[],10) - else - plot(SAvdec(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',3,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - set(gca,'fontsize',10) - end - title(M_.exo_names(j,:),'interpreter','none','fontsize',10) - if mod(j,6)==0 | j==M_.exo_nbr - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_vdec',fsuffix,'_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); - end - end - - try - EET=load([OutputDirectoryName,'\SCREEN\',fname_,'_morris_IDE'],'SAcc','ir_cc','ic_cc'); - catch - EET=[]; - end - SAcc=zeros(size(cc,2),npT); - for j=1:size(cc,2), - if itrans==0, - y0 = cc(istable,j); - elseif itrans==1, - y0 = log_trans_(cc(istable,j)); - else - y0 = trank(cc(istable,j)); - end - if ~isempty(EET), -% imap=find(EET.SAvdec(j,:)); -% [dum, isort]=sort(-EET.SAvdec(j,:)); - imap=find(EET.SAcc(j,:) >= (0.1.*max(EET.SAcc(j,:))) ); - end - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); - if nfit>nest, - gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... - -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); - end - SAcc(j,imap)=gsa_(j).si; - imap_cc{j}=imap; - - end - save([OutputDirectoryName,'\',fname_,'_main_eff'],'imap_cc','SAcc','cc','ir_cc','ic_cc') - - figure, -% boxplot(SAcc,'whis',10,'symbol','r.') - myboxplot(SAcc,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - ylabel(' ') - title(['Main effects cross-covariances ',fsuffix],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_cc',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_cc',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_cc',fsuffix]); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['Main effects cross-covariances ',fsuffix]); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_cc==j); - iv = [iv; find(ic_cc==j)]; - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAcc(iv,:),'whis',10,'symbol','r.'); - myboxplot(SAcc(iv,:),[],'.',[],10) - else - plot(SAcc(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - set(gca,'fontsize',10) - end - title(options_.varobs(j,:),'interpreter','none','fontsize',10) - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_cc',fsuffix,'_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); - end - end - - try - EET=load([OutputDirectoryName,'\SCREEN\',fname_,'_morris_IDE'],'SAac','ir_ac','ic_ac'); - catch - EET=[]; - end - SAac=zeros(size(ac,2),npT); - for j=1:size(ac,2), - if itrans==0, - y0 = ac(istable,j); - elseif itrans==1, - y0 = log_trans_(ac(istable,j)); - else - y0 = trank(ac(istable,j)); - end - if ~isempty(EET), - imap=find(EET.SAac(j,:) >= (0.1.*max(EET.SAac(j,:))) ); - end -% gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); - if nfit>nest, - gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... - -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); - end - SAac(j,imap)=gsa_(j).si; - imap_ac{j}=imap; - - end - save([OutputDirectoryName,'\',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac') - - figure, -% boxplot(SAac,'whis',10,'symbol','r.') - myboxplot(SAac,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Main effects 1 lag auto-covariances ',fsuffix],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_ac',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_ac',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_ac',fsuffix]); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['Main effects auto-covariances ',fsuffix]); - ifig=ifig+1; - iplo = 0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_ac==j); - %iv = [iv; find(ic_ac==j)]; - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAac(iv,:),'whis',10,'symbol','r.'); - myboxplot(SAac(iv,:),[],'.',[],10) - else - plot(SAac(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - set(gca,'fontsize',10) - end - title(options_.varobs(j,:),'interpreter','none','fontsize',10) - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_ac',fsuffix,'_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); - end - end - - x0=x0(:,nshock+1:end); - imap=[1:np]; - - try - EET=load([OutputDirectoryName,'\SCREEN\',fname_,'_morris_IDE'],'SAtadj','ir_tadj','ic_tadj'); - ny=size(EET.SAtadj,1); - catch - EET=[]; - end - SAtadj=zeros(size(tadj,2),np); - for j=1:size(tadj,2), - if itrans==0, - y0 = tadj(istable,j); - elseif itrans==1, - y0 = log_trans_(tadj(istable,j)); - else - y0 = trank(tadj(istable,j)); - end - if ~isempty(EET), - if size(tadj,2)~=ny, - jj=find(EET.ir_tadj==ir_tadj(j)); - jj=jj(find(EET.ic_tadj(jj)==ic_tadj(j))); - if ~isempty(jj), - imap=find(EET.SAtadj(jj,:) >= (0.1.*max(EET.SAtadj(jj,:))) ); - else - imap=[1:np]; - end - else - imap=find(EET.SAtadj(j,:) >= (0.1.*max(EET.SAtadj(j,:))) ); - end - end -% gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); - if nfit>nest, - gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... - -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); - end - SAtadj(j,imap)=gsa_(j).si; - imap_tadj{j}=imap; - - end - save([OutputDirectoryName,'\',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj') - - figure, -% boxplot(SAtadj,'whis',10,'symbol','r.') - myboxplot(SAtadj,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Main effects speed of adjustment ',fsuffix],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_tadj',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_tadj',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_tadj',fsuffix]); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['Main effects observed speed adjustment ',fsuffix]); - ifig=ifig+1; - iplo = 0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_tadj==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAtadj(iv,:),[],'.',[],10) - else - plot(SAtadj(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_tadj',fsuffix,'_varobs_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); - end - end - - ifig = 0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['Main effects shocks speed of adjustment ',fsuffix]); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ic_tadj==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAtadj(iv,:),[],'.',[],10) - else - plot(SAtadj(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_tadj',fsuffix,'_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); - end - end - - - try - EET=load([OutputDirectoryName,'\SCREEN\',fname_,'_morris_IDE'],'SAIF','ir_if','ic_if'); - catch - EET=[]; - end - SAif=zeros(size(iff,2),np); - for j=1:size(iff,2), - if itrans==0, - y0 = iff(istable,j); - elseif itrans==1, - y0 = log_trans_(iff(istable,j)); - else - y0 = trank(iff(istable,j)); - end - if ~isempty(EET), - imap=find(EET.SAIF(j,:) >= (0.1.*max(EET.SAIF(j,:))) ); - end -% gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); - if nfit>nest, - gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... - -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); - end - SAif(j,imap)=gsa_(j).si; - imap_if{j}=imap; - - end - save([OutputDirectoryName,'\',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if') - - figure, -% boxplot(SAif,'whis',10,'symbol','r.') - myboxplot(SAif,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Main effects impact factors ',fsuffix],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_if',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_if',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_if',fsuffix]); - - ifig = 0; - for j=1:size(options_.varobs,1) - if mod(j,6)==1 - figure('name',['Main effects observed impact factors ',fsuffix]); - ifig=ifig+1; - iplo = 0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ir_if==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAif(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAif(iv,:),[],'.',[],10) - else - plot(SAif(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(options_.varobs(j,:),'interpreter','none') - if mod(j,6)==0 | j==size(options_.varobs,1) - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_if',fsuffix,'_varobs_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); - end - end - - ifig = 0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['Main effects shocks impact factors ',fsuffix]); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(3,2,iplo) - iv = find(ic_if==j); - if ~isempty(iv) - if length(iv)>1 -% boxplot(SAif(iv,:),'whis',3,'symbol','r.'); - myboxplot(SAif(iv,:),[],'.',[],10) - else - plot(SAif(iv,:),'r.'); - end - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) - set(gca,'xlim',[0.5 np+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - end - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr - saveas(gcf,[OutputDirectoryName,'\',fname_,'_map_if',fsuffix,'_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '\' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '\' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); - end - end - -end diff --git a/GSA_distrib/4.0.3/mc_moments.m b/GSA_distrib/4.0.3/mc_moments.m deleted file mode 100644 index 5431a14b5..000000000 --- a/GSA_distrib/4.0.3/mc_moments.m +++ /dev/null @@ -1,21 +0,0 @@ -function [vdec, cc, ac] = mc_moments(mm, ss, dr) -global options_ M_ - - [nr1, nc1, nsam] = size(mm); - disp('Computing theoretical moments ...') - h = waitbar(0,'Theoretical moments ...'); - - for j=1:nsam, - dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j); - dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j); - if ~isempty(ss), - set_shocks_param(ss(j,:)); - end - [vdec(:,:,j), corr, autocorr, z, zz] = th_moments(dr,options_.varobs); - cc(:,:,j)=tril(corr,-1); - ac(:,:,j)=autocorr{1}; - waitbar(j/nsam,h) - end - close(h) - disp(' ') - disp('... done !') diff --git a/GSA_distrib/4.0.3/myboxplot.m b/GSA_distrib/4.0.3/myboxplot.m deleted file mode 100644 index 17f752ff8..000000000 --- a/GSA_distrib/4.0.3/myboxplot.m +++ /dev/null @@ -1,158 +0,0 @@ - -function sout = myboxplot (data,notched,symbol,vertical,maxwhisker) - -% sout = myboxplot (data,notched,symbol,vertical,maxwhisker) - -% % % % endif -if nargin < 5 | isempty(maxwhisker), maxwhisker = 1.5; end -if nargin < 4 | isempty(vertical), vertical = 1; end -if nargin < 3 | isempty(symbol), symbol = ['+','o']; end -if nargin < 2 | isempty(notched), notched = 0; end - -if length(symbol)==1, symbol(2)=symbol(1); end - -if notched==1, notched=0.25; end -a=1-notched; - -% ## figure out how many data sets we have -if iscell(data), - nc = length(data); -else -% if isvector(data), data = data(:); end - nc = size(data,2); -end - -% ## compute statistics -% ## s will contain -% ## 1,5 min and max -% ## 2,3,4 1st, 2nd and 3rd quartile -% ## 6,7 lower and upper confidence intervals for median -s = zeros(7,nc); -box = zeros(1,nc); -whisker_x = ones(2,1)*[1:nc,1:nc]; -whisker_y = zeros(2,2*nc); -outliers_x = []; -outliers_y = []; -outliers2_x = []; -outliers2_y = []; - -for i=1:nc - % ## Get the next data set from the array or cell array - if iscell(data) - col = data{i}(:); - else - col = data(:,i); - end -% ## Skip missing data -% % % % % % % col(isnan(col) | isna (col)) = []; - col(isnan(col)) = []; - - % ## Remember the data length - nd = length(col); - box(i) = nd; - if (nd > 1) -% ## min,max and quartiles -% s(1:5,i) = statistics(col)(1:5); -s(1,i)=min(col); -s(5,i)=max(col); -s(2,i)=myprctilecol(col,25); -s(3,i)=myprctilecol(col,50); -s(4,i)=myprctilecol(col,75); - - - - - - - - -% ## confidence interval for the median - est = 1.57*(s(4,i)-s(2,i))/sqrt(nd); - s(6,i) = max([s(3,i)-est, s(2,i)]); - s(7,i) = min([s(3,i)+est, s(4,i)]); -% ## whiskers out to the last point within the desired inter-quartile range - IQR = maxwhisker*(s(4,i)-s(2,i)); - whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)]; - whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)]; -% ## outliers beyond 1 and 2 inter-quartile ranges - outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR)); - outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR); - outliers_x = [outliers_x; i*ones(size(outliers))]; - outliers_y = [outliers_y; outliers]; - outliers2_x = [outliers2_x; i*ones(size(outliers2))]; - outliers2_y = [outliers2_y; outliers2]; - elseif (nd == 1) -% ## all statistics collapse to the value of the point - s(:,i) = col; -% ## single point data sets are plotted as outliers. - outliers_x = [outliers_x; i]; - outliers_y = [outliers_y; col]; - else -% ## no statistics if no points - s(:,i) = NaN; - end -end -% % % % if isempty(outliers2_y) -% % % % outliers2_y= -% ## Note which boxes don't have enough stats -chop = find(box <= 1); - -% ## Draw a box around the quartiles, with width proportional to the number of -% ## items in the box. Draw notches if desired. -box = box*0.23/max(box); -quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box; -quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:); - -% ## Draw a line through the median -median_x = ones(2,1)*[1:nc] + [-a;+a]*box; -% median_x=median(col); -median_y = s([3,3],:); - -% ## Chop all boxes which don't have enough stats -quartile_x(:,chop) = []; -quartile_y(:,chop) = []; -whisker_x(:,[chop,chop+nc]) = []; -whisker_y(:,[chop,chop+nc]) = []; -median_x(:,chop) = []; -median_y(:,chop) = []; -% % % % -% ## Add caps to the remaining whiskers -cap_x = whisker_x; -cap_x(1,:) =cap_x(1,:)- 0.05; -cap_x(2,:) =cap_x(2,:)+ 0.05; -cap_y = whisker_y([1,1],:); - -% #quartile_x,quartile_y -% #whisker_x,whisker_y -% #median_x,median_y -% #cap_x,cap_y -% -% ## Do the plot - -mm=min(min(data)); -MM=max(max(data)); - -if vertical - plot (quartile_x, quartile_y, 'b', ... - whisker_x, whisker_y, 'b--', ... - cap_x, cap_y, 'k', ... - median_x, median_y, 'r', ... - outliers_x, outliers_y, [symbol(1),'r'], ... - outliers2_x, outliers2_y, [symbol(2),'r']); - set(gca,'XTick',1:nc); - set(gca, 'XLim', [0.5, nc+0.5]); - set(gca, 'YLim', [mm-(MM-mm)*0.05, MM+(MM-mm)*0.05]); - -else -% % % % % plot (quartile_y, quartile_x, "b;;", -% % % % % whisker_y, whisker_x, "b;;", -% % % % % cap_y, cap_x, "b;;", -% % % % % median_y, median_x, "r;;", -% % % % % outliers_y, outliers_x, [symbol(1),"r;;"], -% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]); -end - -if nargout, - sout=s; -end -% % % endfunction \ No newline at end of file diff --git a/GSA_distrib/4.0.3/myprctilecol.m b/GSA_distrib/4.0.3/myprctilecol.m deleted file mode 100644 index d99d5ad50..000000000 --- a/GSA_distrib/4.0.3/myprctilecol.m +++ /dev/null @@ -1,20 +0,0 @@ -function y = myprctilecol(x,p); -xx = sort(x); -[m,n] = size(x); - -if m==1 | n==1 - m = max(m,n); - if m == 1, - y = x*ones(length(p),1); - return; - end - n = 1; - q = 100*(0.5:m - 0.5)./m; - xx = [min(x); xx(:); max(x)]; -else - q = 100*(0.5:m - 0.5)./m; - xx = [min(x); xx; max(x)]; -end - -q = [0 q 100]; -y = interp1(q,xx,p); \ No newline at end of file diff --git a/GSA_distrib/4.0.3/norm_inv.m b/GSA_distrib/4.0.3/norm_inv.m deleted file mode 100644 index fc0f7356d..000000000 --- a/GSA_distrib/4.0.3/norm_inv.m +++ /dev/null @@ -1,44 +0,0 @@ -function invp = norm_inv(x, m, sd) -% PURPOSE: computes the quantile (inverse of the CDF) -% for each component of x with mean m, standard deviation sd -%--------------------------------------------------- -% USAGE: invp = norm_inv(x,m,v) -% where: x = variable vector (nx1) -% m = mean vector (default=0) -% sd = standard deviation vector (default=1) -%--------------------------------------------------- -% RETURNS: invp (nx1) vector -%--------------------------------------------------- -% SEE ALSO: norm_d, norm_rnd, norm_inv, norm_cdf -%--------------------------------------------------- - -% Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Oct 26, 1994 -% Copyright Dept of Probability Theory and Statistics TU Wien -% Converted to MATLAB by JP LeSage, jpl@jpl.econ.utoledo.edu - - if nargin > 3 - error ('Wrong # of arguments to norm_inv'); - end - - [r, c] = size (x); - s = r * c; - - if (nargin == 1) - m = zeros(1,s); - sd = ones(1,s); - end - - - - x = reshape(x,1,s); - m = reshape(m,1,s); - sd = reshape(sd,1,s); - - invp = zeros (1,s); - - invp = m + sd .* (sqrt(2) * erfinv(2 * x - 1)); - - - - invp = reshape (invp, r, c); - diff --git a/GSA_distrib/4.0.3/prior_draw_gsa.m b/GSA_distrib/4.0.3/prior_draw_gsa.m deleted file mode 100644 index 7000a6dc0..000000000 --- a/GSA_distrib/4.0.3/prior_draw_gsa.m +++ /dev/null @@ -1,125 +0,0 @@ -function pdraw = prior_draw_gsa(init,rdraw,cc) -% Draws from the prior distributions -% Adapted by M. Ratto from prior_draw (of DYNARE, copyright M. Juillard), -% for use with Sensitivity Toolbox for DYNARE -% -% -% INPUTS -% o init [integer] scalar equal to 1 (first call) or 0. -% o rdraw -% o cc [double] two columns matrix (same as in -% metropolis.m), constraints over the -% parameter space (upper and lower bounds). -% -% OUTPUTS -% o pdraw [double] draw from the joint prior density. -% -% ALGORITHM -% ... -% -% SPECIAL REQUIREMENTS -% MATLAB Statistics Toolbox -% -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ options_ estim_params_ bayestopt_ -persistent fname npar bounds pshape pmean pstd a b p1 p2 p3 p4 condition - -if init - nvx = estim_params_.nvx; - nvn = estim_params_.nvn; - ncx = estim_params_.ncx; - ncn = estim_params_.ncn; - np = estim_params_.np ; - npar = nvx+nvn+ncx+ncn+np; - MhDirectoryName = CheckPath('metropolis'); - fname = [ MhDirectoryName '/' M_.fname]; - pshape = bayestopt_.pshape; - pmean = bayestopt_.pmean; - pstd = bayestopt_.pstdev; - p1 = bayestopt_.p1; - p2 = bayestopt_.p2; - p3 = bayestopt_.p3; - p4 = bayestopt_.p4; - a = zeros(npar,1); - b = zeros(npar,1); - if nargin == 2 - bounds = cc; - else - bounds = kron(ones(npar,1),[-Inf Inf]); - end - for i = 1:npar - switch pshape(i) - case 3% Gaussian prior - b(i) = pstd(i)^2/(pmean(i)-p3(i)); - a(i) = (pmean(i)-p3(i))/b(i); - case 1% Beta prior - mu = (p1(i)-p3(i))/(p4(i)-p3(i)); - stdd = p2(i)/(p4(i)-p3(i)); - a(i) = (1-mu)*mu^2/stdd^2 - mu; - b(i) = a(i)*(1/mu - 1); - case 2;%Gamma prior - mu = p1(i)-p3(i); - b(i) = p2(i)^2/mu; - a(i) = mu/b(i); - case {5,4,6} - % Nothing to do here - % - % 4: Inverse gamma, type 1, prior - % p2(i) = nu - % p1(i) = s - % 6: Inverse gamma, type 2, prior - % p2(i) = nu - % p1(i) = s - % 5: Uniform prior - % p3(i) and p4(i) are used. - otherwise - disp('prior_draw :: Error!') - disp('Unknown prior shape.') - return - end - pdraw = zeros(npar,1); - end - condition = 1; - pdraw = zeros(npar,1); - return -end - - -for i = 1:npar - switch pshape(i) - case 5% Uniform prior. - pdraw(:,i) = rdraw(:,i)*(p4(i)-p3(i)) + p3(i); - case 3% Gaussian prior. - pdraw(:,i) = norm_inv(rdraw(:,i),pmean(i),pstd(i)); - case 2% Gamma prior. - pdraw(:,i) = gamm_inv(rdraw(:,i),a(i),b(i))+p3(i); - case 1% Beta distribution (TODO: generalized beta distribution) - pdraw(:,i) = beta_inv(rdraw(:,i),a(i),b(i))*(p4(i)-p3(i))+p3(i); - case 4% INV-GAMMA1 distribution - % TO BE CHECKED - pdraw(:,i) = sqrt(1./gamm_inv(rdraw(:,i),p2(i)/2,2/p1(i))); - case 6% INV-GAMMA2 distribution - % TO BE CHECKED - pdraw(:,i) = 1./gamm_inv(rdraw(:,i),p2(i)/2,2/p1(i)); - otherwise - % Nothing to do here. - end -end - - diff --git a/GSA_distrib/4.0.3/priorcdf.m b/GSA_distrib/4.0.3/priorcdf.m deleted file mode 100644 index 06151ccfe..000000000 --- a/GSA_distrib/4.0.3/priorcdf.m +++ /dev/null @@ -1,45 +0,0 @@ -function [xcum] = priorcdf(para, pshape, p1, p2, p3, p4) -% This procedure transforms x vectors into cumulative values -% pshape: 0 is point mass, both para and p2 are ignored -% 1 is BETA(mean,stdd) -% 2 is GAMMA(mean,stdd) -% 3 is NORMAL(mean,stdd) -% 4 is INVGAMMA(s^2,nu) -% 5 is UNIFORM [p1,p2] -% Adapted by M. Ratto from MJ priordens.m - -nprio = length(pshape); - -i = 1; -while i <= nprio; - a = 0; - b = 0; - if pshape(i) == 1; % (generalized) BETA Prior - mu = (p1(i)-p3(i))/(p4(i)-p3(i)); - stdd = p2(i)/(p4(i)-p3(i)); - a = (1-mu)*mu^2/stdd^2 - mu; - b = a*(1/mu - 1); - %lnprior = lnprior + lpdfgbeta(para(i),a,b,p3(i),p4(i)) ; - para(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i)); - xcum(:,i) = betacdf(para(:,i),a,b) ; - elseif pshape(i) == 2; % GAMMA PRIOR - b = p2(i)^2/(p1(i)-p3(i)); - a = (p1(i)-p3(i))/b; - %lnprior = lnprior + lpdfgam(para(i)-p3(i),a,b); - xcum(:,i) = gamcdf(para(:,i)-p3(i),a,b); - elseif pshape(i) == 3; % GAUSSIAN PRIOR - %lnprior = lnprior + lpdfnorm(para(i),p1(i),p2(i)); - xcum(:,i) = normcdf(para(:,i),p1(i),p2(i)); - elseif pshape(i) == 4; % INVGAMMA1 PRIOR - %lnprior = lnprior + lpdfig1(para(i),p1(i),p2(i)); - xcum(:,i) = gamcdf(1/para(:,i).^2,p2(i)/2,2/p1(i)); - elseif pshape(i) == 5; % UNIFORM PRIOR - %lnprior = lnprior + log(1/(p2(i)-p1(i))); - xcum(:,i) = (para(:,i)-p1(i))./(p2(i)-p1(i)); - elseif pshape(i) == 6; % INVGAMMA2 PRIOR -% lnprior = lnprior + lpdfig2(para(i),p1(i),p2(i)); - xcum(:,i) = gamcdf(1/para(:,i),p2(i)/2,2/p1(i)); - end; - i = i+1; -end; - diff --git a/GSA_distrib/4.0.3/read_data.m b/GSA_distrib/4.0.3/read_data.m deleted file mode 100644 index f54f66cb6..000000000 --- a/GSA_distrib/4.0.3/read_data.m +++ /dev/null @@ -1,39 +0,0 @@ -function [gend, data] = read_data -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global options_ bayestopt_ - -rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); - -options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1); -gend = options_.nobs; - -rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); -if options_.loglinear == 1 & ~options_.logdata - rawdata = log(rawdata); -end -if options_.prefilter == 1 - bayestopt_.mean_varobs = mean(rawdata,1); - data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs); -else - data = transpose(rawdata); -end - -if ~isreal(rawdata) - error(['There are complex values in the data. Probably a wrong' ... - ' transformation']) -end diff --git a/GSA_distrib/4.0.3/redform_map.m b/GSA_distrib/4.0.3/redform_map.m deleted file mode 100644 index c5022a19c..000000000 --- a/GSA_distrib/4.0.3/redform_map.m +++ /dev/null @@ -1,342 +0,0 @@ -function redform_map(dirname) -%function redform_map(dirname) -% inputs (from opt_gsa structure -% anamendo = options_gsa_.namendo; -% anamlagendo = options_gsa_.namlagendo; -% anamexo = options_gsa_.namexo; -% iload = options_gsa_.load_redform; -% pprior = options_gsa_.pprior; -% ilog = options_gsa_.logtrans_redform; -% threshold = options_gsa_.threshold_redform; -% ksstat = options_gsa_.ksstat_redform; -% alpha2 = options_gsa_.alpha2_redform; -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ oo_ estim_params_ options_ bayestopt_ - -options_gsa_ = options_.opt_gsa; - -anamendo = options_gsa_.namendo; -anamlagendo = options_gsa_.namlagendo; -anamexo = options_gsa_.namexo; -iload = options_gsa_.load_redform; -pprior = options_gsa_.pprior; -ilog = options_gsa_.logtrans_redform; -threshold = options_gsa_.threshold_redform; -ksstat = options_gsa_.ksstat_redform; -alpha2 = options_gsa_.alpha2_redform; - -pnames = M_.param_names(estim_params_.param_vals(:,1),:); -if nargin==0, - dirname=''; -end - -if pprior - load([dirname,'\',M_.fname,'_prior']); - adir=[dirname '\redform_stab']; -else - load([dirname,'\',M_.fname,'_mc']); - adir=[dirname '\redform_mc']; -end -if ~exist('T') - stab_map_(dirname); -if pprior - load([dirname,'\',M_.fname,'_prior'],'T'); -else - load([dirname,'\',M_.fname,'_mc'],'T'); -end -end -if isempty(dir(adir)) - mkdir(adir) -end -adir0=pwd; -%cd(adir) - -nspred=size(T,2)-M_.exo_nbr; -x0=lpmat(istable,:); -[kn, np]=size(x0); -offset = length(bayestopt_.pshape)-np; -if options_gsa_.prior_range, - pshape=5*(ones(np,1)); - pd = [NaN(np,1) NaN(np,1) bayestopt_.lb(offset+1:end) bayestopt_.ub(offset+1:end)]; -else - pshape = bayestopt_.pshape(offset+1:end); - pd = [bayestopt_.p1(offset+1:end) bayestopt_.p2(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)]; -end - -nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:))); -clear lpmat lpmat0 egg iunstable yys -js=0; -for j=1:size(anamendo,1) - namendo=deblank(anamendo(j,:)); - iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact'); - ifig=0; - iplo=0; - for jx=1:size(anamexo,1) - namexo=deblank(anamexo(jx,:)); - iexo=strmatch(namexo,M_.exo_names,'exact'); - - if ~isempty(iexo), - %y0=squeeze(T(iendo,iexo+nspred,istable)); - y0=squeeze(T(iendo,iexo+nspred,:)); - if (max(y0)-min(y0))>1.e-10, - if mod(iplo,9)==0, - ifig=ifig+1; - figure('name',[namendo,' vs. shocks ',int2str(ifig)]), - iplo=0; - end - iplo=iplo+1; - js=js+1; - xdir0 = [adir,'\',namendo,'_vs_', namexo]; - if ilog==0, - if isempty(threshold) - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namexo, xdir0); - else - iy=find( (y0>threshold(1)) & (y0=threshold(2))); - xdir = [xdir0,'_cut']; - if ~isempty(iy), - si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir); - end - if ~isempty(iy) & ~isempty(iyc) - delete([xdir, '\*cut*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0); - indsmirnov = find(dproba>ksstat); - stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir); - stab_map_2(x0(iy,:),alpha2,'cut',xdir) - stab_map_2(x0(iyc,:),alpha2,'trim',xdir) - end - end - else - [yy, xdir] = log_trans_(y0,xdir0); - silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namexo, xdir); - end - - subplot(3,3,iplo), - if ilog, - [saso, iso] = sort(-silog(:,js)); - bar([silog(iso(1:min(np,10)),js)]) - logflag='log'; - else - [saso, iso] = sort(-si(:,js)); - bar(si(iso(1:min(np,10)),js)) - logflag=''; - end - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([logflag,' ',namendo,' vs. ',namexo],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - close(gcf) - end - - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - close(gcf) - end - ifig=0; - iplo=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - %y0=squeeze(T(iendo,ilagendo,istable)); - y0=squeeze(T(iendo,ilagendo,:)); - if (max(y0)-min(y0))>1.e-10, - if mod(iplo,9)==0, - ifig=ifig+1; - figure('name',[namendo,' vs. lags ',int2str(ifig)]), - iplo=0; - end - iplo=iplo+1; - js=js+1; - xdir0 = [adir,'\',namendo,'_vs_', namlagendo]; - if ilog==0, - if isempty(threshold) - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namlagendo, xdir0); - else - iy=find( (y0>threshold(1)) & (y0=threshold(2))); - xdir = [xdir0,'_cut']; - if ~isempty(iy) - si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir); - end - if ~isempty(iy) & ~isempty(iyc), - delete([xdir, '\*cut*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0); - indsmirnov = find(dproba>ksstat); - stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir); - stab_map_2(x0(iy,:),alpha2,'cut',xdir) - stab_map_2(x0(iyc,:),alpha2,'trim',xdir) - end - end - else - [yy, xdir] = log_trans_(y0,xdir0); - silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namlagendo, xdir); - end - - subplot(3,3,iplo), - if ilog, - [saso, iso] = sort(-silog(:,js)); - bar([silog(iso(1:min(np,10)),js)]) - logflag='log'; - else - [saso, iso] = sort(-si(:,js)); - bar(si(iso(1:min(np,10)),js)) - logflag=''; - end - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([logflag,' ',namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - close(gcf) - end - - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - close(gcf) - end -end - -if ilog==0, -figure, %bar(si) -% boxplot(si','whis',10,'symbol','r.') -myboxplot(si',[],'.',[],10) -xlabel(' ') -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -title('Reduced form GSA') - -saveas(gcf,[dirname,'\',M_.fname,'_redform_gsa']) -eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_gsa']); -eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_gsa']); - -else -figure, %bar(silog) -% boxplot(silog','whis',10,'symbol','r.') -myboxplot(silog',[],'.',[],10) -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -xlabel(' ') -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -title('Reduced form GSA - Log-transformed elements') - -saveas(gcf,[dirname,'\',M_.fname,'_redform_gsa_log']) -eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_gsa_log']); -eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_gsa_log']); - -end -function si = redform_private(x0, y0, pshape, pd, iload, pnames, namy, namx, xdir) -global bayestopt_ options_ - -opt_gsa=options_.opt_gsa; -np=size(x0,2); - if opt_gsa.prior_range, - for j=1:np, - x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3)); - end - else - x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4)); - end - -fname=[xdir,'\map']; -if iload==0, - figure, hist(y0,30), title([namy,' vs. ', namx]) - if isempty(dir(xdir)) - mkdir(xdir) - end - saveas(gcf,[xdir,'\', namy,'_vs_', namx]) - eval(['print -depsc2 ' xdir,'\', namy,'_vs_', namx]); - eval(['print -dpdf ' xdir,'\', namy,'_vs_', namx]); - close(gcf) -% gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames); - nrun=length(y0); - nest=min(250,nrun); - nfit=min(1000,nrun); - gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[],[],0,[fname,'_est'], pnames); - if nfit>nest, - gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[],[],1,fname, pnames); - else - copyfile([fname,'_est.mat'],[fname,'.mat']) - end - figure, - plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'), - title([namy,' vs. ', namx,' fit']) - saveas(gcf,[xdir,'\', namy,'_vs_', namx,'_fit']) - eval(['print -depsc2 ' xdir,'\', namy,'_vs_', namx,'_fit']); - eval(['print -dpdf ' xdir,'\', namy,'_vs_', namx,'_fit']); - close(gcf) - if nfit0 & ifig, - saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]); - close(gcf) - end - - iplo=0; - ifig=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - y0=teff(T(iendo,ilagendo,:),kn,istable); - if ~isempty(y0), - if mod(iplo,9)==0, - ifig=ifig+1; - figure('name',[namendo,' vs. lagged endogenous ',int2str(ifig)]), - iplo=0; - end - iplo=iplo+1; - js=js+1; - subplot(3,3,iplo), - [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); - SAM = squeeze(SAMorris(nshock+1:end,1)); - SA(:,js)=SAM./(max(SAM)+eps); - [saso, iso] = sort(-SA(:,js)); - bar(SA(iso(1:min(np,10)),js)) - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - - title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - close(gcf) - end - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'\',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - close(gcf) - end -end - -figure, -%bar(SA) -% boxplot(SA','whis',10,'symbol','r.') -myboxplot(SA',[],'.',[],10) -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -xlabel(' ') -ylabel('Elementary Effects') -title('Reduced form screening') - -saveas(gcf,[dirname,'\',M_.fname,'_redform_screen']) -eval(['print -depsc2 ' dirname,'\',M_.fname,'_redform_screen']); -eval(['print -dpdf ' dirname,'\',M_.fname,'_redform_screen']); - diff --git a/GSA_distrib/4.0.3/set_shocks_param.m b/GSA_distrib/4.0.3/set_shocks_param.m deleted file mode 100644 index f84247d29..000000000 --- a/GSA_distrib/4.0.3/set_shocks_param.m +++ /dev/null @@ -1,30 +0,0 @@ -function set_shocks_param(xparam1) - global estim_params_ M_ - - nvx = estim_params_.nvx; - ncx = estim_params_.ncx; - np = estim_params_.np; - Sigma_e = M_.Sigma_e; - offset = 0; - if nvx - offset = offset + nvx; - var_exo = estim_params_.var_exo; - for i=1:nvx - k = var_exo(i,1); - Sigma_e(k,k) = xparam1(i)^2; - end - end - - if ncx - offset = offset + estim_params_.nvn; - corrx = estim_params_.corrx; - for i=1:ncx - k1 = corrx(i,1); - k2 = corrx(i,2); - Sigma_e(k1,k2) = xparam1(i+offset)*sqrt(Sigma_e_(k1,k1)*Sigma_e_(k2,k2)); - Sigma_e(k2,k1) = Sigma_e_(k1,k2); - end - end - - - M_.Sigma_e = Sigma_e; \ No newline at end of file diff --git a/GSA_distrib/4.0.3/skewness.m b/GSA_distrib/4.0.3/skewness.m deleted file mode 100644 index 19ce487ab..000000000 --- a/GSA_distrib/4.0.3/skewness.m +++ /dev/null @@ -1,7 +0,0 @@ -function s=skewness(y), - -% y=stand_(y); -% s=mean(y.^3); - m2=mean((y-mean(y)).^2); - m3=mean((y-mean(y)).^3); - s=m3/m2^1.5; \ No newline at end of file diff --git a/GSA_distrib/4.0.3/smirnov.m b/GSA_distrib/4.0.3/smirnov.m deleted file mode 100644 index bc068aeb1..000000000 --- a/GSA_distrib/4.0.3/smirnov.m +++ /dev/null @@ -1,73 +0,0 @@ -function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag ) -% Smirnov test for 2 distributions -% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag ) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - - - -if nargin<3 - alpha = 0.05; -end -if nargin<4, - iflag=0; -end - -% empirical cdfs. -xmix= [x1;x2]; -bin = [-inf ; sort(xmix) ; inf]; - -ncount1 = histc (x1 , bin); -ncount1 = ncount1(:); -ncount2 = histc (x2 , bin); -ncount2 = ncount2(:); - -cum1 = cumsum(ncount1)./sum(ncount1); -cum1 = cum1(1:end-1); - -cum2 = cumsum(ncount2)./sum(ncount2); -cum2 = cum2(1:end-1); - -n1= length(x1); -n2= length(x2); -n = n1*n2 /(n1+n2); - -% Compute the d(n1,n2) statistics. - -if iflag==0, - d = max(abs(cum1 - cum2)); -elseif iflag==-1 - d = max(cum2 - cum1); -elseif iflag==1 - d = max(cum1 - cum2); -end -% -% Compute P-value check H0 hypothesis -% - -lam = max((sqrt(n) + 0.12 + 0.11/sqrt(n)) * d , 0); -if iflag == 0 - j = [1:101]'; - prob = 2 * sum((-1).^(j-1).*exp(-2*lam*lam*j.^2)); - - prob=max(prob,0); - prob=min(1,prob); -else - prob = exp(-2*lam*lam); -end - -H = (alpha >= prob); diff --git a/GSA_distrib/4.0.3/speed.m b/GSA_distrib/4.0.3/speed.m deleted file mode 100644 index faaa1de86..000000000 --- a/GSA_distrib/4.0.3/speed.m +++ /dev/null @@ -1,52 +0,0 @@ -function [tadj, iff] = speed(A,B,mf,p), -% [tadj, iff] = speed(A,B,mf,p), -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -nvar=length(mf); -nstate= size(A,1); -nshock = size(B,2); -nrun=size(B,3); - -iff=zeros(nvar,nshock,nrun); -tadj=iff; -disp('Computing speed of adjustement ...') -h = waitbar(0,'Speed of adjustement...'); - -for i=1:nrun, - irf=zeros(nvar,nshock); - a=squeeze(A(:,:,i)); - b=squeeze(B(:,:,i)); - IFF=inv(eye(nstate)-a)*b; - iff(:,:,i)=IFF(mf,:); - IF=IFF-b; - - t=0; - while any(any(irf<0.5)) - t=t+1; - IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b; - irf=IFT(mf,:)./(IF(mf,:)+eps); - irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7); - %irf=ft(mf,:); - tt=(irf>0.5).*t; - tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i); - end - waitbar(i/nrun,h) -end -disp(' ') -disp('.. done !') -close(h) diff --git a/GSA_distrib/4.0.3/stab_map_.m b/GSA_distrib/4.0.3/stab_map_.m deleted file mode 100644 index 7bfa4cb15..000000000 --- a/GSA_distrib/4.0.3/stab_map_.m +++ /dev/null @@ -1,511 +0,0 @@ -function x0 = stab_map_(OutputDirectoryName) -% -% function x0 = stab_map_(OutputDirectoryName) -% -% Mapping of stability regions in the prior ranges applying -% Monte Carlo filtering techniques. -% -% INPUTS (from opt_gsa structure) -% Nsam = MC sample size -% fload = 0 to run new MC; 1 to load prevoiusly generated analysis -% alpha2 = significance level for bivariate sensitivity analysis -% [abs(corrcoef) > alpha2] -% prepSA = 1: save transition matrices for mapping reduced form -% = 0: no transition matrix saved (default) -% pprior = 1: sample from prior ranges (default): sample saved in -% _prior.mat file -% = 0: sample from posterior ranges: sample saved in -% _mc.mat file -% OUTPUT: -% x0: one parameter vector for which the model is stable. -% -% GRAPHS -% 1) Pdf's of marginal distributions under the stability (dotted -% lines) and unstability (solid lines) regions -% 2) Cumulative distributions of: -% - stable subset (dotted lines) -% - unacceptable subset (solid lines) -% 3) Bivariate plots of significant correlation patterns -% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets -% -% USES lptauSEQ, -% stab_map_1, stab_map_2 -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -%global bayestopt_ estim_params_ dr_ options_ ys_ fname_ -global bayestopt_ estim_params_ options_ oo_ M_ - -opt_gsa=options_.opt_gsa; - -Nsam = opt_gsa.Nsam; -fload = opt_gsa.load_stab; -ksstat = opt_gsa.ksstat; -alpha2 = opt_gsa.alpha2_stab; -prepSA = (opt_gsa.redform | opt_gsa.identification); -pprior = opt_gsa.pprior; -ilptau = opt_gsa.ilptau; -nliv = opt_gsa.morris_nliv; -ntra = opt_gsa.morris_ntra; - -dr_ = oo_.dr; -%if isfield(dr_,'ghx'), - ys_ = oo_.dr.ys; - nspred = dr_.nspred; %size(dr_.ghx,2); - nboth = dr_.nboth; - nfwrd = dr_.nfwrd; -%end -fname_ = M_.fname; - -np = estim_params_.np; -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; -lpmat0=[]; - -pshape = bayestopt_.pshape(nshock+1:end); -p1 = bayestopt_.p1(nshock+1:end); -p2 = bayestopt_.p2(nshock+1:end); -p3 = bayestopt_.p3(nshock+1:end); -p4 = bayestopt_.p4(nshock+1:end); - -if nargin==0, - OutputDirectoryName=''; -end - -opt=options_; - options_.periods=0; - options_.nomoments=1; - options_.irf=0; - options_.noprint=1; - options_.simul=0; -if fload==0, -% if prepSA -% T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam/2); -% end - - if isfield(dr_,'ghx'), - egg=zeros(length(dr_.eigval),Nsam); - end - yys=zeros(length(dr_.ys),Nsam); - - if opt_gsa.morris - if opt_gsa.morris == 1 - [lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []); - lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2; - Nsam=size(lpmat,1); - lpmat0 = lpmat(:,1:nshock); - lpmat = lpmat(:,nshock+1:end); - elseif opt_gsa.morris==2 - lpmat = prep_ide(Nsam,np,5); - Nsam=size(lpmat,1); - end - else - if np<52 & ilptau>0, - [lpmat] = lptauSEQ(Nsam,np); % lptau - if np>30 | ilptau==2, % scrambled lptau - for j=1:np, - lpmat(:,j)=lpmat(randperm(Nsam),j); - end - end - else ilptau==0 - %[lpmat] = rand(Nsam,np); - for j=1:np, - lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - end - - end - end - try - dummy=prior_draw_gsa(1); - catch - if pprior, - if opt_gsa.prior_range==0; - error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!'); - end - end - - end - if pprior, - for j=1:nshock, - if opt_gsa.morris~=1, - lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - end - if opt_gsa.prior_range - lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j); - end - end - if opt_gsa.prior_range - for j=1:np, - lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock); - end - else - xx=prior_draw_gsa(0,[lpmat0 lpmat]); - lpmat0=xx(:,1:nshock); - lpmat=xx(:,nshock+1:end); - clear xx; - end - else - % for j=1:nshock, - % xparam1(j) = oo_.posterior_mode.shocks_std.(bayestopt_.name{j}); - % sd(j) = oo_.posterior_std.shocks_std.(bayestopt_.name{j}); - % lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - % lb = max(bayestopt_.lb(j), xparam1(j)-2*sd(j)); - % ub1=xparam1(j)+(xparam1(j) - lb); % define symmetric range around the mode! - % ub = min(bayestopt_.ub(j),ub1); - % if ub30 & np<52 - % lpmat(:,j) = lpmat(randperm(Nsam),j).*(ub-lb)+lb; - % else - % lpmat(:,j) = lpmat(:,j).*(ub-lb)+lb; - % end - % end - %load([fname_,'_mode']) - eval(['load ' options_.mode_file ';']'); - d = chol(inv(hh)); - lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1'); - for j=1:Nsam*2, - lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub); - end - ireal=[1:2*Nsam]; - ireal=ireal(find(lnprior==0)); - lp=lp(ireal,:); - Nsam=min(Nsam, length(ireal)); - lpmat0=lp(1:Nsam,1:nshock); - lpmat=lp(1:Nsam,nshock+1:end); - clear lp lnprior ireal; - end - % - h = waitbar(0,'Please wait...'); - istable=[1:Nsam]; - jstab=0; - iunstable=[1:Nsam]; - iindeterm=zeros(1,Nsam); - iwrong=zeros(1,Nsam); - for j=1:Nsam, - M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)'; - %try stoch_simul([]); - try - [Tt,Rr,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,... - bayestopt_.restrict_columns,... - bayestopt_.restrict_aux); - - if ~exist('T') - T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam); - end - catch - if isfield(oo_.dr,'eigval'), - oo_.dr=rmfield(oo_.dr,'eigval'); - end - if isfield(oo_.dr,'ghx'), - oo_.dr=rmfield(oo_.dr,'ghx'); - end - disp('No solution could be found'), - end - dr_ = oo_.dr; - if isfield(dr_,'ghx'), - egg(:,j) = sort(dr_.eigval); - iunstable(j)=0; - if prepSA - jstab=jstab+1; - T(:,:,jstab) = [dr_.ghx dr_.ghu]; - [A,B] = ghx2transition(squeeze(T(:,:,jstab)), ... - bayestopt_.restrict_var_list, ... - bayestopt_.restrict_columns, ... - bayestopt_.restrict_aux); - end - if ~exist('nspred'), - nspred = dr_.nspred; %size(dr_.ghx,2); - nboth = dr_.nboth; - nfwrd = dr_.nfwrd; - end - else - istable(j)=0; - if isfield(dr_,'eigval') - egg(:,j) = sort(dr_.eigval); - if exist('nspred') - if any(isnan(egg(1:nspred,j))) - iwrong(j)=j; - else - if (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium, - iindeterm(j)=j; - end - end - end - else - if exist('egg'), - egg(:,j)=ones(size(egg,1),1).*NaN; - end - iwrong(j)=j; - end - end - ys_=real(dr_.ys); - yys(:,j) = ys_; - ys_=yys(:,1); - waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)]) - end - close(h) - if prepSA, - T=T(:,:,1:jstab); - end - istable=istable(find(istable)); % stable params - iunstable=iunstable(find(iunstable)); % unstable params - iindeterm=iindeterm(find(iindeterm)); % indeterminacy - iwrong=iwrong(find(iwrong)); % dynare could not find solution - - % % map stable samples - % istable=[1:Nsam]; - % for j=1:Nsam, - % if any(isnan(egg(1:nspred,j))) - % istable(j)=0; - % else - % if abs(egg(nspred,j))>=options_.qz_criterium; %(1-(options_.qz_criterium-1)); %1-1.e-5; - % istable(j)=0; - % %elseif (dr_.nboth | dr_.nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5; - % elseif (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5; - % istable(j)=0; - % end - % end - % end - % istable=istable(find(istable)); % stable params - % - % % map unstable samples - % iunstable=[1:Nsam]; - % for j=1:Nsam, - % %if abs(egg(dr_.npred+1,j))>1+1.e-5 & abs(egg(dr_.npred,j))<1-1.e-5; - % %if (dr_.nboth | dr_.nfwrd), - % if ~any(isnan(egg(1:5,j))) - % if (nboth | nfwrd), - % if abs(egg(nspred+1,j))>options_.qz_criterium & abs(egg(nspred,j))0 & length(iunstable)ksstat); - disp('Smirnov statistics in driving acceptable behaviour') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indstab) - stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName); - end - ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong]))); - if ~isempty(iindeterm), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'],0); - indindet=find(dproba>ksstat); - disp('Smirnov statistics in driving indeterminacy') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indindet) - stab_map_1(lpmat, istable, iindeterm, [aname, '_indet'], 1, indindet, OutputDirectoryName); - end - end - - if ~isempty(ixun), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'],0); - indunst=find(dproba>ksstat); - disp('Smirnov statistics in driving instability') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indunst) - stab_map_1(lpmat, istable, ixun, [aname, '_unst'], 1, indunst, OutputDirectoryName); - end - end - - disp(' ') - disp('Starting bivariate analysis:') - - c0=corrcoef(lpmat(istable,:)); - c00=tril(c0,-1); - - stab_map_2(lpmat(istable,:),alpha2, asname, OutputDirectoryName); - if length(iunstable)>3, - stab_map_2(lpmat(iunstable,:),alpha2, auname, OutputDirectoryName); - end - if length(iindeterm)>3, - stab_map_2(lpmat(iindeterm,:),alpha2, aindname, OutputDirectoryName); - end - if length(ixun)>3, - stab_map_2(lpmat(ixun,:),alpha2, aunstname, OutputDirectoryName); - end - - x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock); - x0 = [x0; lpmat(istable(1),:)']; - if istable(end)~=Nsam - M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)'; - [oo_.dr, info] = resol(oo_.steady_state,0); -% stoch_simul([]); - end -else - if length(iunstable)==0, - disp('All parameter values in the specified ranges are stable!') - x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock); - x0 = [x0; lpmat(istable(1),:)']; - else - disp('All parameter values in the specified ranges are not acceptable!') - x0=[]; - end - -end - - -options_.periods=opt.periods; -if isfield(opt,'nomoments'), - options_.nomoments=opt.nomoments; -end -options_.irf=opt.irf; -options_.noprint=opt.noprint; -if isfield(opt,'simul'), - options_.simul=opt.simul; -end - - - diff --git a/GSA_distrib/4.0.3/stab_map_1.m b/GSA_distrib/4.0.3/stab_map_1.m deleted file mode 100644 index 17aeaa794..000000000 --- a/GSA_distrib/4.0.3/stab_map_1.m +++ /dev/null @@ -1,87 +0,0 @@ -function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname) -%function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname) -% -% lpmat = Monte Carlo matrix -% ibehaviour = index of behavioural runs -% inonbehaviour = index of non-behavioural runs -% aname = label of the analysis -% iplot = 1 plot cumulative distributions (default) -% iplot = 0 no plots -% ipar = index array of parameters to plot -% dirname = (OPTIONAL) path of the directory where to save -% (default: current directory) -% -% Plots: dotted lines for BEHAVIOURAL -% solid lines for NON BEHAVIOURAL -% USES smirnov -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global estim_params_ bayestopt_ M_ options_ - -if nargin<5, - iplot=1; -end -fname_ = M_.fname; -if nargin<7, - dirname='';; -end - -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; - -npar=size(lpmat,2); -ishock= npar>estim_params_.np; - -if nargin<6 | isempty(ipar), - ipar=[1:npar]; -end -nparplot=length(ipar); - -% Smirnov test for Blanchard; -for j=1:npar, - [H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j)); - proba(j)=P; - dproba(j)=KSSTAT; -end -if iplot - lpmat=lpmat(:,ipar); - ftit=bayestopt_.name(ipar+nshock*(1-ishock)); - -for i=1:ceil(nparplot/12), - figure('name',aname), - for j=1+12*(i-1):min(nparplot,12*i), - subplot(3,4,j-12*(i-1)) - if ~isempty(ibehaviour), - h=cumplot(lpmat(ibehaviour,j)); - set(h,'color',[0 0 0], 'linestyle',':') - end - hold on, - if ~isempty(inonbehaviour), - h=cumplot(lpmat(inonbehaviour,j)); - set(h,'color',[0 0 0]) - end - title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none') - end - saveas(gcf,[dirname,'\',fname_,'_',aname,'_SA_',int2str(i)]) - eval(['print -depsc2 ' dirname '\' fname_ '_' aname '_SA_' int2str(i)]); - eval(['print -dpdf ' dirname '\' fname_ '_' aname '_SA_' int2str(i)]); - if options_.nograph, close(gcf), end -end -end diff --git a/GSA_distrib/4.0.3/stab_map_2.m b/GSA_distrib/4.0.3/stab_map_2.m deleted file mode 100644 index 3941132a2..000000000 --- a/GSA_distrib/4.0.3/stab_map_2.m +++ /dev/null @@ -1,97 +0,0 @@ -%function stab_map_2(x,alpha2,istab,fnam) -function stab_map_2(x,alpha2,fnam, dirname) -% function stab_map_2(x,alpha2,fnam, dirname) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -%global bayestopt_ estim_params_ dr_ options_ ys_ fname_ -global bayestopt_ estim_params_ options_ oo_ M_ - -npar=size(x,2); -ishock= npar>estim_params_.np; -if nargin<3, - fnam=''; -end -if nargin<4, - dirname=''; -end - -ys_ = oo_.dr.ys; -dr_ = oo_.dr; -fname_ = M_.fname; -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; - -c0=corrcoef(x); -c00=tril(c0,-1); -fig_nam_=[fname_,'_',fnam,'_corr_']; - -ifig=0; -j2=0; -if ishock==0 - npar=estim_params_.np; -else - npar=estim_params_.np+nshock; -end -for j=1:npar, - i2=find(abs(c00(:,j))>alpha2); - if length(i2)>0, - for jx=1:length(i2), - j2=j2+1; - if mod(j2,12)==1, - ifig=ifig+1; - figure('name',['Correlations in the ',fnam,' sample ', num2str(ifig)]), - end - subplot(3,4,j2-(ifig-1)*12) - % bar(c0(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - %plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k') - %hold on, - plot(x(:,j),x(:,i2(jx)),'.') - % xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'), - % ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'), - if ishock, - xlabel(bayestopt_.name{j},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)},'interpreter','none'), - else - xlabel(bayestopt_.name{j+nshock},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'), - end - title(['cc = ',num2str(c0(i2(jx),j))]) - if (mod(j2,12)==0) & j2>0, - saveas(gcf,[dirname,'\',fig_nam_,int2str(ifig)]) - eval(['print -depsc2 ' dirname '\' fig_nam_ int2str(ifig)]); - eval(['print -dpdf ' dirname '\' fig_nam_ int2str(ifig)]); - if options_.nograph, close(gcf), end - end - end - end - if (j==(npar)) & j2>0, - saveas(gcf,[dirname,'\',fig_nam_,int2str(ifig)]) - eval(['print -depsc2 ' dirname '\' fig_nam_ int2str(ifig)]); - eval(['print -dpdf ' dirname '\' fig_nam_ int2str(ifig)]); - if options_.nograph, close(gcf), end - end - -end -if ifig==0, - disp(['No correlation term >', num2str(alpha2),' found for ',fnam]) -end -%close all diff --git a/GSA_distrib/4.0.3/stand_.m b/GSA_distrib/4.0.3/stand_.m deleted file mode 100644 index 2b19a7405..000000000 --- a/GSA_distrib/4.0.3/stand_.m +++ /dev/null @@ -1,25 +0,0 @@ -function [y, meany, stdy] = stand_(x) -% STAND_ Standardise a matrix by columns -% -% [x,my,sy]=stand(y) -% -% y: Time series (column matrix) -% -% x: standardised equivalent of y -% my: Vector of mean values for each column of y -% sy: Vector of standard deviations for each column of y -% -% Copyright (c) 2006 by JRC, European Commission, United Kingdom -% Author : Marco Ratto - - -if nargin==0, - return; -end - -meany=mean(x); -stdy=std(x); -for j=1:size(x,2); - y(:,j)=(x(:,j)-meany(j))./stdy(j); -end -% end of m-file \ No newline at end of file diff --git a/GSA_distrib/4.0.3/teff.m b/GSA_distrib/4.0.3/teff.m deleted file mode 100644 index 57b1beb3e..000000000 --- a/GSA_distrib/4.0.3/teff.m +++ /dev/null @@ -1,38 +0,0 @@ -function [yt, j0, ir, ic]=teff(T,Nsam,istable) -% -% [yt, j0, ir, ic]=teff(T,Nsam,istable) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -if nargin==1, - Nsam=size(T,3); - istable = [1:Nsam]'; -end -tmax=max(T,[],3); -tmin=min(T,[],3); -[ir, ic]=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=zeros(Nsam, j0); - -for j=1:j0, - y0=squeeze(T(ir(j),ic(j),:)); - %y1=ones(size(lpmat,1),1)*NaN; - y1=ones(Nsam,1)*NaN; - y1(istable,1)=y0; - yt(:,j)=y1; -end -%clear y0 y1; diff --git a/GSA_distrib/4.0.3/th_moments.m b/GSA_distrib/4.0.3/th_moments.m deleted file mode 100644 index 1e7f3405a..000000000 --- a/GSA_distrib/4.0.3/th_moments.m +++ /dev/null @@ -1,56 +0,0 @@ -% Copyright (C) 2001 Michel Juillard -% -function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list) - global M_ oo_ options_ - - nvar = size(var_list,1); - if nvar == 0 - nvar = length(dr.order_var); - ivar = [1:nvar]'; - else - ivar=zeros(nvar,1); - for i=1:nvar - i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact'); - if isempty(i_tmp) - error (['One of the variable specified does not exist']) ; - else - ivar(i) = i_tmp; - end - end - end - - [gamma_y,ivar] = th_autocovariances(dr,ivar); - m = dr.ys(ivar); - - - i1 = find(abs(diag(gamma_y{1})) > 1e-12); - s2 = diag(gamma_y{1}); - sd = sqrt(s2); - - - z = [ m sd s2 ]; - mean = m; - var = gamma_y{1}; - - -%'THEORETICAL MOMENTS'; -%'MEAN','STD. DEV.','VARIANCE'); -z; - -%'VARIANCE DECOMPOSITION (in percent)'; - -vdec = 100*gamma_y{options_.ar+2}(i1,:); - -%'MATRIX OF CORRELATIONS'; - corr = gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)'); - - if options_.ar > 0 -%'COEFFICIENTS OF AUTOCORRELATION'; - for i=1:options_.ar - autocorr{i} = gamma_y{i+1}; - zz(:,i) = diag(gamma_y{i+1}(i1,i1)); - end - end - - - \ No newline at end of file diff --git a/GSA_distrib/4.0.3/trank.m b/GSA_distrib/4.0.3/trank.m deleted file mode 100644 index a0c5bda99..000000000 --- a/GSA_distrib/4.0.3/trank.m +++ /dev/null @@ -1,25 +0,0 @@ -function yr = trank(y); -% yr = trank(y); -% yr is the rank transformation of y -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -[nr, nc] = size(y); -for j=1:nc, - [dum, is]=sort(y(:,j)); - yr(is,j)=[1:nr]'./nr; -end diff --git a/GSA_distrib/4.1/GSA_manual.pdf b/GSA_distrib/4.1/GSA_manual.pdf deleted file mode 100644 index 49c70a592..000000000 Binary files a/GSA_distrib/4.1/GSA_manual.pdf and /dev/null differ diff --git a/GSA_distrib/4.1/LPTAU.m b/GSA_distrib/4.1/LPTAU.m deleted file mode 100644 index 7427de885..000000000 --- a/GSA_distrib/4.1/LPTAU.m +++ /dev/null @@ -1,512 +0,0 @@ -function VECTOR = LPTAU(I, N) -% -% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN -% KELDYSH INSTITUTE OF APPLIED MATHEMATICS -% RUSSIAN ACADEMY OF SCIENCES -% -% QUASIRANDOM SEQUENCE GENERATORS -% ------------------------------- -% -% 28.11.1991 -% -% NOTE TO THE USER BY the NEA Data Bank: -% This quasi random number generator has been made available to -% you on condition that its identity is preserved when used -% in computer programs. If its use leads to scientific publication -% of results you should cite it in the references, in addition -% no commercial use should be made unless agreed upon with the -% main author (Prof. I.M. Sobol') -% -% ABSTRACT -% ........ -% -% POINTS BELONGING TO LP-TAU SEQUENCES UNIFORMLY DISTRIBUTED IN THE -% N-DIMENSIONAL UNIT CUBE ARE OFTEN USED IN NUMERICAL MATHEMATICS: -% -% - AS NODES FOR MULTIDIMENSIONAL INTEGRATION; -% - AS SEARCHING POINTS IN GLOBAL OPTIMIZATION; -% - AS TRIAL POINTS IN MULTI-CRITERIA DECISION MAKING; -% - AS QUASIRANDOM POINTS FOR QUASI-MONTECARLO ALGORITHMS; -% - ETC. -% -% THIS SUBROUTINE CONTAINS THE ALGORITHM FOR FAST GENERATION OF -% LP-TAU SEQUENCES THAT ARE SUITABLE FOR MULTI-PROCESSOR COMPUTATIONS. -% THE DIMENSIONS N.LE.51, THE NUMBER OF POINTS N.LT.2**30. -% THE PROGRAMMING LANGUAGE IS FORTRAN-77. THIS SUBROUTINE IS AVAILABLE -% ALSO IN %-LANGUAGE. -% THE REPORT DESCRIBING THE ALGORITHM CONTAINS THE DESCRIPTION OF THE -% ALGORITHM AND CERTAIN IMPORTANT PROPERTIES OF LP-TAU SEQUENCES AND -% THEIR GENERALIZATIONS ARE DISCUSSED. -% -% REFERENCE: -% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN -% KELDYSH INSTITUTE OF APPLIED MATHEMATICS -% RUSSIAN ACADEMY OF SCIENCES -% -% QUASIRANDOM SEQUENCE GENERATORS -% MOSCOW 1992, IPM ZAK. NO.30 (100 COPIES) -% -% ------------------------------------------------------------------------ -% -% INPUT PARAMETERS: -% -% I - NUMBER OF THE POINT (I=(0,2**30-1)), -% N - DIMENSION OF THE POINT (0MAXNUM) | (N>MAXDIM)), - disp('LP-TAU CALL FAILED') - disp(' PRESS TO EXIT LPTAU') - pause - return -end -if ((PRVNUM+1==I) & (N<=PRVDIM)), - % - % RECURRENT GENERATION OF THE POINT - % - % - % SEARCH POSITION OF THE RIGHTMOST "1" - % IN THE BINARY REPRESENTATION OF I - % - L=0; - POS=0; - while L1e-010); - % If we deal with groups we can only estimate the new mu* - % measure since factors in the same groups can move in - % opposite direction and the definition of the standard - % Morris mu cannopt be applied. - % In the new version the elementary effect is defined with - % the absolute value. - %SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3)); - SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); - else - Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:)); - % If no groups --> we compute both the original and - % modified measure - if Delta(j) > 0 %=> +Delta - SAmeas(Change_factor(j,i),i) = (Single_OutValues(j+1) - Single_OutValues(j) )/Delt; %(2/3); - else %=> -Delta - SAmeas(Change_factor(j,i),i) = (Single_OutValues(j) - Single_OutValues(j+1) )/Delt; %(2/3); - end - end - end %for j=1:sizea - - end %for i=1:r - - if NumGroups ~ 0 - SAmeas = SAmeas'; - end - - % Compute Mu AbsMu and StDev - if any(any(isnan(SAmeas))) - for j=1:NumFact, - SAm = SAmeas(j,:); - SAm = SAm(find(~isnan(SAm))); - rr=length(SAm); - AbsMu(j,1) = sum(abs(SAm),2)/rr; - if NumGroups == 0 - Mu(j,1) = sum(SAm,2)/rr; - StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5; - end - end - else - AbsMu = sum(abs(SAmeas),2)/r; - if NumGroups == 0 - Mu = sum(SAmeas,2)/r; - StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5; - end - end - - % Define the output Matrix - if we have groups we cannot define the old - % measure mu, only mu* makes sense - if NumGroups > 0 - OutMatrix = [OutMatrix; AbsMu]; - else - OutMatrix = [OutMatrix; AbsMu, Mu, StDev]; - end -end % For Each Output diff --git a/GSA_distrib/4.1/Sampling_Function_2.m b/GSA_distrib/4.1/Sampling_Function_2.m deleted file mode 100644 index ccd3a87f9..000000000 --- a/GSA_distrib/4.1/Sampling_Function_2.m +++ /dev/null @@ -1,174 +0,0 @@ -function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -% Inputs: k (1,1) := number of factors examined or number of groups examined. -% In case the groups are chosen the number of factors is stores in NumFact and -% sizea becomes the number of created groups. -% NumFact (1,1) := number of factors examined in the case when groups are chosen -% r (1,1) := sample size -% p (1,1) := number of intervals considered in [0, 1] -% UB(sizea,1) := Upper Bound for each factor -% LB(sizea,1) := Lower Bound for each factor -% GroupNumber(1,1) := Number of groups (eventually 0) -% GroupMat(NumFact,GroupNumber):= Matrix which describes the chosen groups. Each column represents a group and its elements -% are set to 1 in correspondence of the factors that belong to the fixed group. All -% the other elements are zero. -% Local Variables: -% sizeb (1,1) := sizea+1 -% sizec (1,1) := 1 -% randmult (sizea,1) := vector of random +1 and -1 -% perm_e(1,sizea) := vector of sizea random permutated indeces -% fact(sizea) := vector containing the factor varied within each traj -% DDo(sizea,sizea) := D* in Morris, 1991 -% A(sizeb,sizea) := Jk+1,k in Morris, 1991 -% B(sizeb,sizea) := B in Morris, 1991 -% Po(sizea,sizea) := P* in Morris, 1991 -% Bo(sizeb,sizea) := B* in Morris, 1991 -% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991 -% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory) -% In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory -% of k step in the parameter space and it provides a single elementary -% effect per factor -% MyInt() -% Fact(sizea,1) := for each loop vector indicating which factor or group of factors has been changed -% in each step of the trajectory -% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design -% for single factor analysis, while it constitutes an intermediate step for the group analysis. -% -% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices -% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors -% -% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine -% follows the following steps: -% 1- Creation of P0 and DD0 matrices defined in Morris for the groups. This means that the dimensions of these -% 2 matrices are (GroupNumber,GroupNumber). -% 2- Creation of AuxMat matrix with (GroupNumber+1,GroupNumber) elements. -% 3- Definition of GroupB0 starting from AuxMat, GroupMat and P0. -% 4- The final B0 for groups is obtained as [ones(sizeb,1)*x0' + GroupB0]. The P0 permutation is present in GroupB0 -% and it's not necessary to permute the matrix (ones(sizeb,1)*x0') because it's already randomly created. -% Reference: -% A. Saltelli, K. Chan, E.M. Scott, "Sensitivity Analysis" on page 68 ss -% -% F. Campolongo, J. Cariboni, JRC - IPSC Ispra, Varese, IT -% Last Update: 15 November 2005 by J.Cariboni -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -% Parameters and initialisation of the output matrix -sizea = k; -Delta = p/(2*p-2); -%Delta = 1/3 -NumFact = sizea; -GroupNumber = size(GroupMat,2); - -if GroupNumber ~ 0; - sizea = size(GroupMat,2); -end - -sizeb = sizea + 1; -sizec = 1; -Outmatrix = []; -OutFact = []; - -% For each i generate a trajectory -for i=1:r - - % Construct DD0 - OLD VERSION - it does not need communication toolbox - % RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0). - % Note that DD0 tells if the factor have to be increased or ddecreased - % by Delta. - randmult = ones(k,1); - v = rand(k,1); - randmult (find(v < 0.5))=-1; - randmult = repmat(randmult,1,k); - DD0 = randmult .* eye(k); - - % Construct DD0 - NEW VERSION - it needs communication toolbox - % randsrc(m) generates an m-by-m matrix, each of whose entries independently takes the value -1 with probability 1/2, - % and 1 with probability 1/2. - % DD0 = randsrc(NumFact) .* eye(NumFact); - - % Construct B (lower triangular) - B = ones(sizeb,sizea); - for j = 1:sizea - B(1:j,j)=0; - end - - % Construct A0, A - A0 = ones(sizeb,1); - A = ones(sizeb,NumFact); - - % Construct the permutation matrix P0. In each column of P0 one randomly chosen element equals 1 - % while all the others equal zero. - % P0 tells the order in which order factors are changed in each - % trajectory. P0 is created as it follows: - % 1) All the elements of P0 are set equal to zero ==> P0 = zeros (sizea, sizea); - % 2) The function randperm create a random permutation of integer 1:sizea, without repetitions ==> perm_e; - % 3) In each column of P0 the element indicated in perm_e is set equal to one. - % Note that P0 is then used reading it by rows. - P0 = zeros (sizea, sizea); - perm_e = randperm(sizea); % RANDPERM(n) is a random permutation of the integers from 1 to n. - for j = 1:sizea - P0(perm_e(j),j) = 1; - end - - % When groups are present the random permutation is done only on B. The effect is the same since - % the added part (A0*x0') is completely random. - if GroupNumber ~ 0 - B = B * (GroupMat*P0')'; - end - - % Compute AuxMat both for single factors and groups analysis. For Single factors analysis - % AuxMat is added to (A0*X0) and then permutated through P0. When groups are active AuxMat is - % used to build GroupB0. AuxMat is created considering DD0. If the element on DD0 diagonal - % is 1 then AuxMat will start with zero and add Delta. If the element on DD0 diagonal is -1 - % then DD0 will start Delta and goes to zero. - AuxMat = Delta*0.5*((2*B - A) * DD0 + A); - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube - % [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta] - MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors - - % OLD VERSION - it needs communication toolbox - % w = randint(NumFact,1,[1,size(MyInt,2)]); - - % NEW VERSION - construct a version of random integers - % 1) create a vector of random integers - % 2) divide [0,1] into the needed steps - % 3) check in which interval the random numbers fall - % 4) generate the corresponding integer - v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1) - IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2) - DiffAuxVec = IntUsed - v; % 3) - - for ii = 1:size(DiffAuxVec,1) - w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4) - end - x0 = MyInt(1,w)'; % Define x0 - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a - % trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors) - if GroupNumber ~ 0 - B0 = (A0*x0' + AuxMat); - else - B0 = (A0*x0' + AuxMat)*P0; - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % c --> Compute values in the original intervals - % B0 has values x(i,j) in [0, 1/(p -1), 2/(p -1), ... , 1]. - % To obtain values in the original intervals [LB, UB] we compute - % LB(j) + x(i,j)*(UB(j)-LB(j)) - In = repmat(LB,1,sizeb)' + B0 .* repmat((UB-LB),1,sizeb)'; - - % Create the Factor vector. Each component of this vector indicate which factor or group of factor - % has been changed in each step of the trajectory. - for j=1:sizea - Fact(1,j) = find(P0(j,:)); - end - Fact(1,sizea+1) = 0; - - Outmatrix = [Outmatrix; In]; - OutFact = [OutFact; Fact']; - -end \ No newline at end of file diff --git a/GSA_distrib/4.1/beta_inv.m b/GSA_distrib/4.1/beta_inv.m deleted file mode 100644 index d3c95836d..000000000 --- a/GSA_distrib/4.1/beta_inv.m +++ /dev/null @@ -1,38 +0,0 @@ -function x = beta_inv(p, a, b) -% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution -%-------------------------------------------------------------- -% USAGE: x = beta_inv(p,a,b) -% where: p = vector of probabilities -% a = beta distribution parameter, a = scalar -% b = beta distribution parameter b = scalar -% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1)) -%-------------------------------------------------------------- -% RETURNS: x at each element of p for the beta(a,b) distribution -%-------------------------------------------------------------- -% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd -%-------------------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to -% match the format of the econometrics toolbox - -if (nargin ~= 3) - error('Wrong # of arguments to beta_inv'); -end - -if any(any((a<=0)|(b<=0))) - error('beta_inv parameter a or b is nonpositive'); -end -if any(any(abs(2*p-1)>1)) - error('beta_inv: A probability should be 0<=p<=1'); -end - -x = a ./ (a+b); -dx = 1; -while any(any(abs(dx)>256*eps*max(x,1))) - dx = (betainc(x,a,b) - p) ./ beta_pdf(x,a,b); - x = x - dx; - x = x + (dx - x) / 2 .* (x<0); -end - \ No newline at end of file diff --git a/GSA_distrib/4.1/beta_pdf.m b/GSA_distrib/4.1/beta_pdf.m deleted file mode 100644 index 8412fbdce..000000000 --- a/GSA_distrib/4.1/beta_pdf.m +++ /dev/null @@ -1,32 +0,0 @@ -function pdf = beta_pdf(x, a, b) -% PURPOSE: pdf of the beta(a,b) distribution -%-------------------------------------------------------------- -% USAGE: pdf = beta_pdf(x,a,b) -% where: x = vector of components -% a = beta distribution parameter, a = scalar -% b = beta distribution parameter b = scalar -% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1)) -%-------------------------------------------------------------- -% RETURNS: pdf at each element of x of the beta(a,b) distribution -%-------------------------------------------------------------- -% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd -%-------------------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to -% match the format of the econometrics toolbox - - -if (nargin ~=3) - error('Wrong # of arguments to beta_pdf'); -end - -if any(any((a<=0)|(b<=0))) - error('Parameter a or b is nonpositive'); -end - -I = find((x<0)|(x>1)); - -pdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b); -pdf(I) = 0*I; diff --git a/GSA_distrib/4.1/cumplot.m b/GSA_distrib/4.1/cumplot.m deleted file mode 100644 index a700d3784..000000000 --- a/GSA_distrib/4.1/cumplot.m +++ /dev/null @@ -1,14 +0,0 @@ -function h = cumplot(x); -%function h =cumplot(x) -% Copyright (C) 2005 Marco Ratto - - -n=length(x); -x=[-inf; sort(x); Inf]; -y=[0:n n]./n; -h0 = stairs(x,y); -grid on, - -if nargout, - h=h0; -end diff --git a/GSA_distrib/4.1/dat_fil_.m b/GSA_distrib/4.1/dat_fil_.m deleted file mode 100644 index 0b3ac8f8e..000000000 --- a/GSA_distrib/4.1/dat_fil_.m +++ /dev/null @@ -1,30 +0,0 @@ -function c = dat_fil_(data_file); -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -try - eval(data_file); -catch - load(data_file); -end -clear data_file; - -a=who; - -for j=1:length(a) - eval(['c.',a{j},'=',a{j},';']); -end \ No newline at end of file diff --git a/GSA_distrib/4.1/dynare_MC.m b/GSA_distrib/4.1/dynare_MC.m deleted file mode 100644 index 05c83da2e..000000000 --- a/GSA_distrib/4.1/dynare_MC.m +++ /dev/null @@ -1,149 +0,0 @@ -function dynare_MC(var_list_,OutDir) -% -% Adapted by M. Ratto from dynare_estimation.m and posteriorsmoother.m -% (dynare_estimation.m and posteriorsmoother.m are part of DYNARE, -% copyright M. Juillard) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ options_ oo_ estim_params_ -global bayestopt_ - -% if options_.filtered_vars ~= 0 & options_.filter_step_ahead == 0 -% options_.filter_step_ahead = 1; -% end -% if options_.filter_step_ahead ~= 0 -% options_.nk = max(options_.filter_step_ahead); -% else -% options_.nk = 0; -% end -% -options_.filter_step_ahead=1; -options_.nk = 1; - - - -nvx = estim_params_.nvx; -nvn = estim_params_.nvn; -ncx = estim_params_.ncx; -ncn = estim_params_.ncn; -np = estim_params_.np ; -npar = nvx+nvn+ncx+ncn+np; - -if isempty(options_.datafile) - error('ESTIMATION: datafile option is missing') -end - -if isempty(options_.varobs) - error('ESTIMATION: VAROBS is missing') -end - -%% Read and demean data -rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); - -options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1); -gend = options_.nobs; -n_varobs = size(options_.varobs,1); - -rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); -if options_.loglinear == 1 & ~options_.logdata - rawdata = log(rawdata); -end -if options_.prefilter == 1 - bayestopt_.mean_varobs = mean(rawdata,1); - data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs); -else - data = transpose(rawdata); -end -[data_index,number_of_observations,no_more_missing_observations] = describe_missing_data(data,gend,n_varobs); - -if ~isreal(rawdata) - error(['There are complex values in the data. Probably a wrong' ... - ' transformation']) -end - -offset = npar-np; -fname_=M_.fname; - -options_ = set_default_option(options_,'opt_gsa',1); -options_gsa_ = options_.opt_gsa; - -if options_gsa_.pprior, - namfile=[fname_,'_prior']; -else - namfile=[fname_,'_mc']; -end -load([OutDir,'/',namfile],'lpmat', 'lpmat0', 'istable') -% load(options_.mode_file) -%% -%% -%% -x=[lpmat0(istable,:) lpmat(istable,:)]; -clear lpmat lpmat0 istable %iunstable egg yys T -B = size(x,1); -[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(x(1,:)',gend,data,{},0); -n1=size(atT,1); - -nfil=B/40; -stock_smooth = zeros(M_.endo_nbr,gend,40); -stock_filter = zeros(M_.endo_nbr,gend+1,40); -stock_ys = zeros(40, M_.endo_nbr); -logpo2=zeros(B,1); -%% -h = waitbar(0,'MC smoother ...'); -delete([OutDir,'/',namfile,'_*.mat']) -ib=0; -ifil=0; -opt_gsa=options_.opt_gsa; - -for b=1:B - ib=ib+1; - deep = x(b,:)'; - set_all_parameters(deep); - dr = resol(oo_.steady_state,0); - %deep(1:offset) = xparam1(1:offset); - logpo2(b,1) = DsgeLikelihood(deep,gend,data,data_index,number_of_observations,no_more_missing_observations); - if opt_gsa.lik_only==0, - [atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff, aK] = DsgeSmoother(deep,gend,data,data_index,0); - stock_smooth(:,:,ib)=atT(1:M_.endo_nbr,:); -% stock_filter(:,:,ib)=filtered_state_vector(1:M_.endo_nbr,:); - stock_filter(:,:,ib)=aK(1,1:M_.endo_nbr,:); - stock_ys(ib,:)=ys'; - if ib==40, - ib=0; - ifil=ifil+1; - save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys') - stock_smooth = zeros(M_.endo_nbr,gend,40); - stock_filter = zeros(M_.endo_nbr,gend+1,40); - stock_ys = zeros(40, M_.endo_nbr); - end - end - waitbar(b/B,h,['MC smoother ...',num2str(b),'/',num2str(B)]); -end -close(h) -if opt_gsa.lik_only==0, -if ib>0, - ifil=ifil+1; - stock_smooth = stock_smooth(:,:,1:ib); - stock_filter = stock_filter(:,:,1:ib); - stock_ys = stock_ys(1:ib,:); - save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys') -end -end -stock_gend=gend; -stock_data=data; -save([OutDir,'/',namfile],'x','logpo2','stock_gend','stock_data','-append') diff --git a/GSA_distrib/4.1/fdjac.m b/GSA_distrib/4.1/fdjac.m deleted file mode 100644 index 2ff746531..000000000 --- a/GSA_distrib/4.1/fdjac.m +++ /dev/null @@ -1,37 +0,0 @@ -% FDJAC Computes two-sided finite difference Jacobian -% USAGE -% fjac = fdjac(f,x,P1,P2,...) -% INPUTS -% f : name of function of form fval = f(x) -% x : evaluation point -% P1,P2,... : additional arguments for f (optional) -% OUTPUT -% fjac : finite differnce Jacobian -% -% USER OPTIONS (SET WITH OPSET) -% tol : a factor used in setting the step size -% increase if f is inaccurately computed - -% Copyright (c) 1997-2002, Paul L. Fackler & Mario J. Miranda -% paul_fackler@ncsu.edu, miranda.4@osu.edu - -function fjac = fdjac(f,x,varargin) - -tol = optget(mfilename,'tol',eps.^(1/3)); - -h = tol.*max(abs(x),1); -xh1=x+h; xh0=x-h; -h=xh1-xh0; -for j=1:length(x); - xx = x; - xx(j) = xh1(j); f1=feval(f,xx,varargin{:}); - xx(j) = xh0(j); f0=feval(f,xx,varargin{:}); - fjac(:,j) = (f1-f0)/h(j); -% v = (f1-f0); -% k = find(abs(v) < 1e-8); -% v(k) = 0; -% -% fjac(:,j) = v/h(j); -end - -feval(f,x,varargin{:}); \ No newline at end of file diff --git a/GSA_distrib/4.1/filt_mc_.m b/GSA_distrib/4.1/filt_mc_.m deleted file mode 100644 index 45c1caf60..000000000 --- a/GSA_distrib/4.1/filt_mc_.m +++ /dev/null @@ -1,708 +0,0 @@ -function [rmse_MC, ixx] = filt_mc_(OutDir) -% function [rmse_MC, ixx] = filt_mc_(OutDir) -% copyright Marco Ratto 2006 -% inputs (from opt_gsa structure) -% vvarvecm = options_gsa_.var_rmse; -% loadSA = options_gsa_.load_rmse; -% pfilt = options_gsa_.pfilt_rmse; -% alpha = options_gsa_.alpha_rmse; -% alpha2 = options_gsa_.alpha2_rmse; -% istart = options_gsa_.istart_rmse; -% alphaPC = 0.5; -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global bayestopt_ estim_params_ M_ options_ oo_ - -options_gsa_=options_.opt_gsa; -vvarvecm = options_gsa_.var_rmse; -loadSA = options_gsa_.load_rmse; -pfilt = options_gsa_.pfilt_rmse; -alpha = options_gsa_.alpha_rmse; -alpha2 = options_gsa_.alpha2_rmse; -istart = options_gsa_.istart_rmse; -alphaPC = 0.5; - -fname_ = M_.fname; -lgy_ = M_.endo_names; -dr_ = oo_.dr; - -disp(' ') -disp(' ') -disp('Starting sensitivity analysis') -disp('for the fit of EACH observed series ...') -disp(' ') -disp('Deleting old SA figures...') -a=dir([OutDir,'/*.*']); -tmp1='0'; -if options_.opt_gsa.ppost, - tmp=['_rmse_post']; -else - if options_.opt_gsa.pprior - tmp=['_rmse_prior']; - else - tmp=['_rmse_mc']; - end - if options_gsa_.lik_only, - tmp1 = [tmp,'_post_SA']; - tmp = [tmp,'_lik_SA']; - end -end -for j=1:length(a), - if strmatch([fname_,tmp],a(j).name), - disp(a(j).name) - delete([OutDir,'/',a(j).name]) - end, - if strmatch([fname_,tmp1],a(j).name), - disp(a(j).name) - delete([OutDir,'/',a(j).name]) - end, -end -disp('done !') - - -nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn; -npar=estim_params_.np; -if ~isempty(options_.mode_file), - load(options_.mode_file,'xparam1'), -end -if options_.opt_gsa.ppost, - c=load([fname_,'_mean'],'xparam1'); - xparam1_mean=c.xparam1; - clear c -elseif ~isempty(options_.mode_file) & ~isempty(ls([fname_,'_mean.mat'])) - c=load([fname_,'_mean'],'xparam1'); - xparam1_mean=c.xparam1; - clear c -end - -if options_.opt_gsa.ppost, - fnamtmp=[fname_,'_post']; - DirectoryName = CheckPath('metropolis'); -else - if options_.opt_gsa.pprior - fnamtmp=[fname_,'_prior']; - else - fnamtmp=[fname_,'_mc']; - end -end -if ~loadSA, - if exist('xparam1','var') - set_all_parameters(xparam1); - steady_; - ys_mode=oo_.steady_state; - end - if exist('xparam1_mean','var') - set_all_parameters(xparam1_mean); - steady_; - ys_mean=oo_.steady_state; - end -% eval(options_.datafile) - obs = dat_fil_(options_.datafile); - if ~options_.opt_gsa.ppost - load([OutDir,'/',fnamtmp],'x','logpo2','stock_gend','stock_data'); - logpo2=-logpo2; - else - %load([DirectoryName '/' M_.fname '_data.mat']); - [stock_gend, stock_data] = read_data; - filfilt = dir([DirectoryName '/' M_.fname '_filter_step_ahead*.mat']); - filparam = dir([DirectoryName '/' M_.fname '_param*.mat']); - x=[]; - logpo2=[]; - sto_ys=[]; - for j=1:length(filparam), - %load([DirectoryName '/' M_.fname '_param',int2str(j),'.mat']); - if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name)) - load([DirectoryName '/' filparam(j).name]); - x=[x; stock]; - logpo2=[logpo2; stock_logpo]; - sto_ys=[sto_ys; stock_ys]; - clear stock stock_logpo stock_ys; - end - end - end - nruns=size(x,1); - nfilt=floor(pfilt*nruns); - if options_.opt_gsa.ppost | (options_.opt_gsa.ppost==0 & options_.opt_gsa.lik_only==0) - disp(' ') - disp('Computing RMSE''s...') - fobs = options_.first_obs; - nobs=options_.nobs; - for i=1:size(vvarvecm,1), - vj=deblank(vvarvecm(i,:)); - eval(['vobs =obs.',vj,'(fobs:fobs-1+nobs);']) - if options_.prefilter == 1 - %eval([vj,'=',vj,'-bayestopt_.mean_varobs(i);']) - %eval([vj,'=',vj,'-mean(',vj,',1);']) - vobs = vobs-mean(vobs,1); - end - - jxj = strmatch(vj,lgy_(dr_.order_var,:),'exact'); - js = strmatch(vj,lgy_,'exact'); - if exist('xparam1','var') -% if isfield(oo_,'FilteredVariables') -% eval(['rmse_mode(i) = sqrt(mean((vobs(istart:end)-oo_.steady_state(js)-oo_.FilteredVariables.',vj,'(istart:end-1)).^2));']) -% else - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,stock_gend,stock_data,{},0); - y0 = squeeze(aK(1,jxj,:)) + ... - kron(ys_mode(js,:),ones(size(aK,3),1)); -% y0 = ahat(jxj,:)' + ... -% kron(ys_mode(js,:),ones(size(ahat,2),1)); - rmse_mode(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2)); -% end - end - y0=zeros(nobs+1,nruns); - if options_.opt_gsa.ppost - %y0=zeros(nobs+max(options_.filter_step_ahead),nruns); - nbb=0; - for j=1:length(filfilt), - load([DirectoryName '/' M_.fname '_filter_step_ahead',num2str(j),'.mat']); - nb = size(stock,4); -% y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,:,:)) + ... -% kron(sto_ys(nbb+1:nbb+nb,js)',ones(size(stock,3),1)); - y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,1:nobs+1,:)) + ... - kron(sto_ys(nbb+1:nbb+nb,js)',ones(nobs+1,1)); - %y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock; - nbb=nbb+nb; - clear stock; - end - else - filfilt=dir([OutDir,'/',fnamtmp,'_*.mat']); - nbb=0; - for j=1:size(filfilt,1), - load([OutDir,'/',fnamtmp,'_',num2str(j),'.mat'],'stock_filter','stock_ys'); - nb = size(stock_filter,3); - y0(:,nbb+1:nbb+nb) = squeeze(stock_filter(jxj,:,:)) + ... - kron(stock_ys(:,js)',ones(nobs+1,1)); - %y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock; - nbb=nbb+nb; - clear stock_filter; - end - -% y0 = squeeze(stock_filter(:,jxj,:)) + ... -% kron(stock_ys(js,:),ones(size(stock_filter,1),1)); - end - y0M=mean(y0,2); - for j=1:nruns, - rmse_MC(j,i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1,j)).^2)); - end - if exist('xparam1_mean','var') - %eval(['rmse_pmean(i) = sqrt(mean((',vj,'(fobs-1+istart:fobs-1+nobs)-y0M(istart:end-1)).^2));']) - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,stock_gend,stock_data,{},0); - y0 = squeeze(aK(1,jxj,:)) + ... - kron(ys_mean(js,:),ones(size(aK,3),1)); -% y0 = ahat(jxj,:)' + ... -% kron(ys_mean(js,:),ones(size(ahat,2),1)); - rmse_pmean(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2)); - end - end - clear stock_filter; - end - for j=1:nruns, - lnprior(j,1) = priordens(x(j,:)',bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4); - end - likelihood=logpo2(:)-lnprior(:); - disp('... done!') - - if options_.opt_gsa.ppost - save([OutDir,'/',fnamtmp], 'x', 'logpo2', 'likelihood', 'rmse_MC', 'rmse_mode','rmse_pmean') - else - if options_.opt_gsa.lik_only - save([OutDir,'/',fnamtmp], 'likelihood', '-append') - else - save([OutDir,'/',fnamtmp], 'likelihood', 'rmse_MC','-append') - if exist('xparam1_mean','var') - save([OutDir,'/',fnamtmp], 'rmse_pmean','-append') - end - if exist('xparam1','var') - save([OutDir,'/',fnamtmp], 'rmse_mode','-append') - end - end - end -else - if options_.opt_gsa.lik_only & options_.opt_gsa.ppost==0 - load([OutDir,'/',fnamtmp],'x','logpo2','likelihood'); - else - load([OutDir,'/',fnamtmp],'x','logpo2','likelihood','rmse_MC','rmse_mode','rmse_pmean'); - end - lnprior=logpo2(:)-likelihood(:); - nruns=size(x,1); - nfilt=floor(pfilt*nruns); -end -% smirnov tests -nfilt0=nfilt*ones(size(vvarvecm,1),1); -logpo2=logpo2(:); -if ~options_.opt_gsa.ppost - [dum, ipost]=sort(-logpo2); - [dum, ilik]=sort(-likelihood); -end -if ~options_.opt_gsa.ppost & options_.opt_gsa.lik_only - if options_.opt_gsa.pprior - anam='rmse_prior_post'; - else - anam='rmse_mc_post'; - end - stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ipost(1:nfilt),:),alpha2,anam, OutDir); - if options_.opt_gsa.pprior - anam='rmse_prior_lik'; - else - anam='rmse_mc_lik'; - end - stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ilik(1:nfilt),:),alpha2,anam, OutDir); -else - for i=1:size(vvarvecm,1), - [dum, ixx(:,i)]=sort(rmse_MC(:,i)); - if options_.opt_gsa.ppost, - %nfilt0(i)=length(find(rmse_MC(:,i)0.0001 ); -vvarvecm=vvarvecm(ivar,:); -rmse_MC=rmse_MC(:,ivar); - -disp(' ') -% if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior, - disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ]) -% else -% disp(['Sample filtered the best RMSE''s smaller than RMSE at the posterior mean ...' ]) -% end -% figure, boxplot(rmse_MC) -% set(gca,'xticklabel',vvarvecm) -% saveas(gcf,[fname_,'_SA_RMSE']) - -disp(' ') -disp(' ') -disp('RMSE ranges after filtering:') -if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior, - disp([' best ',num2str(pfilt*100),'% filtered remaining 90%']) - disp([' min max min max posterior mode']) -else - disp([' best filtered remaining ']) - disp([' min max min max posterior mean']) -end -for j=1:size(vvarvecm,1), - disp([vvarvecm(j,:), sprintf('%15.5g',[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - max(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - rmse_txt(j)])]) - % disp([vvarvecm(j,:), sprintf('%15.5g',[min(logpo2(ixx(1:nfilt,j))) ... - % max(logpo2(ixx(1:nfilt,j))) ... - % min(logpo2(ixx(nfilt+1:end,j))) ... - % max(logpo2(ixx(nfilt+1:end,j)))])]) -end - -SP=zeros(npar+nshock,size(vvarvecm,1)); -for j=1:size(vvarvecm,1), - ns=find(PP(:,j)1),:); -snam=param_names(find(nsp>0),:); -% snam0=bayestopt_.name(find(nsp==0)); -% snam1=bayestopt_.name(find(nsp==1)); -% snam2=bayestopt_.name(find(nsp>1)); -% snam=bayestopt_.name(find(nsp>0)); -nsnam=(find(nsp>1)); - -disp(' ') -disp(' ') -disp('These parameters do not affect significantly the fit of ANY observed series:') -disp(snam0) -disp(' ') -disp('These parameters affect ONE single observed series:') -disp(snam1) -disp(' ') -disp('These parameters affect MORE THAN ONE observed series: trade off exists!') -disp(snam2) - - -%pnam=bayestopt_.name(end-estim_params_.np+1:end); -pnam=bayestopt_.name; - -% plot trade-offs -a00=jet(size(vvarvecm,1)); -for ix=1:ceil(length(nsnam)/5), - figure, - for j=1+5*(ix-1):min(size(snam2,1),5*ix), - subplot(2,3,j-5*(ix-1)) - %h0=cumplot(x(:,nsnam(j)+nshock)); - h0=cumplot(x(:,nsnam(j))); - set(h0,'color',[0 0 0]) - hold on, - np=find(SP(nsnam(j),:)); - %a0=jet(nsp(nsnam(j))); - a0=a00(np,:); - for i=1:nsp(nsnam(j)), %size(vvarvecm,1), - %h0=cumplot(x(ixx(1:nfilt,np(i)),nsnam(j)+nshock)); - h0=cumplot(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j))); - set(h0,'color',a0(i,:)) - end - ydum=get(gca,'ylim'); - %xdum=xparam1(nshock+nsnam(j)); - if exist('xparam1') - xdum=xparam1(nsnam(j)); - h1=plot([xdum xdum],ydum); - set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - end - xlabel('') - title([pnam{nsnam(j)}],'interpreter','none') - end - %subplot(3,2,6) - h0=legend(str2mat('base',vvarvecm(np,:)),0); - set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none') - %h0=legend({'base',vnam{np}}',0); - %set(findobj(get(h0,'children'),'type','text'),'interpreter','none') - if options_.opt_gsa.ppost - saveas(gcf,[OutDir,'/',fname_,'_rmse_post_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]); - else - if options_.opt_gsa.pprior - saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]); - else - saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]); - end - end -end -close all - -for j=1:size(SP,2), - nsx(j)=length(find(SP(:,j))); -end - -number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two. -bandwidth = 0; % Rule of thumb optimal bandwidth parameter. -kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton. -%kernel_function = 'uniform'; % Gaussian kernel for Fast Fourrier Transform approximaton. - -for ix=1:ceil(length(nsnam)/5), - figure, - for j=1+5*(ix-1):min(size(snam2,1),5*ix), - subplot(2,3,j-5*(ix-1)) - optimal_bandwidth = mh_optimal_bandwidth(x(:,nsnam(j)),size(x,1),bandwidth,kernel_function); - [x1,f1] = kernel_density_estimate(x(:,nsnam(j)),number_of_grid_points,... - size(x,1),optimal_bandwidth,kernel_function); - h0 = plot(x1, f1,'k'); - hold on, - np=find(SP(nsnam(j),:)); - %a0=jet(nsp(nsnam(j))); - a0=a00(np,:); - for i=1:nsp(nsnam(j)), %size(vvarvecm,1), - optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),nfilt,bandwidth,kernel_function); - [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),number_of_grid_points,... - nfilt, optimal_bandwidth,kernel_function); - h0 = plot(x1, f1); - set(h0,'color',a0(i,:)) - end - ydum=get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]); - if exist('xparam1') - %xdum=xparam1(nshock+nsnam(j)); - xdum=xparam1(nsnam(j)); - h1=plot([xdum xdum],[0 ydum(2)]); - set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - end - xlabel('') - title([pnam{nsnam(j)}],'interpreter','none') - end - h0=legend(str2mat('base',vvarvecm(np,:)),0); - set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none') - %h0=legend({'base',vnam{np}}',0); - %set(findobj(get(h0,'children'),'type','text'),'interpreter','none') - if options_.opt_gsa.ppost - saveas(gcf,[OutDir,'/',fname_,'_rmse_post_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]); - else - if options_.opt_gsa.pprior - saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]); - else - saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]); - end - end -end -close all - -% for j=1:size(SP,2), -% nfig=0; -% np=find(SP(:,j)); -% for i=1:nsx(j), %size(vvarvecm,1), -% if mod(i,12)==1, -% nfig=nfig+1; -% %figure('name',['Sensitivity of fit of ',vnam{j}]), -% figure('name',['Sensitivity of fit of ',deblank(vvarvecm(j,:)),' ',num2str(nfig)]), -% end -% -% subplot(3,4,i-12*(nfig-1)) -% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt,j),np(i)),nfilt,bandwidth,kernel_function); -% [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt,j),np(i)),number_of_grid_points,... -% nfilt, optimal_bandwidth,kernel_function); -% plot(x1, f1,':k','linewidth',2) -% optimal_bandwidth = mh_optimal_bandwidth(x(ixx(nfilt+1:end,j),np(i)),nruns-nfilt,bandwidth,kernel_function); -% [x1,f1] = kernel_density_estimate(x(ixx(nfilt+1:end,j),np(i)),number_of_grid_points,... -% nruns-nfilt,optimal_bandwidth,kernel_function); -% hold on, plot(x1, f1,'k','linewidth',2) -% ydum=get(gca,'ylim'); -% %xdum=xparam1(nshock+np(i)); -% xdum=xparam1(np(i)); -% h1=plot([xdum xdum],ydum); -% set(h1,'color',[0.85 0.85 0.85],'linewidth',2) -% %xdum1=mean(x(ixx(1:nfilt,j),np(i)+nshock)); -% xdum1=mean(x(ixx(1:nfilt,j),np(i))); -% h2=plot([xdum1 xdum1],ydum); -% set(h2,'color',[0 1 0],'linewidth',2) -% % h0=cumplot(x(nfilt+1:end,np(i)+nshock)); -% % set(h0,'color',[1 1 1]) -% % hold on, -% % h0=cumplot(x(ixx(1:nfilt,j),np(i)+nshock)); -% % set(h0,'linestyle',':','color',[1 1 1]) -% %title([pnam{np(i)}]) -% title([pnam{np(i)},'. K-S prob ', num2str(PP(np(i),j))],'interpreter','none') -% xlabel('') -% if mod(i,12)==0 | i==nsx(j), -% saveas(gcf,[fname_,'_rmse_',deblank(vvarvecm(j,:)),'_',int2str(nfig)]) -% close(gcf) -% end -% end -% end - - -disp(' ') -disp(' ') -disp('Sensitivity table (significance and direction):') -vav=char(zeros(1, size(param_names,2)+3 )); -ibl = 12-size(vvarvecm,2); -for j=1:size(vvarvecm,1), - vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)]; -end -disp(vav) -for j=1:npar+nshock, %estim_params_.np, - %disp([param_names(j,:), sprintf('%8.5g',SP(j,:))]) - disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))]) - disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))]) -end - - -disp(' ') -disp(' ') -disp('Starting bivariate analysis:') - -for i=1:size(vvarvecm,1) - if options_.opt_gsa.ppost - fnam = ['rmse_post_',deblank(vvarvecm(i,:))]; - else - if options_.opt_gsa.pprior - fnam = ['rmse_prior_',deblank(vvarvecm(i,:))]; - else - fnam = ['rmse_mc_',deblank(vvarvecm(i,:))]; - end - end - stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,fnam, OutDir); - - % [pc,latent,explained] = pcacov(c0); - % %figure, bar([explained cumsum(explained)]) - % ifig=0; - % j2=0; - % for j=1:npar+nshock, - % i2=find(abs(pc(:,j))>alphaPC); - % if ~isempty(i2), - % j2=j2+1; - % if mod(j2,12)==1, - % ifig=ifig+1; - % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), - % end - % subplot(3,4,j2-(ifig-1)*12) - % bar(pc(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) - % end - % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, - % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) - % end - % end - % close all -end - -end \ No newline at end of file diff --git a/GSA_distrib/4.1/gamm_cdf.m b/GSA_distrib/4.1/gamm_cdf.m deleted file mode 100644 index a11d0962a..000000000 --- a/GSA_distrib/4.1/gamm_cdf.m +++ /dev/null @@ -1,27 +0,0 @@ -function cdf = gamm_cdf (x, a) -% PURPOSE: returns the cdf at x of the gamma(a) distribution -%--------------------------------------------------- -% USAGE: cdf = gamm_cdf(x,a) -% where: x = a vector -% a = a scalar gamma(a) -%--------------------------------------------------- -% RETURNS: -% a vector of cdf at each element of x of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_inv -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg - -if nargin ~= 2 -error('Wrong # of arguments to gamm_cdf'); -end; - -if any(any(a<=0)) - error('gamm_cdf: parameter a is wrong') -end - -cdf = gammainc(x,a); -I0 = find(x<0); -cdf(I0) = zeros(size(I0)); diff --git a/GSA_distrib/4.1/gamm_inv.m b/GSA_distrib/4.1/gamm_inv.m deleted file mode 100644 index 3bede95ba..000000000 --- a/GSA_distrib/4.1/gamm_inv.m +++ /dev/null @@ -1,50 +0,0 @@ -function x = gamm_inv(p,a,b) -% PURPOSE: returns the inverse of the cdf at p of the gamma(a,b) distribution -%--------------------------------------------------- -% USAGE: x = gamm_inv(p,a) -% where: p = a vector of probabilities -% a = a scalar parameter gamma(a) -% b = scaling factor for gamma -%--------------------------------------------------- -% RETURNS: -% a vector x of the quantile at each element of p of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_cdf -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to fit the format -% of the econometrics toolbox - - if (nargin < 2 | isempty(b)) - b=1; - end - - if (nargin > 3) - error('Wrong # of arguments to gamm_inv'); - end - - -if any(any(abs(2*p-1)>1)) - error('gamm_inv: a probability should be 0<=p<=1') -end -if any(any(a<=0)) - error('gamma_inv: parameter a is wrong') -end - -x = max(a-1,0.1); -dx = 1; -while any(any(abs(dx)>256*eps*max(x,1))) - dx = (gamm_cdf(x,a) - p) ./ gamm_pdf(x,a); - x = x - dx; - x = x + (dx - x) / 2 .* (x<0); -end - -I0 = find(p==0); -x(I0) = zeros(size(I0)); -I1 = find(p==1); -x(I1) = zeros(size(I0)) + Inf; - - -x=x.*b; diff --git a/GSA_distrib/4.1/gamm_pdf.m b/GSA_distrib/4.1/gamm_pdf.m deleted file mode 100644 index 86f4ffb1d..000000000 --- a/GSA_distrib/4.1/gamm_pdf.m +++ /dev/null @@ -1,27 +0,0 @@ -function f = gamm_pdf (x, a) -% PURPOSE: returns the pdf at x of the gamma(a) distribution -%--------------------------------------------------- -% USAGE: pdf = gamm_pdf(x,a) -% where: x = a vector -% a = a scalar for gamma(a) -%--------------------------------------------------- -% RETURNS: -% a vector of pdf at each element of x of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_cdf, gamm_rnd, gamm_inv -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg - -if nargin ~= 2 -error('Wrong # of arguments to gamm_cdf'); -end; - -if any(any(a<=0)) - error('gamm_pdf: parameter a is wrong') -end - -f = x .^ (a-1) .* exp(-x) ./ gamma(a); -I0 = find(x<0); -f(I0) = zeros(size(I0)); diff --git a/GSA_distrib/4.1/gsa.zip b/GSA_distrib/4.1/gsa.zip deleted file mode 100644 index 8a40d3f8f..000000000 Binary files a/GSA_distrib/4.1/gsa.zip and /dev/null differ diff --git a/GSA_distrib/4.1/log_trans_.m b/GSA_distrib/4.1/log_trans_.m deleted file mode 100644 index b0ff26ddf..000000000 --- a/GSA_distrib/4.1/log_trans_.m +++ /dev/null @@ -1,54 +0,0 @@ -function [yy, xdir, isig, lam]=log_trans_(y0,xdir0) - -if nargin==1, - xdir0=''; -end -f=inline('skewness(log(y+lam))','lam','y'); -isig=1; -if ~(max(y0)<0 | min(y0)>0) - if skewness(y0)<0, - isig=-1; - y0=-y0; - end - n=hist(y0,10); - if n(1)>20*n(end), - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))0 - %yy=log(y0); - xdir=[xdir0,'_log']; - end - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))1, - ifig=0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['Variance decomposition shocks']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(2,3,iplo) - myboxplot(squeeze(vdec(:,j,:))',[],'.',[],10) - % boxplot(squeeze(vdec(:,j,:))','whis',10,'symbol','.r') - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:size(options_.varobs,1)]) - set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5]) - set(gca,'ylim',[-2 102]) - for ip=1:size(options_.varobs,1), - text(ip,-4,deblank(options_.varobs(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - ylabel(' ') - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - saveas(gcf,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_vdec_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_vdec_exo_',int2str(ifig)]); - close(gcf), - end - end - end - for j=1:size(cc,1) - cc(j,j,:)=stand_(squeeze(log(cc(j,j,:))))./2; - end - [vdec, j0, ir_vdec, ic_vdec] = teff(vdec,Nsam,istable); - [cc, j0, ir_cc, ic_cc] = teff(cc,Nsam,istable); - [ac, j0, ir_ac, ic_ac] = teff(ac,Nsam,istable); - - [nr1, nc1, nnn] = size(T); - endo_nbr = M_.endo_nbr; - nstatic = oo_.dr.nstatic; - npred = oo_.dr.npred; - iv = (1:endo_nbr)'; - ic = [ nstatic+(1:npred) endo_nbr+(1:size(oo_.dr.ghx,2)-npred) ]'; - aux = oo_.dr.transition_auxiliary_variables; - k = find(aux(:,2) > npred); - aux(:,2) = aux(:,2) + nstatic; - aux(k,2) = aux(k,2) + oo_.dr.nfwrd; - - dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],1); - dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], 1); - [Aa,Bb] = kalman_transition_matrix(dr, ... - iv, ic, aux, M_.exo_nbr); -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux, M_.exo_nbr); - A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable)); - % Sig(estim_params_.var_exo(:,1))=lpmatx(1,:).^2; - set_shocks_param(lpmatx(1,:)); - A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; - for j=2:length(istable), - dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],j); - dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], j); - [Aa,Bb] = kalman_transition_matrix(dr, ... - iv, ic, aux, M_.exo_nbr); -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux, M_.exo_nbr); - set_shocks_param(lpmatx(j,:)); - A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; - end - clear T; - clear lpmatx; - - [nr,nc,nn]=size(A); - io=bayestopt_.mf2; - % T1=A(io,1:nr,:); - % ino=find(~ismember([1:nr],io)); - % T2=A(ino,1:nr,:); - R=A(:,nr+1:nc,:); -% [tadj, iff] = speed(A(1:nr,1:nr,:),R,io,0.5); -% [tadj, j0, ir_tadj, ic_tadj] = teff(tadj,Nsam,istable); -% [iff, j0, ir_if, ic_if] = teff(iff,Nsam,istable); - - - [yt, j0]=teff(A,Nsam,istable); - yt = [yys yt]; - if opt_gsa.morris==2, -% iii=find(std(yt(istable,:))>1.e-8); -% if max(max(abs(TAU-yt(istable,iii)')))<= 1.e-8, -% err = max(max(abs(TAU-yt(istable,iii)'))); -% disp(['Model check OK ',num2str(err)]), - clear TAU A -% end - else - clear A, - end - % [yt1, j01]=teff(T1,Nsam,istable); - % [yt2, j02]=teff(T2,Nsam,istable); - % [ytr, j0r]=teff(R,Nsam,istable); - % - % yt=[yt1 yt2 ytr]; - save([OutputDirectoryName,'/',fname_,'_main_eff'],'ac','cc','vdec','yt','mss') -else - if opt_gsa.morris==2, -% [pdraws, TAU, GAM] = dynare_identification([1:npT]); %,[lpmatx lpmat(istable,:)]); - [pdraws, TAU, GAM] = dynare_identification(options_.options_ident); - end - load([OutputDirectoryName,'/',fname_,'_main_eff'],'ac','cc','vdec','yt','mss') -end - -% for j=1:nr, -% for i=1:nc, -% y0=squeeze(A(j,i,:)); -% if max(y0)-min(y0)>1.e-10, -% j0=j0+1; -% y1=ones(size(lpmat,1),1)*NaN; -% y1(istable,1)=y0; -% yt(:,j0)=y1; -% end -% end -% end -% yt = yt(:,j0); - -if opt_gsa.morris==1, - %OutputDir = CheckPath('GSA/SCREEN'); - if ~isempty(vdec), - if opt_gsa.load_ident_files==0, - SAMorris = []; - for i=1:size(vdec,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv); - end - SAvdec = squeeze(SAMorris(:,1,:))'; - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') - end - - figure, -% boxplot(SAvdec,'whis',10,'symbol','r.') - myboxplot(SAvdec,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('All variance decomposition') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec']); - close(gcf) - else - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'vdec') - - end - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET variance decomposition observed variables']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],3) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); -% close(gcf) -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET variance decomposition shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],3) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - - if opt_gsa.load_ident_files==0, - SAMorris = []; - ccac = [mss cc ac]; - for i=1:size(ccac,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv); - end - SAcc = squeeze(SAMorris(:,1,:))'; - SAcc = SAcc./(max(SAcc')'*ones(1,npT)); - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc','-append') - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac','-append') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc') - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac') - end - - figure, -% boxplot(SAcc,'whis',10,'symbol','r.') - myboxplot(SAcc,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('EET All moments') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_moments']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_moments']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_moments']); -% close(gcf), - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% MORRIS FOR DERIVATIVES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% if opt_gsa.load_ident_files==0, -% for j=1:npT, -% SAMorris = []; -% ddd=NaN(size(lpmat,1),size(JJ,1)); -% ddd(istable,:) = squeeze(JJ(:,j,:))'; -% for i=1:size(ddd,2), -% [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ddd(:,i)],nliv); -% end -% SAddd(:,:,j) = squeeze(SAMorris(:,1,:))'; -% SAddd(:,:,j) = SAddd(:,:,j)./(max(SAddd(:,:,j)')'*ones(1,npT)); -% sad(:,j) = median(SAddd(find(~isnan(squeeze(SAddd(:,1,j)))),:,j))'; -% end -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad') -% end -% figure, -% contourf(sad,10), colorbar -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'yticklabel',' ','fontsize',10,'ytick',[1:npT]) -% for ip=1:npT, -% text(ip,0.9,['D(',bayestopt_.name{ip},')'],'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(0.9,ip,[bayestopt_.name{ip}],'rotation',0,'HorizontalAlignment','right','interpreter','none') -% end -% [m,im]=max(sad); -% iii = find((im-[1:npT])==0); -% disp('Most identified params') -% disp(bayestopt_.name(iii)) - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% END OF MORRIS FOR DERIVATIVES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET cross-correlations']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_cc==j); -% iv = [iv; find(ic_cc==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAcc(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAcc(iv,:),[],'.',[],3) -% else -% plot(SAcc(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_cc_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); -% close(gcf), -% end -% end - - -% if opt_gsa.load_ident_files==0, -% SAMorris = []; -% for i=1:size(ac,2), -% [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], ac(:,i),nliv); -% end -% %end -% SAac = squeeze(SAMorris(:,1,:))'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac') -% end -% figure, -% % boxplot(SAac,'whis',10,'symbol','r.') -% myboxplot(SAac,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('EET All auto-correlations') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac']); -% close(gcf), - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET auto-correlations']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_ac==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAac(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAac(iv,:),[],'.',[],3) -% else -% plot(SAac(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); -% close(gcf), -% end -% end - -% if opt_gsa.load_ident_files==0, -% js=0; -% %for j=1:size(tadj,1), -% SAMorris = []; -% for i=1:size(tadj,2), -% js=js+1; -% [SAmeas, SAMorris(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], tadj(:,i),nliv); -% end -% %end -% SAM = squeeze(SAMorris(nshock+1:end,1,:)); -% for j=1:js, -% SAtadj(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); -% end -% SAtadj = SAtadj'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj') -% end -% if opt_gsa.load_ident_files==0, -% js=0; -% SAMorris = []; -% for i=1:size(iff,2), -% js=js+1; -% [SAmeas, SAMorriss(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], iff(:,i),nliv); -% end -% SAM = squeeze(SAMorriss(nshock+1:end,1,:)); -% for j=1:js, -% SAIF(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); -% end -% SAIF = SAIF'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if') -% end -% figure, -% %bar(SAtadj), -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAtadj,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('All half-life') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj']); -% close(gcf), - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET speed of adjustment observed variables']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],3) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end - -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET speed of adjustment shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],3) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - -% figure, -% %bar(SAIF), -% % boxplot(SAIF,'whis',10,'symbol','r.') -% myboxplot(SAIF,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% ylabel('Elementary Effects') -% title('Steady state gains (impact factors)') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain']); -% close(gcf), - %figure, bar(SAIF'), title('All Gain Relationships') -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET steady state gain observed series']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAIF(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAIF(iv,:),[],'.',[],10) -% else -% plot(SAIF(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET steady state gain shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAIF(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAIF(iv,:),[],'.',[],3) -% else -% plot(SAIF(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - - if opt_gsa.load_ident_files==0, - SAMorris = []; - for j=1:j0, - [SAmeas, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv); - end - -% SAM = squeeze(SAMorris(nshock+1:end,1,:)); - SAM = squeeze(SAMorris(1:end,1,:)); - for j=1:j0 - SAnorm(:,j)=SAM(:,j)./max(SAM(:,j)); - irex(j)=length(find(SAnorm(:,j)>0.01)); - end - [dum, irel]=sort(irex); - -% SAMmu = squeeze(SAMorris(nshock+1:end,2,:)); - SAMmu = squeeze(SAMorris(1:end,2,:)); - for j=1:j0 - SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j)); % normalised w.r.t. mu* - end -% SAMsig = squeeze(SAMorris(nshock+1:end,3,:)); - SAMsig = squeeze(SAMorris(1:end,3,:)); - for j=1:j0 - SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j)); - end - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm','-append') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm') - end - figure, %bar(SAnorm(:,irel)) -% boxplot(SAnorm','whis',10,'symbol','r.') - myboxplot(SAnorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('Elementary effects in the model') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_par']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_par']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_par']); - - figure, %bar(SAmunorm(:,irel)) -% boxplot(SAmunorm','whis',10,'symbol','r.') - myboxplot(SAmunorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[-1 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('\mu in the model') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morrismu_par']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morrismu_par']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morrismu_par']); - close(gcf), - - figure, %bar(SAsignorm(:,irel)) -% boxplot(SAsignorm','whis',10,'symbol','r.') - myboxplot(SAsignorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('\sigma in the model') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morrissig_par']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morrissig_par']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morrissig_par']); - close(gcf), - - % figure, bar(SAnorm(:,irel)') - % set(gca,'xtick',[1:j0]) - % set(gca,'xlim',[0.5 j0+0.5]) - % title('Elementary effects relationships') - % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_redform']) - % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_redform']); - % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_redform']); - -elseif opt_gsa.morris==3, - np=estim_params_.np; - na=(4*np+1)*opt_gsa.Nsam; - for j=1:j0, - [idex(j,:), yd(j,:)] = spop_ide(lpmat, yt(:,j), opt_gsa.Nsam, 5-1); - end - iok=find(~isnan(yt(1:opt_gsa.Nsam,1))); - yr=NaN*ones(size(lpmat,1),j0); - for j=1:j0, - ys(j,:)=yd(j,:)./max(yd(j,:)); - [dum, is]=sort(yt(iok,j)); - yr(iok(is),j)=[1:length(iok)]'./length(iok); - yr(istable(length(iok)+1:end),j) = interp1(yt(iok,j),yr(iok,j),yt(istable(length(iok)+1:end),j),'','extrap'); - ineg=find(yr(:,j)<0); - if any(ineg), - [dum, is]=sort(yr(ineg,j)); - yr(ineg(is),j)=-[length(ineg):-1:1]./length(iok); - - end - [idex_r(j,:), yd_r(j,:)] = spop_ide(lpmat, yr(:,j), opt_gsa.Nsam, 5-1); - ys_r(j,:)=yd_r(j,:)./max(yd_r(j,:)); - - end, - figure, bar((idex.*ys)./opt_gsa.Nsam), title('Relationships') - figure, bar((idex.*ys)'./opt_gsa.Nsam), title('Parameters') - figure, bar((idex_r.*ys_r)./opt_gsa.Nsam), title('Relationships rank') - figure, bar((idex_r.*ys_r)'./opt_gsa.Nsam), title('Parameters rank') - [v0,d0]=eig(corrcoef(yt(iok,:))); - ee=diag(d0); - ee=ee([end:-1:1])./j0; - i0=length(find(ee>0.01)); - v0=v0(:,[end:-1:1]); - for j=1:i0, - [idex_pc(j,:), yd_pc(j,:)] = spop_ide(lpmat, yt*v0(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:i0, - ys_pc(j,:)=yd_pc(j,:)./max(yd_pc(j,:)); - end, - figure, bar((idex_pc.*ys_pc)./opt_gsa.Nsam), title('Relationships PCA') - figure, bar((idex_pc.*ys_pc)'./opt_gsa.Nsam), title('Parameters PCA') - - [vr,dr]=eig(corrcoef(yr(iok,:))); - er=diag(dr); - er=er([end:-1:1])./j0; - ir0=length(find(er>0.01)); - vr=vr(:,[end:-1:1]); - for j=1:ir0, - [idex_pcr(j,:), yd_pcr(j,:)] = spop_ide(lpmat, yr*vr(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:ir0, - ys_pcr(j,:)=yd_pcr(j,:)./max(yd_pcr(j,:)); - end, - figure, bar((idex_pcr.*ys_pcr)./opt_gsa.Nsam), title('Relationships rank PCA') - figure, bar((idex_pcr.*ys_pcr)'./opt_gsa.Nsam), title('Parameters rank PCA') - -elseif opt_gsa.morris==2, % ISKREV staff - return, - - -else, % main effects analysis - - if itrans==0, - fsuffix = ''; - elseif itrans==1, - fsuffix = '_log'; - else - fsuffix = '_rank'; - end - - imap=[1:npT]; - - x0=[lpmat0(istable,:), lpmat(istable,:)]; - nrun=length(istable); - nest=min(250,nrun); - nfit=min(1000,nrun); - -% opt_gsa.load_ident_files=0; - -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec'); -% catch -% EET=[]; -% end -% SAvdec=zeros(size(vdec,2),npT); -% -% for j=1:size(vdec,2), -% if itrans==0, -% y0 = vdec(istable,j); -% elseif itrans==1, -% y0 = log_trans_(vdec(istable,j)); -% else -% y0 = trank(vdec(istable,j)); -% end -% if ~isempty(EET), -% % imap=find(EET.SAvdec(j,:)); -% % [dum, isort]=sort(-EET.SAvdec(j,:)); -% imap=find(EET.SAvdec(j,:) >= (0.1.*max(EET.SAvdec(j,:))) ); -% end -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); -% end -% -% SAvdec(j,imap)=gsa_(j).si; -% imap_vdec{j}=imap; -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec') -% end -% figure, -% % boxplot(SAvdec,'whis',10,'symbol','r.') -% myboxplot(SAvdec,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects variance decomposition ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed variance decomposition ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],10) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks variance decomposition ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],10) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',3,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(M_.exo_names(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==M_.exo_nbr -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - if opt_gsa.load_ident_files==0, - try - EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAcc','ir_cc','ic_cc'); - catch - EET=[]; - end - ccac = stand_([mss cc ac]); - [pcc, dd] = eig(cov(ccac(istable,:))); - [latent, isort] = sort(-diag(dd)); - latent = -latent; - figure, bar(latent) - title('Eigenvalues in PCA') - pcc=pcc(:,isort); - ccac = ccac*pcc; -% npca = min(40, max(find(cumsum(latent)./length(latent)<0.99))+1); - npca = max(find(cumsum(latent)./length(latent)<0.99))+1; - siPCA = (EET.SAcc'*abs(pcc'))'; -% siPCA = siPCA./(max(siPCA')'*ones(1,npT)).*(latent*ones(1,npT)); - siPCA = siPCA./(max(siPCA')'*ones(1,npT)); -% siPCA = sum(siPCA,1); -% siPCA = siPCA./max(siPCA); - SAcc=zeros(size(ccac,2),npT); - for j=1:npca, %size(ccac,2), - if itrans==0, - y0 = ccac(istable,j); - elseif itrans==1, - y0 = log_trans_(ccac(istable,j)); - else - y0 = trank(ccac(istable,j)); - end - if ~isempty(EET), -% imap=find(EET.SAvdec(j,:)); -% [dum, isort]=sort(-EET.SAvdec(j,:)); - imap=find(siPCA(j,:) >= (0.1.*max(siPCA(j,:))) ); -% imap=find(EET.SAcc(j,:) >= (0.1.*max(EET.SAcc(j,:))) ); - end - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); -% end - SAcc(j,imap)=gsa_(j).si; - imap_cc{j}=imap; - - end - save([OutputDirectoryName,'/map_cc',fsuffix],'gsa_') - save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac','-append') - else - load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac') - - end -% figure, -% % boxplot(SAcc,'whis',10,'symbol','r.') -% myboxplot(SAcc,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% ylabel(' ') -% title(['Main effects moments''s PCA ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% close(gcf), - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects cross-covariances ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_cc==j); -% iv = [iv; find(ic_cc==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAcc(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAcc(iv,:),[],'.',[],10) -% else -% plot(SAcc(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(options_.varobs(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix,'_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAac','ir_ac','ic_ac'); -% catch -% EET=[]; -% end -% SAac=zeros(size(ac,2),npT); -% for j=1:size(ac,2), -% if itrans==0, -% y0 = ac(istable,j); -% elseif itrans==1, -% y0 = log_trans_(ac(istable,j)); -% else -% y0 = trank(ac(istable,j)); -% end -% if ~isempty(EET), -% imap=find(EET.SAac(j,:) >= (0.1.*max(EET.SAac(j,:))) ); -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% end -% SAac(j,imap)=gsa_(j).si; -% imap_ac{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac') -% end -% -% figure, -% % boxplot(SAac,'whis',10,'symbol','r.') -% myboxplot(SAac,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects 1 lag auto-covariances ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects auto-covariances ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_ac==j); -% %iv = [iv; find(ic_ac==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAac(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAac(iv,:),[],'.',[],10) -% else -% plot(SAac(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(options_.varobs(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix,'_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); -% close(gcf), -% end -% end - -% x0=x0(:,nshock+1:end); - imap=[1:npT]; - -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAtadj','ir_tadj','ic_tadj'); -% ny=size(EET.SAtadj,1); -% catch -% EET=[]; -% end -% SAtadj=zeros(size(tadj,2),np); -% for j=1:size(tadj,2), -% if itrans==0, -% y0 = tadj(istable,j); -% elseif itrans==1, -% y0 = log_trans_(tadj(istable,j)); -% else -% y0 = trank(tadj(istable,j)); -% end -% if ~isempty(EET), -% if size(tadj,2)~=ny, -% jj=find(EET.ir_tadj==ir_tadj(j)); -% jj=jj(find(EET.ic_tadj(jj)==ic_tadj(j))); -% if ~isempty(jj), -% imap=find(EET.SAtadj(jj,:) >= (0.1.*max(EET.SAtadj(jj,:))) ); -% else -% imap=[1:np]; -% end -% else -% imap=find(EET.SAtadj(j,:) >= (0.1.*max(EET.SAtadj(j,:))) ); -% end -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% end -% SAtadj(j,imap)=gsa_(j).si; -% imap_tadj{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj') -% end -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAtadj,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects speed of adjustment ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed speed adjustment ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],10) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks speed of adjustment ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],10) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAIF','ir_if','ic_if'); -% catch -% EET=[]; -% end -% SAif=zeros(size(iff,2),np); -% for j=1:size(iff,2), -% if itrans==0, -% y0 = iff(istable,j); -% elseif itrans==1, -% y0 = log_trans_(iff(istable,j)); -% else -% y0 = trank(iff(istable,j)); -% end -% if ~isempty(EET), -% imap=find(EET.SAIF(j,:) >= (0.1.*max(EET.SAIF(j,:))) ); -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% end -% SAif(j,imap)=gsa_(j).si; -% imap_if{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if') -% end -% -% figure, -% % boxplot(SAif,'whis',10,'symbol','r.') -% myboxplot(SAif,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects impact factors ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed impact factors ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAif(iv,:),[],'.',[],10) -% else -% plot(SAif(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks impact factors ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAif(iv,:),[],'.',[],10) -% else -% plot(SAif(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end -% SAmom = [SAvdec' SAcc' SAac']'; -% SAdyn = [SAtadj' SAif']'; -% SAall = [SAmom(:,nshock+1:end)' SAdyn']'; -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAmom,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects theoretical moments ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_moments',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% % close(gcf), -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAdyn,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects short-long term dynamics ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_dynamics',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); -% % close(gcf), -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAall,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects all ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ALL',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); -% % close(gcf), - -% for j=1:size(SAall,1), -% SAallN(j,:)=SAall(j,:)./max(SAall(j,:)); -% end -% SAmean=mean(SAallN); -% for j=1:size(SAmom,1), -% SAmomN(j,:)=SAmom(j,1:nshock)./max(SAmom(j,1:nshock)); -% end -% SAmomN(find(isnan(SAmomN)))=0; -% SAmeanexo=mean(SAmomN(:,1:nshock)); - -% figure, bar(latent'*SAcc), - figure, bar(sum(SAcc)), - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Identifiability indices in the ',fsuffix,' moments.'],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_ALL',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_ALL',fsuffix]); - -% figure, bar(SAmeanexo), -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:nshock]) -% set(gca,'xlim',[0.5 nshock+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:nshock, -% % text(ip,-0.02*(ydum(2)),deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Identifiability indices for shocks',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_SHOCKS',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); -end - -return diff --git a/GSA_distrib/4.1/mc_moments.m b/GSA_distrib/4.1/mc_moments.m deleted file mode 100644 index 0f38ff6a6..000000000 --- a/GSA_distrib/4.1/mc_moments.m +++ /dev/null @@ -1,25 +0,0 @@ -function [vdec, cc, ac] = mc_moments(mm, ss, dr) -global options_ M_ - - [nr1, nc1, nsam] = size(mm); - disp('Computing theoretical moments ...') - h = waitbar(0,'Theoretical moments ...'); - - for j=1:nsam, - dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j); - dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j); - if ~isempty(ss), - set_shocks_param(ss(j,:)); - end - [vdec(:,:,j), corr, autocorr, z, zz] = th_moments(dr,options_.varobs); - cc(:,:,j)=triu(corr); - dum=[]; - for i=1:options_.ar - dum=[dum, autocorr{i}]; - end - ac(:,:,j)=dum; - waitbar(j/nsam,h) - end - close(h) - disp(' ') - disp('... done !') diff --git a/GSA_distrib/4.1/myboxplot.m b/GSA_distrib/4.1/myboxplot.m deleted file mode 100644 index 096d1a854..000000000 --- a/GSA_distrib/4.1/myboxplot.m +++ /dev/null @@ -1,158 +0,0 @@ - -function sout = myboxplot (data,notched,symbol,vertical,maxwhisker) - -% sout = myboxplot (data,notched,symbol,vertical,maxwhisker) - -% % % % endif -if nargin < 5 | isempty(maxwhisker), maxwhisker = 1.5; end -if nargin < 4 | isempty(vertical), vertical = 1; end -if nargin < 3 | isempty(symbol), symbol = ['+','o']; end -if nargin < 2 | isempty(notched), notched = 0; end - -if length(symbol)==1, symbol(2)=symbol(1); end - -if notched==1, notched=0.25; end -a=1-notched; - -% ## figure out how many data sets we have -if iscell(data), - nc = length(data); -else -% if isvector(data), data = data(:); end - nc = size(data,2); -end - -% ## compute statistics -% ## s will contain -% ## 1,5 min and max -% ## 2,3,4 1st, 2nd and 3rd quartile -% ## 6,7 lower and upper confidence intervals for median -s = zeros(7,nc); -box = zeros(1,nc); -whisker_x = ones(2,1)*[1:nc,1:nc]; -whisker_y = zeros(2,2*nc); -outliers_x = []; -outliers_y = []; -outliers2_x = []; -outliers2_y = []; - -for i=1:nc - % ## Get the next data set from the array or cell array - if iscell(data) - col = data{i}(:); - else - col = data(:,i); - end -% ## Skip missing data -% % % % % % % col(isnan(col) | isna (col)) = []; - col(isnan(col)) = []; - - % ## Remember the data length - nd = length(col); - box(i) = nd; - if (nd > 1) -% ## min,max and quartiles -% s(1:5,i) = statistics(col)(1:5); -s(1,i)=min(col); -s(5,i)=max(col); -s(2,i)=myprctilecol(col,25); -s(3,i)=myprctilecol(col,50); -s(4,i)=myprctilecol(col,75); - - - - - - - - -% ## confidence interval for the median - est = 1.57*(s(4,i)-s(2,i))/sqrt(nd); - s(6,i) = max([s(3,i)-est, s(2,i)]); - s(7,i) = min([s(3,i)+est, s(4,i)]); -% ## whiskers out to the last point within the desired inter-quartile range - IQR = maxwhisker*(s(4,i)-s(2,i)); - whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)]; - whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)]; -% ## outliers beyond 1 and 2 inter-quartile ranges - outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR)); - outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR); - outliers_x = [outliers_x; i*ones(size(outliers))]; - outliers_y = [outliers_y; outliers]; - outliers2_x = [outliers2_x; i*ones(size(outliers2))]; - outliers2_y = [outliers2_y; outliers2]; - elseif (nd == 1) -% ## all statistics collapse to the value of the point - s(:,i) = col; -% ## single point data sets are plotted as outliers. - outliers_x = [outliers_x; i]; - outliers_y = [outliers_y; col]; - else -% ## no statistics if no points - s(:,i) = NaN; - end -end -% % % % if isempty(outliers2_y) -% % % % outliers2_y= -% ## Note which boxes don't have enough stats -chop = find(box <= 1); - -% ## Draw a box around the quartiles, with width proportional to the number of -% ## items in the box. Draw notches if desired. -box = box*0.23/max(box); -quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box; -quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:); - -% ## Draw a line through the median -median_x = ones(2,1)*[1:nc] + [-a;+a]*box; -% median_x=median(col); -median_y = s([3,3],:); - -% ## Chop all boxes which don't have enough stats -quartile_x(:,chop) = []; -quartile_y(:,chop) = []; -whisker_x(:,[chop,chop+nc]) = []; -whisker_y(:,[chop,chop+nc]) = []; -median_x(:,chop) = []; -median_y(:,chop) = []; -% % % % -% ## Add caps to the remaining whiskers -cap_x = whisker_x; -cap_x(1,:) =cap_x(1,:)- 0.05; -cap_x(2,:) =cap_x(2,:)+ 0.05; -cap_y = whisker_y([1,1],:); - -% #quartile_x,quartile_y -% #whisker_x,whisker_y -% #median_x,median_y -% #cap_x,cap_y -% -% ## Do the plot - -mm=min(min(data)); -MM=max(max(data)); - -if vertical - plot (quartile_x, quartile_y, 'b', ... - whisker_x, whisker_y, 'b--', ... - cap_x, cap_y, 'k', ... - median_x, median_y, 'r', ... - outliers_x, outliers_y, [symbol(1),'r'], ... - outliers2_x, outliers2_y, [symbol(2),'r']); - set(gca,'XTick',1:nc); - set(gca, 'XLim', [0.5, nc+0.5]); - set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]); - -else -% % % % % plot (quartile_y, quartile_x, "b;;", -% % % % % whisker_y, whisker_x, "b;;", -% % % % % cap_y, cap_x, "b;;", -% % % % % median_y, median_x, "r;;", -% % % % % outliers_y, outliers_x, [symbol(1),"r;;"], -% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]); -end - -if nargout, - sout=s; -end -% % % endfunction \ No newline at end of file diff --git a/GSA_distrib/4.1/myprctilecol.m b/GSA_distrib/4.1/myprctilecol.m deleted file mode 100644 index d99d5ad50..000000000 --- a/GSA_distrib/4.1/myprctilecol.m +++ /dev/null @@ -1,20 +0,0 @@ -function y = myprctilecol(x,p); -xx = sort(x); -[m,n] = size(x); - -if m==1 | n==1 - m = max(m,n); - if m == 1, - y = x*ones(length(p),1); - return; - end - n = 1; - q = 100*(0.5:m - 0.5)./m; - xx = [min(x); xx(:); max(x)]; -else - q = 100*(0.5:m - 0.5)./m; - xx = [min(x); xx; max(x)]; -end - -q = [0 q 100]; -y = interp1(q,xx,p); \ No newline at end of file diff --git a/GSA_distrib/4.1/norm_inv.m b/GSA_distrib/4.1/norm_inv.m deleted file mode 100644 index e676be94e..000000000 --- a/GSA_distrib/4.1/norm_inv.m +++ /dev/null @@ -1,49 +0,0 @@ -function invp = norm_inv(x, m, sd) -% PURPOSE: computes the quantile (inverse of the CDF) -% for each component of x with mean m, standard deviation sd -%--------------------------------------------------- -% USAGE: invp = norm_inv(x,m,v) -% where: x = variable vector (nx1) -% m = mean vector (default=0) -% sd = standard deviation vector (default=1) -%--------------------------------------------------- -% RETURNS: invp (nx1) vector -%--------------------------------------------------- -% SEE ALSO: norm_d, norm_rnd, norm_inv, norm_cdf -%--------------------------------------------------- - -% Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Oct 26, 1994 -% Copyright Dept of Probability Theory and Statistics TU Wien -% Converted to MATLAB by JP LeSage, jpl@jpl.econ.utoledo.edu - - if nargin > 3 - error ('Wrong # of arguments to norm_inv'); - end - - [r, c] = size (x); - s = r * c; - - if (nargin == 1) - m = zeros(1,s); - sd = ones(1,s); - end - - - if length(m)==1, - m = repmat(m,1,s); - end - if length(sd)==1, - sd = repmat(sd,1,s); - end - x = reshape(x,1,s); - m = reshape(m,1,s); - sd = reshape(sd,1,s); - - invp = zeros (1,s); - - invp = m + sd .* (sqrt(2) * erfinv(2 * x - 1)); - - - - invp = reshape (invp, r, c); - diff --git a/GSA_distrib/4.1/optget.m b/GSA_distrib/4.1/optget.m deleted file mode 100644 index b2893e2ce..000000000 --- a/GSA_distrib/4.1/optget.m +++ /dev/null @@ -1,39 +0,0 @@ -% OPTGET Utility to get previously set function default values -% USAGE -% optvalue=optget(funcname,optname,optvalue); -% INPUTS -% funcname : name of function -% optname : name of option -% optval : option value -% OUTPUT -% optval : the current value of the option -% -% If the named field is not already defined, it will be set to -% optvalue, but optvalue has no effect if the field has already -% been set. Use OPTSET to change a previously set field. -% -% optget(funcname) returns the current values of the options structure. - -% Copyright (c) 1997-2000, Paul L. Fackler & Mario J. Miranda -% paul_fackler@ncsu.edu, miranda.4@osu.edu - -function optvalue = optget(funcname,optname,optvalue) - -funcname = lower(funcname); -optvar=[funcname '_options']; -eval(['global ' optvar]) % declare a global variable - -if nargin==1 % return the whole option structure - optvalue=(eval(optvar)); - return -end - -optname = lower(optname); -% if structure is empty or the named field does not exist -% set to the value passed -if isempty(eval(optvar)) | ~isfield(eval(optvar),optname) - eval([optvar '.' optname '=optvalue;']); -% otherwise return the value in the field -else - optvalue = eval([optvar '.' optname]); -end diff --git a/GSA_distrib/4.1/prior_draw_gsa.m b/GSA_distrib/4.1/prior_draw_gsa.m deleted file mode 100644 index 278e1e237..000000000 --- a/GSA_distrib/4.1/prior_draw_gsa.m +++ /dev/null @@ -1,105 +0,0 @@ -function pdraw = prior_draw_gsa(init,rdraw) -% Draws from the prior distributions -% Adapted by M. Ratto from prior_draw (of DYNARE, copyright M. Juillard), -% for use with Sensitivity Toolbox for DYNARE -% -% -% INPUTS -% o init [integer] scalar equal to 1 (first call) or 0. -% o rdraw -% -% OUTPUTS -% o pdraw [double] draw from the joint prior density. -% -% ALGORITHM -% ... -% -% SPECIAL REQUIREMENTS -% MATLAB Statistics Toolbox -% -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -% global M_ options_ estim_params_ bayestopt_ -global bayestopt_ -persistent npar pshape p6 p7 p3 p4 lbcum ubcum - -if init - pshape = bayestopt_.pshape; - p6 = bayestopt_.p6; - p7 = bayestopt_.p7; - p3 = bayestopt_.p3; - p4 = bayestopt_.p4; - npar = length(p6); - pdraw = zeros(npar,1); - lbcum = zeros(npar,1); - ubcum = ones(npar,1); - - % set bounds for cumulative probabilities - for i = 1:npar - switch pshape(i) - case 5% Uniform prior. - p4(i) = min(p4(i),bayestopt_.ub(i)); - p3(i) = max(p3(i),bayestopt_.lb(i)); - case 3% Gaussian prior. - lbcum(i) = 0.5 * erfc(-(bayestopt_.lb(i)-p6(i))/p7(i) ./ sqrt(2));; - ubcum(i) = 0.5 * erfc(-(bayestopt_.ub(i)-p6(i))/p7(i) ./ sqrt(2));; - case 2% Gamma prior. - lbcum(i) = gamm_cdf((bayestopt_.lb(i)-p3(i))/p7(i),p6(i)); - ubcum(i) = gamm_cdf((bayestopt_.ub(i)-p3(i))/p7(i),p6(i)); - case 1% Beta distribution (TODO: generalized beta distribution) - lbcum(i) = betainc((bayestopt_.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); - ubcum(i) = betainc((bayestopt_.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); - case 4% INV-GAMMA1 distribution - % TO BE CHECKED - lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i))^2)/(2/p6(i)),p7(i)/2); - ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i))^2)/(2/p6(i)),p7(i)/2); - case 6% INV-GAMMA2 distribution - % TO BE CHECKED - lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i)))/(2/p6(i)),p7(i)/2); - ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i)))/(2/p6(i)),p7(i)/2); - otherwise - % Nothing to do here. - end - end - return -end - - -for i = 1:npar - rdraw(:,i) = rdraw(:,i).*(ubcum(i)-lbcum(i))+lbcum(i); - switch pshape(i) - case 5% Uniform prior. - pdraw(:,i) = rdraw(:,i)*(p4(i)-p3(i)) + p3(i); - case 3% Gaussian prior. - pdraw(:,i) = norm_inv(rdraw(:,i),p6(i),p7(i)); - case 2% Gamma prior. - pdraw(:,i) = gamm_inv(rdraw(:,i),p6(i),p7(i))+p3(i); - case 1% Beta distribution (TODO: generalized beta distribution) - pdraw(:,i) = beta_inv(rdraw(:,i),p6(i),p7(i))*(p4(i)-p3(i))+p3(i); - case 4% INV-GAMMA1 distribution - % TO BE CHECKED - pdraw(:,i) = sqrt(1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i)))+p3(i); - case 6% INV-GAMMA2 distribution - % TO BE CHECKED - pdraw(:,i) = 1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i))+p3(i); - otherwise - % Nothing to do here. - end -end - - diff --git a/GSA_distrib/4.1/priorcdf.m b/GSA_distrib/4.1/priorcdf.m deleted file mode 100644 index 53d8ec34d..000000000 --- a/GSA_distrib/4.1/priorcdf.m +++ /dev/null @@ -1,50 +0,0 @@ -function [xcum] = priorcdf(para, pshape, p6, p7, p3, p4) -% This procedure transforms x vectors into cumulative values -% pshape: 0 is point mass, both para and p2 are ignored -% 1 is BETA(mean,stdd) -% 2 is GAMMA(mean,stdd) -% 3 is NORMAL(mean,stdd) -% 4 is INVGAMMA(s^2,nu) -% 5 is UNIFORM [p1,p2] -% Adapted by M. Ratto from MJ priordens.m - -nprio = length(pshape); - -i = 1; -while i <= nprio; - a = 0; - b = 0; - if pshape(i) == 1; % (generalized) BETA Prior -% mu = (p1(i)-p3(i))/(p4(i)-p3(i)); -% stdd = p2(i)/(p4(i)-p3(i)); -% a = (1-mu)*mu^2/stdd^2 - mu; -% b = a*(1/mu - 1); - %lnprior = lnprior + lpdfgbeta(para(i),a,b,p3(i),p4(i)) ; - para(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i)); -% xcum(:,i) = betacdf(para(:,i),a,b) ; - xcum(:,i) = betainc(para(:,i),p6(i),p7(i)); - elseif pshape(i) == 2; % GAMMA PRIOR -% b = p2(i)^2/(p1(i)-p3(i)); -% a = (p1(i)-p3(i))/b; - %lnprior = lnprior + lpdfgam(para(i)-p3(i),a,b); -% xcum(:,i) = gamcdf(para(:,i)-p3(i),a,b); - xcum(:,i) = gamm_cdf((para(:,i)-p3(i))./p7(i),p6(i)); - elseif pshape(i) == 3; % GAUSSIAN PRIOR - %lnprior = lnprior + lpdfnorm(para(i),p1(i),p2(i)); -% xcum(:,i) = normcdf(para(:,i),p1(i),p2(i)); - xcum(:,i) = 0.5 * erfc(-(para(:,i)-p6(i))/p7(i) ./ sqrt(2)); - elseif pshape(i) == 4; % INVGAMMA1 PRIOR - %lnprior = lnprior + lpdfig1(para(i),p1(i),p2(i)); -% xcum(:,i) = gamcdf(1/para(:,i).^2,p2(i)/2,2/p1(i)); - xcum(:,i) = gamm_cdf((1./(para(:,i)-p3(i)).^2)/(2/p6(i)),p7(i)/2); - elseif pshape(i) == 5; % UNIFORM PRIOR - %lnprior = lnprior + log(1/(p2(i)-p1(i))); - xcum(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i)); - elseif pshape(i) == 6; % INVGAMMA2 PRIOR -% lnprior = lnprior + lpdfig2(para(i),p1(i),p2(i)); -% xcum(:,i) = gamcdf(1/para(:,i),p2(i)/2,2/p1(i)); - xcum(:,i) = gamm_cdf((1./(para(:,i)-p3(i)))./(2/p6(i)),p7(i)/2); - end; - i = i+1; -end; - diff --git a/GSA_distrib/4.1/read_data.m b/GSA_distrib/4.1/read_data.m deleted file mode 100644 index f54f66cb6..000000000 --- a/GSA_distrib/4.1/read_data.m +++ /dev/null @@ -1,39 +0,0 @@ -function [gend, data] = read_data -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global options_ bayestopt_ - -rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); - -options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1); -gend = options_.nobs; - -rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); -if options_.loglinear == 1 & ~options_.logdata - rawdata = log(rawdata); -end -if options_.prefilter == 1 - bayestopt_.mean_varobs = mean(rawdata,1); - data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs); -else - data = transpose(rawdata); -end - -if ~isreal(rawdata) - error(['There are complex values in the data. Probably a wrong' ... - ' transformation']) -end diff --git a/GSA_distrib/4.1/redform_map.m b/GSA_distrib/4.1/redform_map.m deleted file mode 100644 index 2350c5993..000000000 --- a/GSA_distrib/4.1/redform_map.m +++ /dev/null @@ -1,351 +0,0 @@ -function redform_map(dirname) -%function redform_map(dirname) -% inputs (from opt_gsa structure -% anamendo = options_gsa_.namendo; -% anamlagendo = options_gsa_.namlagendo; -% anamexo = options_gsa_.namexo; -% iload = options_gsa_.load_redform; -% pprior = options_gsa_.pprior; -% ilog = options_gsa_.logtrans_redform; -% threshold = options_gsa_.threshold_redform; -% ksstat = options_gsa_.ksstat_redform; -% alpha2 = options_gsa_.alpha2_redform; -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ oo_ estim_params_ options_ bayestopt_ - -options_gsa_ = options_.opt_gsa; - -anamendo = options_gsa_.namendo; -anamlagendo = options_gsa_.namlagendo; -anamexo = options_gsa_.namexo; -iload = options_gsa_.load_redform; -pprior = options_gsa_.pprior; -ilog = options_gsa_.logtrans_redform; -threshold = options_gsa_.threshold_redform; -ksstat = options_gsa_.ksstat_redform; -alpha2 = options_gsa_.alpha2_redform; - -pnames = M_.param_names(estim_params_.param_vals(:,1),:); -if nargin==0, - dirname=''; -end - -if pprior - load([dirname,'/',M_.fname,'_prior']); - adir=[dirname '/redform_stab']; -else - load([dirname,'/',M_.fname,'_mc']); - adir=[dirname '/redform_mc']; -end -if ~exist('T') - stab_map_(dirname); -if pprior - load([dirname,'/',M_.fname,'_prior'],'T'); -else - load([dirname,'/',M_.fname,'_mc'],'T'); -end -end -if isempty(dir(adir)) - mkdir(adir) -end -adir0=pwd; -%cd(adir) - -nspred=size(T,2)-M_.exo_nbr; -x0=lpmat(istable,:); -[kn, np]=size(x0); -offset = length(bayestopt_.pshape)-np; -if options_gsa_.prior_range, - pshape=5*(ones(np,1)); - pd = [NaN(np,1) NaN(np,1) bayestopt_.lb(offset+1:end) bayestopt_.ub(offset+1:end)]; -else - pshape = bayestopt_.pshape(offset+1:end); - pd = [bayestopt_.p6(offset+1:end) bayestopt_.p7(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)]; -end - -nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:))); -clear lpmat lpmat0 egg iunstable yys -js=0; -for j=1:size(anamendo,1) - namendo=deblank(anamendo(j,:)); - iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact'); - ifig=0; - iplo=0; - for jx=1:size(anamexo,1) - namexo=deblank(anamexo(jx,:)); - iexo=strmatch(namexo,M_.exo_names,'exact'); - - if ~isempty(iexo), - %y0=squeeze(T(iendo,iexo+nspred,istable)); - y0=squeeze(T(iendo,iexo+nspred,:)); - if (max(y0)-min(y0))>1.e-10, - if mod(iplo,9)==0, - ifig=ifig+1; - hfig = figure('name',[namendo,' vs. shocks ',int2str(ifig)]); - iplo=0; - end - iplo=iplo+1; - js=js+1; - xdir0 = [adir,'/',namendo,'_vs_', namexo]; - if ilog==0, - if isempty(threshold) - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namexo, xdir0); - else - iy=find( (y0>threshold(1)) & (y0=threshold(2))); - xdir = [xdir0,'_cut']; - if ~isempty(iy), - si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir); - end - if ~isempty(iy) & ~isempty(iyc) - delete([xdir, '/*cut*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0); - indsmirnov = find(dproba>ksstat); - stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir); - stab_map_2(x0(iy,:),alpha2,'cut',xdir) - stab_map_2(x0(iyc,:),alpha2,'trim',xdir) - end - end - else - [yy, xdir] = log_trans_(y0,xdir0); - silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namexo, xdir); - end - - figure(hfig) - subplot(3,3,iplo), - if ilog, - [saso, iso] = sort(-silog(:,js)); - bar([silog(iso(1:min(np,10)),js)]) - logflag='log'; - else - [saso, iso] = sort(-si(:,js)); - bar(si(iso(1:min(np,10)),js)) - logflag=''; - end - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([logflag,' ',namendo,' vs. ',namexo],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - close(gcf) - end - - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - close(gcf) - end - ifig=0; - iplo=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - %y0=squeeze(T(iendo,ilagendo,istable)); - y0=squeeze(T(iendo,ilagendo,:)); - if (max(y0)-min(y0))>1.e-10, - if mod(iplo,9)==0, - ifig=ifig+1; - hfig = figure('name',[namendo,' vs. lags ',int2str(ifig)]); - iplo=0; - end - iplo=iplo+1; - js=js+1; - xdir0 = [adir,'/',namendo,'_vs_', namlagendo]; - if ilog==0, - if isempty(threshold) - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namlagendo, xdir0); - else - iy=find( (y0>threshold(1)) & (y0=threshold(2))); - xdir = [xdir0,'_cut']; - if ~isempty(iy) - si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir); - end - if ~isempty(iy) & ~isempty(iyc), - delete([xdir, '/*cut*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0); - indsmirnov = find(dproba>ksstat); - stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir); - stab_map_2(x0(iy,:),alpha2,'cut',xdir) - stab_map_2(x0(iyc,:),alpha2,'trim',xdir) - end - end - else - [yy, xdir] = log_trans_(y0,xdir0); - silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namlagendo, xdir); - end - - figure(hfig), - subplot(3,3,iplo), - if ilog, - [saso, iso] = sort(-silog(:,js)); - bar([silog(iso(1:min(np,10)),js)]) - logflag='log'; - else - [saso, iso] = sort(-si(:,js)); - bar(si(iso(1:min(np,10)),js)) - logflag=''; - end - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([logflag,' ',namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - close(gcf) - end - - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - close(gcf) - end -end - -if ilog==0, -figure, %bar(si) -% boxplot(si','whis',10,'symbol','r.') -myboxplot(si',[],'.',[],10) -xlabel(' ') -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -title('Reduced form GSA') - -saveas(gcf,[dirname,'/',M_.fname,'_redform_gsa']) -eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_gsa']); -eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_gsa']); - -else -figure, %bar(silog) -% boxplot(silog','whis',10,'symbol','r.') -myboxplot(silog',[],'.',[],10) -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -xlabel(' ') -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -title('Reduced form GSA - Log-transformed elements') - -saveas(gcf,[dirname,'/',M_.fname,'_redform_gsa_log']) -eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_gsa_log']); -eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_gsa_log']); - -end -function si = redform_private(x0, y0, pshape, pd, iload, pnames, namy, namx, xdir) -global bayestopt_ options_ - -opt_gsa=options_.opt_gsa; -np=size(x0,2); -x00=x0; - if opt_gsa.prior_range, - for j=1:np, - x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3)); - end - else - x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4)); - end - -fname=[xdir,'/map']; -if iload==0, - figure, hist(y0,30), title([namy,' vs. ', namx]) - if isempty(dir(xdir)) - mkdir(xdir) - end - saveas(gcf,[xdir,'/', namy,'_vs_', namx]) - eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx]); - eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx]); - close(gcf) -% gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames); - nrun=length(y0); - nest=min(250,nrun); - nfit=min(1000,nrun); -% dotheplots = (nfit<=nest); - gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames); - if nfit>nest, - gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames); - end - save([fname,'.mat'],'gsa_') - [sidum, iii]=sort(-gsa_.si); - gsa_.x0=x00(1:nfit,:); - hfig=gsa_sdp_plot(gsa_,fname,pnames,iii(1:min(12,np))); - close(hfig); - gsa_.x0=x0(1:nfit,:); -% copyfile([fname,'_est.mat'],[fname,'.mat']) - figure, - plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'), - title([namy,' vs. ', namx,' fit']) - saveas(gcf,[xdir,'/', namy,'_vs_', namx,'_fit']) - eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx,'_fit']); - eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx,'_fit']); - close(gcf) - if nfit0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]); - close(gcf) - end - - iplo=0; - ifig=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - y0=teff(T(iendo,ilagendo,:),kn,istable); - if ~isempty(y0), - if mod(iplo,9)==0, - ifig=ifig+1; - figure('name',[namendo,' vs. lagged endogenous ',int2str(ifig)]), - iplo=0; - end - iplo=iplo+1; - js=js+1; - subplot(3,3,iplo), - [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); - SAM = squeeze(SAMorris(nshock+1:end,1)); - SA(:,js)=SAM./(max(SAM)+eps); - [saso, iso] = sort(-SA(:,js)); - bar(SA(iso(1:min(np,10)),js)) - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - - title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - close(gcf) - end - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - close(gcf) - end -end - -figure, -%bar(SA) -% boxplot(SA','whis',10,'symbol','r.') -myboxplot(SA',[],'.',[],10) -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -xlabel(' ') -ylabel('Elementary Effects') -title('Reduced form screening') - -saveas(gcf,[dirname,'/',M_.fname,'_redform_screen']) -eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_screen']); -eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_screen']); - diff --git a/GSA_distrib/4.1/set_shocks_param.m b/GSA_distrib/4.1/set_shocks_param.m deleted file mode 100644 index f84247d29..000000000 --- a/GSA_distrib/4.1/set_shocks_param.m +++ /dev/null @@ -1,30 +0,0 @@ -function set_shocks_param(xparam1) - global estim_params_ M_ - - nvx = estim_params_.nvx; - ncx = estim_params_.ncx; - np = estim_params_.np; - Sigma_e = M_.Sigma_e; - offset = 0; - if nvx - offset = offset + nvx; - var_exo = estim_params_.var_exo; - for i=1:nvx - k = var_exo(i,1); - Sigma_e(k,k) = xparam1(i)^2; - end - end - - if ncx - offset = offset + estim_params_.nvn; - corrx = estim_params_.corrx; - for i=1:ncx - k1 = corrx(i,1); - k2 = corrx(i,2); - Sigma_e(k1,k2) = xparam1(i+offset)*sqrt(Sigma_e_(k1,k1)*Sigma_e_(k2,k2)); - Sigma_e(k2,k1) = Sigma_e_(k1,k2); - end - end - - - M_.Sigma_e = Sigma_e; \ No newline at end of file diff --git a/GSA_distrib/4.1/skewness.m b/GSA_distrib/4.1/skewness.m deleted file mode 100644 index 19ce487ab..000000000 --- a/GSA_distrib/4.1/skewness.m +++ /dev/null @@ -1,7 +0,0 @@ -function s=skewness(y), - -% y=stand_(y); -% s=mean(y.^3); - m2=mean((y-mean(y)).^2); - m3=mean((y-mean(y)).^3); - s=m3/m2^1.5; \ No newline at end of file diff --git a/GSA_distrib/4.1/smirnov.m b/GSA_distrib/4.1/smirnov.m deleted file mode 100644 index bc068aeb1..000000000 --- a/GSA_distrib/4.1/smirnov.m +++ /dev/null @@ -1,73 +0,0 @@ -function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag ) -% Smirnov test for 2 distributions -% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag ) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - - - -if nargin<3 - alpha = 0.05; -end -if nargin<4, - iflag=0; -end - -% empirical cdfs. -xmix= [x1;x2]; -bin = [-inf ; sort(xmix) ; inf]; - -ncount1 = histc (x1 , bin); -ncount1 = ncount1(:); -ncount2 = histc (x2 , bin); -ncount2 = ncount2(:); - -cum1 = cumsum(ncount1)./sum(ncount1); -cum1 = cum1(1:end-1); - -cum2 = cumsum(ncount2)./sum(ncount2); -cum2 = cum2(1:end-1); - -n1= length(x1); -n2= length(x2); -n = n1*n2 /(n1+n2); - -% Compute the d(n1,n2) statistics. - -if iflag==0, - d = max(abs(cum1 - cum2)); -elseif iflag==-1 - d = max(cum2 - cum1); -elseif iflag==1 - d = max(cum1 - cum2); -end -% -% Compute P-value check H0 hypothesis -% - -lam = max((sqrt(n) + 0.12 + 0.11/sqrt(n)) * d , 0); -if iflag == 0 - j = [1:101]'; - prob = 2 * sum((-1).^(j-1).*exp(-2*lam*lam*j.^2)); - - prob=max(prob,0); - prob=min(1,prob); -else - prob = exp(-2*lam*lam); -end - -H = (alpha >= prob); diff --git a/GSA_distrib/4.1/speed.m b/GSA_distrib/4.1/speed.m deleted file mode 100644 index faaa1de86..000000000 --- a/GSA_distrib/4.1/speed.m +++ /dev/null @@ -1,52 +0,0 @@ -function [tadj, iff] = speed(A,B,mf,p), -% [tadj, iff] = speed(A,B,mf,p), -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -nvar=length(mf); -nstate= size(A,1); -nshock = size(B,2); -nrun=size(B,3); - -iff=zeros(nvar,nshock,nrun); -tadj=iff; -disp('Computing speed of adjustement ...') -h = waitbar(0,'Speed of adjustement...'); - -for i=1:nrun, - irf=zeros(nvar,nshock); - a=squeeze(A(:,:,i)); - b=squeeze(B(:,:,i)); - IFF=inv(eye(nstate)-a)*b; - iff(:,:,i)=IFF(mf,:); - IF=IFF-b; - - t=0; - while any(any(irf<0.5)) - t=t+1; - IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b; - irf=IFT(mf,:)./(IF(mf,:)+eps); - irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7); - %irf=ft(mf,:); - tt=(irf>0.5).*t; - tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i); - end - waitbar(i/nrun,h) -end -disp(' ') -disp('.. done !') -close(h) diff --git a/GSA_distrib/4.1/stab_map_.m b/GSA_distrib/4.1/stab_map_.m deleted file mode 100644 index f525e0121..000000000 --- a/GSA_distrib/4.1/stab_map_.m +++ /dev/null @@ -1,556 +0,0 @@ -function x0 = stab_map_(OutputDirectoryName) -% -% function x0 = stab_map_(OutputDirectoryName) -% -% Mapping of stability regions in the prior ranges applying -% Monte Carlo filtering techniques. -% -% INPUTS (from opt_gsa structure) -% Nsam = MC sample size -% fload = 0 to run new MC; 1 to load prevoiusly generated analysis -% alpha2 = significance level for bivariate sensitivity analysis -% [abs(corrcoef) > alpha2] -% prepSA = 1: save transition matrices for mapping reduced form -% = 0: no transition matrix saved (default) -% pprior = 1: sample from prior ranges (default): sample saved in -% _prior.mat file -% = 0: sample from posterior ranges: sample saved in -% _mc.mat file -% OUTPUT: -% x0: one parameter vector for which the model is stable. -% -% GRAPHS -% 1) Pdf's of marginal distributions under the stability (dotted -% lines) and unstability (solid lines) regions -% 2) Cumulative distributions of: -% - stable subset (dotted lines) -% - unacceptable subset (solid lines) -% 3) Bivariate plots of significant correlation patterns -% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets -% -% USES lptauSEQ, -% stab_map_1, stab_map_2 -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -%global bayestopt_ estim_params_ dr_ options_ ys_ fname_ -global bayestopt_ estim_params_ options_ oo_ M_ - -opt_gsa=options_.opt_gsa; - -Nsam = opt_gsa.Nsam; -fload = opt_gsa.load_stab; -ksstat = opt_gsa.ksstat; -alpha2 = opt_gsa.alpha2_stab; -prepSA = (opt_gsa.redform | opt_gsa.identification); -pprior = opt_gsa.pprior; -ilptau = opt_gsa.ilptau; -nliv = opt_gsa.morris_nliv; -ntra = opt_gsa.morris_ntra; - -dr_ = oo_.dr; -%if isfield(dr_,'ghx'), - ys_ = oo_.dr.ys; - nspred = dr_.nspred; %size(dr_.ghx,2); - nboth = dr_.nboth; - nfwrd = dr_.nfwrd; -%end -fname_ = M_.fname; - -np = estim_params_.np; -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; -lpmat0=[]; - -pshape = bayestopt_.pshape(nshock+1:end); -p1 = bayestopt_.p1(nshock+1:end); -p2 = bayestopt_.p2(nshock+1:end); -p3 = bayestopt_.p3(nshock+1:end); -p4 = bayestopt_.p4(nshock+1:end); - -if nargin==0, - OutputDirectoryName=''; -end - -opt=options_; - options_.periods=0; - options_.nomoments=1; - options_.irf=0; - options_.noprint=1; - options_.simul=0; -if fload==0, -% if prepSA -% T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam/2); -% end - - if isfield(dr_,'ghx'), - egg=zeros(length(dr_.eigval),Nsam); - end - yys=zeros(length(dr_.ys),Nsam); - - if opt_gsa.morris == 1 - [lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []); - lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2; - Nsam=size(lpmat,1); - lpmat0 = lpmat(:,1:nshock); - lpmat = lpmat(:,nshock+1:end); - elseif opt_gsa.morris==3, - lpmat = prep_ide(Nsam,np,5); - Nsam=size(lpmat,1); - else - if np<52 & ilptau>0, - [lpmat] = lptauSEQ(Nsam,np); % lptau - if np>30 | ilptau==2, % scrambled lptau - for j=1:np, - lpmat(:,j)=lpmat(randperm(Nsam),j); - end - end - else %ilptau==0 - %[lpmat] = rand(Nsam,np); - for j=1:np, - lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - end - - end - end -% try - dummy=prior_draw_gsa(1); -% catch -% if pprior, -% if opt_gsa.prior_range==0; -% error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!'); -% end -% end -% -% end - if pprior, - for j=1:nshock, - if opt_gsa.morris~=1, - lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - end - if opt_gsa.prior_range - lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j); - end - end - if opt_gsa.prior_range -% if opt_gsa.identification, -% deltx=min(0.001, 1/Nsam/2); -% for j=1:np, -% xdelt(:,:,j)=prior_draw_gsa(0,[lpmat0 lpmat]+deltx); -% end -% end - for j=1:np, - lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock); - end - else - xx=prior_draw_gsa(0,[lpmat0 lpmat]); -% if opt_gsa.identification, -% deltx=min(0.001, 1/Nsam/2); -% ldum=[lpmat0 lpmat]; -% ldum = prior_draw_gsa(0,ldum+deltx); -% for j=1:nshock+np, -% xdelt(:,:,j)=xx; -% xdelt(:,j,j)=ldum(:,j); -% end -% clear ldum -% end - lpmat0=xx(:,1:nshock); - lpmat=xx(:,nshock+1:end); - clear xx; - end - else - % for j=1:nshock, - % xparam1(j) = oo_.posterior_mode.shocks_std.(bayestopt_.name{j}); - % sd(j) = oo_.posterior_std.shocks_std.(bayestopt_.name{j}); - % lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - % lb = max(bayestopt_.lb(j), xparam1(j)-2*sd(j)); - % ub1=xparam1(j)+(xparam1(j) - lb); % define symmetric range around the mode! - % ub = min(bayestopt_.ub(j),ub1); - % if ub30 & np<52 - % lpmat(:,j) = lpmat(randperm(Nsam),j).*(ub-lb)+lb; - % else - % lpmat(:,j) = lpmat(:,j).*(ub-lb)+lb; - % end - % end - %load([fname_,'_mode']) - eval(['load ' options_.mode_file ';']'); - d = chol(inv(hh)); - lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1'); - for j=1:Nsam*2, - lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub); - end - ireal=[1:2*Nsam]; - ireal=ireal(find(lnprior==0)); - lp=lp(ireal,:); - Nsam=min(Nsam, length(ireal)); - lpmat0=lp(1:Nsam,1:nshock); - lpmat=lp(1:Nsam,nshock+1:end); - clear lp lnprior ireal; - end - % - h = waitbar(0,'Please wait...'); - istable=[1:Nsam]; - jstab=0; - iunstable=[1:Nsam]; - iindeterm=zeros(1,Nsam); - iwrong=zeros(1,Nsam); - for j=1:Nsam, - M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)'; - %try stoch_simul([]); - try - [Tt,Rr,SteadyState,infox{j}] = dynare_resolve(bayestopt_.restrict_var_list,... - bayestopt_.restrict_columns,... - bayestopt_.restrict_aux); - if infox{j}==0, - check1 = max(abs(feval([M_.fname '_static'],... - SteadyState,... - [oo_.exo_steady_state; ... - oo_.exo_det_steady_state], M_.params))) > options_.dynatol ; - if check1, - error(['The seadystate values returned by ' M_.fname ... - '_steadystate.m don''t solve the static model!' ]) - end - end - - - if ~exist('T') - dr_=oo_.dr; - T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam); - egg=zeros(length(dr_.eigval),Nsam); - end - catch - if isfield(oo_.dr,'eigval'), - oo_.dr=rmfield(oo_.dr,'eigval'); - end - if isfield(oo_.dr,'ghx'), - oo_.dr=rmfield(oo_.dr,'ghx'); - end - disp('No solution could be found'), - end - dr_ = oo_.dr; - if isfield(dr_,'ghx'), - egg(:,j) = sort(dr_.eigval); - iunstable(j)=0; - if prepSA - jstab=jstab+1; - T(:,:,jstab) = [dr_.ghx dr_.ghu]; -% [A,B] = ghx2transition(squeeze(T(:,:,jstab)), ... -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux); - end - if ~exist('nspred'), - nspred = dr_.nspred; %size(dr_.ghx,2); - nboth = dr_.nboth; - nfwrd = dr_.nfwrd; - end - else - istable(j)=0; - if isfield(dr_,'eigval') - egg(:,j) = sort(dr_.eigval); - if exist('nspred') - if any(isnan(egg(1:nspred,j))) - iwrong(j)=j; - else - if (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium, - iindeterm(j)=j; - end - end - end - else - if exist('egg'), - egg(:,j)=ones(size(egg,1),1).*NaN; - end - iwrong(j)=j; - end - end - ys_=real(dr_.ys); - yys(:,j) = ys_; - ys_=yys(:,1); - waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)]) - end - close(h) - if prepSA, - T=T(:,:,1:jstab); - end - istable=istable(find(istable)); % stable params - iunstable=iunstable(find(iunstable)); % unstable params - iindeterm=iindeterm(find(iindeterm)); % indeterminacy - iwrong=iwrong(find(iwrong)); % dynare could not find solution - - % % map stable samples - % istable=[1:Nsam]; - % for j=1:Nsam, - % if any(isnan(egg(1:nspred,j))) - % istable(j)=0; - % else - % if abs(egg(nspred,j))>=options_.qz_criterium; %(1-(options_.qz_criterium-1)); %1-1.e-5; - % istable(j)=0; - % %elseif (dr_.nboth | dr_.nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5; - % elseif (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5; - % istable(j)=0; - % end - % end - % end - % istable=istable(find(istable)); % stable params - % - % % map unstable samples - % iunstable=[1:Nsam]; - % for j=1:Nsam, - % %if abs(egg(dr_.npred+1,j))>1+1.e-5 & abs(egg(dr_.npred,j))<1-1.e-5; - % %if (dr_.nboth | dr_.nfwrd), - % if ~any(isnan(egg(1:5,j))) - % if (nboth | nfwrd), - % if abs(egg(nspred+1,j))>options_.qz_criterium & abs(egg(nspred,j))0 & length(iunstable)ksstat); - disp('Smirnov statistics in driving acceptable behaviour') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indstab) - stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName); - end - ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong]))); - if ~isempty(iindeterm), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'],0); - indindet=find(dproba>ksstat); - disp('Smirnov statistics in driving indeterminacy') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indindet) - stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'], 1, indindet, OutputDirectoryName); - end - end - - if ~isempty(ixun), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'],0); - indunst=find(dproba>ksstat); - disp('Smirnov statistics in driving instability') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indunst) - stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'], 1, indunst, OutputDirectoryName); - end - end - - if ~isempty(iwrong), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'],0); - indwrong=find(dproba>ksstat); - disp('Smirnov statistics in driving no solution') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indwrong) - stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'], 1, indwrong, OutputDirectoryName); - end - end - - disp(' ') - disp('Starting bivariate analysis:') - - c0=corrcoef(lpmat(istable,:)); - c00=tril(c0,-1); - - stab_map_2(lpmat(istable,:),alpha2, asname, OutputDirectoryName); - if length(iunstable)>10, - stab_map_2(lpmat(iunstable,:),alpha2, auname, OutputDirectoryName); - end - if length(iindeterm)>10, - stab_map_2(lpmat(iindeterm,:),alpha2, aindname, OutputDirectoryName); - end - if length(ixun)>10, - stab_map_2(lpmat(ixun,:),alpha2, aunstname, OutputDirectoryName); - end - if length(iwrong)>10, - stab_map_2(lpmat(iwrong,:),alpha2, awrongname, OutputDirectoryName); - end - - x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock); - x0 = [x0; lpmat(istable(1),:)']; - if istable(end)~=Nsam - M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)'; - [oo_.dr, info] = resol(oo_.steady_state,0); -% stoch_simul([]); - end -else - if length(iunstable)==0, - disp('All parameter values in the specified ranges are stable!') - x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock); - x0 = [x0; lpmat(istable(1),:)']; - else - disp('All parameter values in the specified ranges are not acceptable!') - x0=[]; - end - -end - - -options_.periods=opt.periods; -if isfield(opt,'nomoments'), - options_.nomoments=opt.nomoments; -end -options_.irf=opt.irf; -options_.noprint=opt.noprint; -if isfield(opt,'simul'), - options_.simul=opt.simul; -end - - - diff --git a/GSA_distrib/4.1/stab_map_1.m b/GSA_distrib/4.1/stab_map_1.m deleted file mode 100644 index 8813fa572..000000000 --- a/GSA_distrib/4.1/stab_map_1.m +++ /dev/null @@ -1,87 +0,0 @@ -function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname) -%function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname) -% -% lpmat = Monte Carlo matrix -% ibehaviour = index of behavioural runs -% inonbehaviour = index of non-behavioural runs -% aname = label of the analysis -% iplot = 1 plot cumulative distributions (default) -% iplot = 0 no plots -% ipar = index array of parameters to plot -% dirname = (OPTIONAL) path of the directory where to save -% (default: current directory) -% -% Plots: dotted lines for BEHAVIOURAL -% solid lines for NON BEHAVIOURAL -% USES smirnov -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global estim_params_ bayestopt_ M_ options_ - -if nargin<5, - iplot=1; -end -fname_ = M_.fname; -if nargin<7, - dirname='';; -end - -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; - -npar=size(lpmat,2); -ishock= npar>estim_params_.np; - -if nargin<6 | isempty(ipar), - ipar=[1:npar]; -end -nparplot=length(ipar); - -% Smirnov test for Blanchard; -for j=1:npar, - [H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j)); - proba(j)=P; - dproba(j)=KSSTAT; -end -if iplot - lpmat=lpmat(:,ipar); - ftit=bayestopt_.name(ipar+nshock*(1-ishock)); - -for i=1:ceil(nparplot/12), - figure('name',aname), - for j=1+12*(i-1):min(nparplot,12*i), - subplot(3,4,j-12*(i-1)) - if ~isempty(ibehaviour), - h=cumplot(lpmat(ibehaviour,j)); - set(h,'color',[0 0 0], 'linestyle',':') - end - hold on, - if ~isempty(inonbehaviour), - h=cumplot(lpmat(inonbehaviour,j)); - set(h,'color',[0 0 0]) - end - title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none') - end - saveas(gcf,[dirname,'/',fname_,'_',aname,'_SA_',int2str(i)]) - eval(['print -depsc2 ' dirname '/' fname_ '_' aname '_SA_' int2str(i)]); - eval(['print -dpdf ' dirname '/' fname_ '_' aname '_SA_' int2str(i)]); - if options_.nograph, close(gcf), end -end -end diff --git a/GSA_distrib/4.1/stab_map_2.m b/GSA_distrib/4.1/stab_map_2.m deleted file mode 100644 index 3d1a8fa9c..000000000 --- a/GSA_distrib/4.1/stab_map_2.m +++ /dev/null @@ -1,97 +0,0 @@ -%function stab_map_2(x,alpha2,istab,fnam) -function stab_map_2(x,alpha2,fnam, dirname) -% function stab_map_2(x,alpha2,fnam, dirname) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -%global bayestopt_ estim_params_ dr_ options_ ys_ fname_ -global bayestopt_ estim_params_ options_ oo_ M_ - -npar=size(x,2); -ishock= npar>estim_params_.np; -if nargin<3, - fnam=''; -end -if nargin<4, - dirname=''; -end - -ys_ = oo_.dr.ys; -dr_ = oo_.dr; -fname_ = M_.fname; -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; - -c0=corrcoef(x); -c00=tril(c0,-1); -fig_nam_=[fname_,'_',fnam,'_corr_']; - -ifig=0; -j2=0; -if ishock==0 - npar=estim_params_.np; -else - npar=estim_params_.np+nshock; -end -for j=1:npar, - i2=find(abs(c00(:,j))>alpha2); - if length(i2)>0, - for jx=1:length(i2), - j2=j2+1; - if mod(j2,12)==1, - ifig=ifig+1; - figure('name',['Correlations in the ',fnam,' sample ', num2str(ifig)]), - end - subplot(3,4,j2-(ifig-1)*12) - % bar(c0(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - %plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k') - %hold on, - plot(x(:,j),x(:,i2(jx)),'.') - % xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'), - % ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'), - if ishock, - xlabel(bayestopt_.name{j},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)},'interpreter','none'), - else - xlabel(bayestopt_.name{j+nshock},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'), - end - title(['cc = ',num2str(c0(i2(jx),j))]) - if (mod(j2,12)==0) & j2>0, - saveas(gcf,[dirname,'/',fig_nam_,int2str(ifig)]) - eval(['print -depsc2 ' dirname '/' fig_nam_ int2str(ifig)]); - eval(['print -dpdf ' dirname '/' fig_nam_ int2str(ifig)]); - if options_.nograph, close(gcf), end - end - end - end - if (j==(npar)) & j2>0, - saveas(gcf,[dirname,'/',fig_nam_,int2str(ifig)]) - eval(['print -depsc2 ' dirname '/' fig_nam_ int2str(ifig)]); - eval(['print -dpdf ' dirname '/' fig_nam_ int2str(ifig)]); - if options_.nograph, close(gcf), end - end - -end -if ifig==0, - disp(['No correlation term >', num2str(alpha2),' found for ',fnam]) -end -%close all diff --git a/GSA_distrib/4.1/stand_.m b/GSA_distrib/4.1/stand_.m deleted file mode 100644 index fb0b3fda3..000000000 --- a/GSA_distrib/4.1/stand_.m +++ /dev/null @@ -1,25 +0,0 @@ -function [y, meany, stdy] = stand_(x) -% STAND_ Standardise a matrix by columns -% -% [x,my,sy]=stand(y) -% -% y: Time series (column matrix) -% -% x: standardised equivalent of y -% my: Vector of mean values for each column of y -% sy: Vector of standard deviations for each column of y -% -% Copyright (c) 2006 by JRC, European Commission, United Kingdom -% Author : Marco Ratto - - -if nargin==0, - return; -end - -for j=1:size(x,2); -meany(j)=mean(x(find(~isnan(x(:,j))),j)); -stdy(j)=std(x(find(~isnan(x(:,j))),j)); - y(:,j)=(x(:,j)-meany(j))./stdy(j); -end -% end of m-file \ No newline at end of file diff --git a/GSA_distrib/4.1/teff.m b/GSA_distrib/4.1/teff.m deleted file mode 100644 index 6c33706e5..000000000 --- a/GSA_distrib/4.1/teff.m +++ /dev/null @@ -1,51 +0,0 @@ -function [yt, j0, ir, ic]=teff(T,Nsam,istable) -% -% [yt, j0, ir, ic]=teff(T,Nsam,istable) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -ndim = (length(size(T))); -if ndim==3, -if nargin==1, - Nsam=size(T,3); - istable = [1:Nsam]'; -end -tmax=max(T,[],3); -tmin=min(T,[],3); -[ir, ic]=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=zeros(Nsam, j0); - -for j=1:j0, - y0=squeeze(T(ir(j),ic(j),:)); - %y1=ones(size(lpmat,1),1)*NaN; - y1=ones(Nsam,1)*NaN; - y1(istable,1)=y0; - yt(:,j)=y1; -end - -else -tmax=max(T,[],2); -tmin=min(T,[],2); -ir=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=NaN(Nsam, j0); -yt(istable,:)=T(ir,:)'; - - -end -%clear y0 y1; diff --git a/GSA_distrib/4.1/th_moments.m b/GSA_distrib/4.1/th_moments.m deleted file mode 100644 index 41bb18d78..000000000 --- a/GSA_distrib/4.1/th_moments.m +++ /dev/null @@ -1,66 +0,0 @@ -% Copyright (C) 2001 Michel Juillard -% -function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list) - global M_ oo_ options_ - - nvar = size(var_list,1); - if nvar == 0 - nvar = length(dr.order_var); - ivar = [1:nvar]'; - else - ivar=zeros(nvar,1); - for i=1:nvar - i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact'); - if isempty(i_tmp) - error (['One of the variable specified does not exist']) ; - else - ivar(i) = i_tmp; - end - end - end - - [gamma_y,ivar] = th_autocovariances(dr,ivar,M_, options_); - m = dr.ys(ivar); - - - i1 = find(abs(diag(gamma_y{1})) > 1e-12); - s2 = diag(gamma_y{1}); - sd = sqrt(s2); - - - z = [ m sd s2 ]; - mean = m; - var = gamma_y{1}; - - -%'THEORETICAL MOMENTS'; -%'MEAN','STD. DEV.','VARIANCE'); -z; - -%'VARIANCE DECOMPOSITION (in percent)'; -if M_.exo_nbr>1, -vdec = 100*gamma_y{options_.ar+2}(i1,:); -else -vdec = 100*ones(size(gamma_y{1}(i1,1))); -end -%'MATRIX OF CORRELATIONS'; -if options_.opt_gsa.useautocorr, - corr = gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)'); - corr = corr-diag(diag(corr))+diag(diag(gamma_y{1}(i1,i1))); -else - corr = gamma_y{1}(i1,i1); -end - if options_.ar > 0 -%'COEFFICIENTS OF AUTOCORRELATION'; - for i=1:options_.ar - if options_.opt_gsa.useautocorr, - autocorr{i} = gamma_y{i+1}(i1,i1); - else - autocorr{i} = gamma_y{i+1}(i1,i1).*(sd(i1)*sd(i1)'); - end - zz(:,i) = diag(gamma_y{i+1}(i1,i1)); - end - end - - - \ No newline at end of file diff --git a/GSA_distrib/4.1/thet2tau.m b/GSA_distrib/4.1/thet2tau.m deleted file mode 100644 index 5cd29f00e..000000000 --- a/GSA_distrib/4.1/thet2tau.m +++ /dev/null @@ -1,45 +0,0 @@ -function tau = thet2tau(params, indx, indexo, flagmoments,mf,nlags,useautocorr) -global M_ oo_ options_ - -if nargin==1, - indx = [1:M_.param_nbr]; - indexo = []; -end - -if nargin<4, - flagmoments=0; -end -if nargin<7 | isempty(useautocorr), - useautocorr=0; -end - -M_.params(indx) = params(length(indexo)+1:end); -if ~isempty(indexo) - M_.Sigma_e(indexo,indexo) = diag(params(1:length(indexo)).^2); -end -% [A(oo_.dr.order_var,oo_.dr.order_var),B(oo_.dr.order_var,:)]=dynare_resolve; -[A,B]=dynare_resolve; -if flagmoments==0, -tau = [oo_.dr.ys(oo_.dr.order_var); A(:); vech(B*M_.Sigma_e*B')]; -else -GAM = lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold); -k = find(abs(GAM) < 1e-12); -GAM(k) = 0; -if useautocorr, - sy = sqrt(diag(GAM)); - sy = sy*sy'; - sy0 = sy-diag(diag(sy))+eye(length(sy)); - dum = GAM./sy0; - tau = vech(dum(mf,mf)); -else - tau = vech(GAM(mf,mf)); -end -for ii = 1:nlags - dum = A^(ii)*GAM; - if useautocorr, - dum = dum./sy; - end - tau = [tau;vec(dum(mf,mf))]; -end -tau = [ oo_.dr.ys(oo_.dr.order_var(mf)); tau]; -end \ No newline at end of file diff --git a/GSA_distrib/4.1/trank.m b/GSA_distrib/4.1/trank.m deleted file mode 100644 index a0c5bda99..000000000 --- a/GSA_distrib/4.1/trank.m +++ /dev/null @@ -1,25 +0,0 @@ -function yr = trank(y); -% yr = trank(y); -% yr is the rank transformation of y -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -[nr, nc] = size(y); -for j=1:nc, - [dum, is]=sort(y(:,j)); - yr(is,j)=[1:nr]'./nr; -end diff --git a/GSA_distrib/4.2/LPTAU.m b/GSA_distrib/4.2/LPTAU.m deleted file mode 100644 index 7427de885..000000000 --- a/GSA_distrib/4.2/LPTAU.m +++ /dev/null @@ -1,512 +0,0 @@ -function VECTOR = LPTAU(I, N) -% -% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN -% KELDYSH INSTITUTE OF APPLIED MATHEMATICS -% RUSSIAN ACADEMY OF SCIENCES -% -% QUASIRANDOM SEQUENCE GENERATORS -% ------------------------------- -% -% 28.11.1991 -% -% NOTE TO THE USER BY the NEA Data Bank: -% This quasi random number generator has been made available to -% you on condition that its identity is preserved when used -% in computer programs. If its use leads to scientific publication -% of results you should cite it in the references, in addition -% no commercial use should be made unless agreed upon with the -% main author (Prof. I.M. Sobol') -% -% ABSTRACT -% ........ -% -% POINTS BELONGING TO LP-TAU SEQUENCES UNIFORMLY DISTRIBUTED IN THE -% N-DIMENSIONAL UNIT CUBE ARE OFTEN USED IN NUMERICAL MATHEMATICS: -% -% - AS NODES FOR MULTIDIMENSIONAL INTEGRATION; -% - AS SEARCHING POINTS IN GLOBAL OPTIMIZATION; -% - AS TRIAL POINTS IN MULTI-CRITERIA DECISION MAKING; -% - AS QUASIRANDOM POINTS FOR QUASI-MONTECARLO ALGORITHMS; -% - ETC. -% -% THIS SUBROUTINE CONTAINS THE ALGORITHM FOR FAST GENERATION OF -% LP-TAU SEQUENCES THAT ARE SUITABLE FOR MULTI-PROCESSOR COMPUTATIONS. -% THE DIMENSIONS N.LE.51, THE NUMBER OF POINTS N.LT.2**30. -% THE PROGRAMMING LANGUAGE IS FORTRAN-77. THIS SUBROUTINE IS AVAILABLE -% ALSO IN %-LANGUAGE. -% THE REPORT DESCRIBING THE ALGORITHM CONTAINS THE DESCRIPTION OF THE -% ALGORITHM AND CERTAIN IMPORTANT PROPERTIES OF LP-TAU SEQUENCES AND -% THEIR GENERALIZATIONS ARE DISCUSSED. -% -% REFERENCE: -% I.M. SOBOL', V.I. TURCHANINOV, Yu.L. LEVITAN, B.V. SHUKHMAN -% KELDYSH INSTITUTE OF APPLIED MATHEMATICS -% RUSSIAN ACADEMY OF SCIENCES -% -% QUASIRANDOM SEQUENCE GENERATORS -% MOSCOW 1992, IPM ZAK. NO.30 (100 COPIES) -% -% ------------------------------------------------------------------------ -% -% INPUT PARAMETERS: -% -% I - NUMBER OF THE POINT (I=(0,2**30-1)), -% N - DIMENSION OF THE POINT (0MAXNUM) | (N>MAXDIM)), - disp('LP-TAU CALL FAILED') - disp(' PRESS TO EXIT LPTAU') - pause - return -end -if ((PRVNUM+1==I) & (N<=PRVDIM)), - % - % RECURRENT GENERATION OF THE POINT - % - % - % SEARCH POSITION OF THE RIGHTMOST "1" - % IN THE BINARY REPRESENTATION OF I - % - L=0; - POS=0; - while L1e-010); - % If we deal with groups we can only estimate the new mu* - % measure since factors in the same groups can move in - % opposite direction and the definition of the standard - % Morris mu cannopt be applied. - % In the new version the elementary effect is defined with - % the absolute value. - %SAmeas(find(GroupMat(Change_factor(j,i),:)),i) = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); %(2/3)); - SAmeas(i,Change_factor') = abs((Single_OutValues(j) - Single_OutValues(j+1) )/Delt); - else - Change_factor(j,i) = find(Single_Sample(j+1,:)-Single_Sample(j,:)); - % If no groups --> we compute both the original and - % modified measure - if Delta(j) > 0 %=> +Delta - SAmeas(Change_factor(j,i),i) = (Single_OutValues(j+1) - Single_OutValues(j) )/Delt; %(2/3); - else %=> -Delta - SAmeas(Change_factor(j,i),i) = (Single_OutValues(j) - Single_OutValues(j+1) )/Delt; %(2/3); - end - end - end %for j=1:sizea - - end %for i=1:r - - if NumGroups ~ 0 - SAmeas = SAmeas'; - end - - % Compute Mu AbsMu and StDev - if any(any(isnan(SAmeas))) - for j=1:NumFact, - SAm = SAmeas(j,:); - SAm = SAm(find(~isnan(SAm))); - rr=length(SAm); - AbsMu(j,1) = sum(abs(SAm),2)/rr; - if NumGroups == 0 - Mu(j,1) = sum(SAm,2)/rr; - StDev(j,1) = sum((SAm - repmat(Mu(j),1,rr)).^2/(rr*(rr-1)),2).^0.5; - end - end - else - AbsMu = sum(abs(SAmeas),2)/r; - if NumGroups == 0 - Mu = sum(SAmeas,2)/r; - StDev = sum((SAmeas - repmat(Mu,1,r)).^2/(r*(r-1)),2).^0.5; - end - end - - % Define the output Matrix - if we have groups we cannot define the old - % measure mu, only mu* makes sense - if NumGroups > 0 - OutMatrix = [OutMatrix; AbsMu]; - else - OutMatrix = [OutMatrix; AbsMu, Mu, StDev]; - end -end % For Each Output diff --git a/GSA_distrib/4.2/Sampling_Function_2.m b/GSA_distrib/4.2/Sampling_Function_2.m deleted file mode 100644 index ccd3a87f9..000000000 --- a/GSA_distrib/4.2/Sampling_Function_2.m +++ /dev/null @@ -1,174 +0,0 @@ -function [Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -%[Outmatrix, OutFact] = Sampling_Function_2(p, k, r, UB, LB, GroupMat) -% Inputs: k (1,1) := number of factors examined or number of groups examined. -% In case the groups are chosen the number of factors is stores in NumFact and -% sizea becomes the number of created groups. -% NumFact (1,1) := number of factors examined in the case when groups are chosen -% r (1,1) := sample size -% p (1,1) := number of intervals considered in [0, 1] -% UB(sizea,1) := Upper Bound for each factor -% LB(sizea,1) := Lower Bound for each factor -% GroupNumber(1,1) := Number of groups (eventually 0) -% GroupMat(NumFact,GroupNumber):= Matrix which describes the chosen groups. Each column represents a group and its elements -% are set to 1 in correspondence of the factors that belong to the fixed group. All -% the other elements are zero. -% Local Variables: -% sizeb (1,1) := sizea+1 -% sizec (1,1) := 1 -% randmult (sizea,1) := vector of random +1 and -1 -% perm_e(1,sizea) := vector of sizea random permutated indeces -% fact(sizea) := vector containing the factor varied within each traj -% DDo(sizea,sizea) := D* in Morris, 1991 -% A(sizeb,sizea) := Jk+1,k in Morris, 1991 -% B(sizeb,sizea) := B in Morris, 1991 -% Po(sizea,sizea) := P* in Morris, 1991 -% Bo(sizeb,sizea) := B* in Morris, 1991 -% Ao(sizeb,sizec) := Jk+1,1 in Morris, 1991 -% xo(sizec,sizea) := x* in Morris, 1991 (starting point for the trajectory) -% In(sizeb,sizea) := for each loop orientation matrix. It corresponds to a trajectory -% of k step in the parameter space and it provides a single elementary -% effect per factor -% MyInt() -% Fact(sizea,1) := for each loop vector indicating which factor or group of factors has been changed -% in each step of the trajectory -% AuxMat(sizeb,sizea) := Delta*0.5*((2*B - A) * DD0 + A) in Morris, 1991. The AuxMat is used as in Morris design -% for single factor analysis, while it constitutes an intermediate step for the group analysis. -% -% Output: Outmatrix(sizeb*r, sizea) := for the entire sample size computed In(i,j) matrices -% OutFact(sizea*r,1) := for the entire sample size computed Fact(i,1) vectors -% -% Note: B0 is constructed as in Morris design when groups are not considered. When groups are considered the routine -% follows the following steps: -% 1- Creation of P0 and DD0 matrices defined in Morris for the groups. This means that the dimensions of these -% 2 matrices are (GroupNumber,GroupNumber). -% 2- Creation of AuxMat matrix with (GroupNumber+1,GroupNumber) elements. -% 3- Definition of GroupB0 starting from AuxMat, GroupMat and P0. -% 4- The final B0 for groups is obtained as [ones(sizeb,1)*x0' + GroupB0]. The P0 permutation is present in GroupB0 -% and it's not necessary to permute the matrix (ones(sizeb,1)*x0') because it's already randomly created. -% Reference: -% A. Saltelli, K. Chan, E.M. Scott, "Sensitivity Analysis" on page 68 ss -% -% F. Campolongo, J. Cariboni, JRC - IPSC Ispra, Varese, IT -% Last Update: 15 November 2005 by J.Cariboni -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - -% Parameters and initialisation of the output matrix -sizea = k; -Delta = p/(2*p-2); -%Delta = 1/3 -NumFact = sizea; -GroupNumber = size(GroupMat,2); - -if GroupNumber ~ 0; - sizea = size(GroupMat,2); -end - -sizeb = sizea + 1; -sizec = 1; -Outmatrix = []; -OutFact = []; - -% For each i generate a trajectory -for i=1:r - - % Construct DD0 - OLD VERSION - it does not need communication toolbox - % RAND(N,M) is an NXM matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0). - % Note that DD0 tells if the factor have to be increased or ddecreased - % by Delta. - randmult = ones(k,1); - v = rand(k,1); - randmult (find(v < 0.5))=-1; - randmult = repmat(randmult,1,k); - DD0 = randmult .* eye(k); - - % Construct DD0 - NEW VERSION - it needs communication toolbox - % randsrc(m) generates an m-by-m matrix, each of whose entries independently takes the value -1 with probability 1/2, - % and 1 with probability 1/2. - % DD0 = randsrc(NumFact) .* eye(NumFact); - - % Construct B (lower triangular) - B = ones(sizeb,sizea); - for j = 1:sizea - B(1:j,j)=0; - end - - % Construct A0, A - A0 = ones(sizeb,1); - A = ones(sizeb,NumFact); - - % Construct the permutation matrix P0. In each column of P0 one randomly chosen element equals 1 - % while all the others equal zero. - % P0 tells the order in which order factors are changed in each - % trajectory. P0 is created as it follows: - % 1) All the elements of P0 are set equal to zero ==> P0 = zeros (sizea, sizea); - % 2) The function randperm create a random permutation of integer 1:sizea, without repetitions ==> perm_e; - % 3) In each column of P0 the element indicated in perm_e is set equal to one. - % Note that P0 is then used reading it by rows. - P0 = zeros (sizea, sizea); - perm_e = randperm(sizea); % RANDPERM(n) is a random permutation of the integers from 1 to n. - for j = 1:sizea - P0(perm_e(j),j) = 1; - end - - % When groups are present the random permutation is done only on B. The effect is the same since - % the added part (A0*x0') is completely random. - if GroupNumber ~ 0 - B = B * (GroupMat*P0')'; - end - - % Compute AuxMat both for single factors and groups analysis. For Single factors analysis - % AuxMat is added to (A0*X0) and then permutated through P0. When groups are active AuxMat is - % used to build GroupB0. AuxMat is created considering DD0. If the element on DD0 diagonal - % is 1 then AuxMat will start with zero and add Delta. If the element on DD0 diagonal is -1 - % then DD0 will start Delta and goes to zero. - AuxMat = Delta*0.5*((2*B - A) * DD0 + A); - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % a --> Define the random vector x0 for the factors. Note that x0 takes value in the hypercube - % [0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta]*[0,...,1-Delta] - MyInt = repmat([0:(1/(p-1)):(1-Delta)],NumFact,1); % Construct all possible values of the factors - - % OLD VERSION - it needs communication toolbox - % w = randint(NumFact,1,[1,size(MyInt,2)]); - - % NEW VERSION - construct a version of random integers - % 1) create a vector of random integers - % 2) divide [0,1] into the needed steps - % 3) check in which interval the random numbers fall - % 4) generate the corresponding integer - v = repmat(rand(NumFact,1),1,size(MyInt,2)+1); % 1) - IntUsed = repmat([0:1/size(MyInt,2):1],NumFact,1); % 2) - DiffAuxVec = IntUsed - v; % 3) - - for ii = 1:size(DiffAuxVec,1) - w(1,ii) = max(find(DiffAuxVec(ii,:)<0)); % 4) - end - x0 = MyInt(1,w)'; % Define x0 - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % b --> Compute the matrix B*, here indicated as B0. Each row in B0 is a - % trajectory for Morris Calculations. The dimension of B0 is (Numfactors+1,Numfactors) - if GroupNumber ~ 0 - B0 = (A0*x0' + AuxMat); - else - B0 = (A0*x0' + AuxMat)*P0; - end - - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % c --> Compute values in the original intervals - % B0 has values x(i,j) in [0, 1/(p -1), 2/(p -1), ... , 1]. - % To obtain values in the original intervals [LB, UB] we compute - % LB(j) + x(i,j)*(UB(j)-LB(j)) - In = repmat(LB,1,sizeb)' + B0 .* repmat((UB-LB),1,sizeb)'; - - % Create the Factor vector. Each component of this vector indicate which factor or group of factor - % has been changed in each step of the trajectory. - for j=1:sizea - Fact(1,j) = find(P0(j,:)); - end - Fact(1,sizea+1) = 0; - - Outmatrix = [Outmatrix; In]; - OutFact = [OutFact; Fact']; - -end \ No newline at end of file diff --git a/GSA_distrib/4.2/beta_inv.m b/GSA_distrib/4.2/beta_inv.m deleted file mode 100644 index d3c95836d..000000000 --- a/GSA_distrib/4.2/beta_inv.m +++ /dev/null @@ -1,38 +0,0 @@ -function x = beta_inv(p, a, b) -% PURPOSE: inverse of the cdf (quantile) of the beta(a,b) distribution -%-------------------------------------------------------------- -% USAGE: x = beta_inv(p,a,b) -% where: p = vector of probabilities -% a = beta distribution parameter, a = scalar -% b = beta distribution parameter b = scalar -% NOTE: mean [beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1)) -%-------------------------------------------------------------- -% RETURNS: x at each element of p for the beta(a,b) distribution -%-------------------------------------------------------------- -% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd -%-------------------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to -% match the format of the econometrics toolbox - -if (nargin ~= 3) - error('Wrong # of arguments to beta_inv'); -end - -if any(any((a<=0)|(b<=0))) - error('beta_inv parameter a or b is nonpositive'); -end -if any(any(abs(2*p-1)>1)) - error('beta_inv: A probability should be 0<=p<=1'); -end - -x = a ./ (a+b); -dx = 1; -while any(any(abs(dx)>256*eps*max(x,1))) - dx = (betainc(x,a,b) - p) ./ beta_pdf(x,a,b); - x = x - dx; - x = x + (dx - x) / 2 .* (x<0); -end - \ No newline at end of file diff --git a/GSA_distrib/4.2/beta_pdf.m b/GSA_distrib/4.2/beta_pdf.m deleted file mode 100644 index 8412fbdce..000000000 --- a/GSA_distrib/4.2/beta_pdf.m +++ /dev/null @@ -1,32 +0,0 @@ -function pdf = beta_pdf(x, a, b) -% PURPOSE: pdf of the beta(a,b) distribution -%-------------------------------------------------------------- -% USAGE: pdf = beta_pdf(x,a,b) -% where: x = vector of components -% a = beta distribution parameter, a = scalar -% b = beta distribution parameter b = scalar -% NOTE: mean[(beta(a,b)] = a/(a+b), variance = ab/((a+b)*(a+b)*(a+b+1)) -%-------------------------------------------------------------- -% RETURNS: pdf at each element of x of the beta(a,b) distribution -%-------------------------------------------------------------- -% SEE ALSO: beta_d, beta_pdf, beta_inv, beta_rnd -%-------------------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to -% match the format of the econometrics toolbox - - -if (nargin ~=3) - error('Wrong # of arguments to beta_pdf'); -end - -if any(any((a<=0)|(b<=0))) - error('Parameter a or b is nonpositive'); -end - -I = find((x<0)|(x>1)); - -pdf = x.^(a-1) .* (1-x).^(b-1) ./ beta(a,b); -pdf(I) = 0*I; diff --git a/GSA_distrib/4.2/cumplot.m b/GSA_distrib/4.2/cumplot.m deleted file mode 100644 index a700d3784..000000000 --- a/GSA_distrib/4.2/cumplot.m +++ /dev/null @@ -1,14 +0,0 @@ -function h = cumplot(x); -%function h =cumplot(x) -% Copyright (C) 2005 Marco Ratto - - -n=length(x); -x=[-inf; sort(x); Inf]; -y=[0:n n]./n; -h0 = stairs(x,y); -grid on, - -if nargout, - h=h0; -end diff --git a/GSA_distrib/4.2/dat_fil_.m b/GSA_distrib/4.2/dat_fil_.m deleted file mode 100644 index 0b3ac8f8e..000000000 --- a/GSA_distrib/4.2/dat_fil_.m +++ /dev/null @@ -1,30 +0,0 @@ -function c = dat_fil_(data_file); -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -try - eval(data_file); -catch - load(data_file); -end -clear data_file; - -a=who; - -for j=1:length(a) - eval(['c.',a{j},'=',a{j},';']); -end \ No newline at end of file diff --git a/GSA_distrib/4.2/dynare_MC.m b/GSA_distrib/4.2/dynare_MC.m deleted file mode 100644 index 3d13b5b51..000000000 --- a/GSA_distrib/4.2/dynare_MC.m +++ /dev/null @@ -1,133 +0,0 @@ -function dynare_MC(var_list_,OutDir,data,rawdata,data_info) -% -% Adapted by M. Ratto from dynare_estimation.m and posteriorsmoother.m -% (dynare_estimation.m and posteriorsmoother.m are part of DYNARE, -% copyright M. Juillard) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ options_ oo_ estim_params_ -global bayestopt_ - -% if options_.filtered_vars ~= 0 & options_.filter_step_ahead == 0 -% options_.filter_step_ahead = 1; -% end -% if options_.filter_step_ahead ~= 0 -% options_.nk = max(options_.filter_step_ahead); -% else -% options_.nk = 0; -% end -% -options_.filter_step_ahead=1; -options_.nk = 1; - - - -nvx = estim_params_.nvx; -nvn = estim_params_.nvn; -ncx = estim_params_.ncx; -ncn = estim_params_.ncn; -np = estim_params_.np ; -npar = nvx+nvn+ncx+ncn+np; - -if isempty(options_.datafile) - error('ESTIMATION: datafile option is missing') -end - -if isempty(options_.varobs) - error('ESTIMATION: VAROBS is missing') -end - -gend = data_info.gend; -n_varobs = size(options_.varobs,1); - -data_index = data_info.data_index; -number_of_observations = data_info.number_of_observations; -no_more_missing_observations = data_info.no_more_missing_observations; -missing_value = data_info.missing_value; - -offset = npar-np; -fname_=M_.fname; - -options_ = set_default_option(options_,'opt_gsa',1); -options_gsa_ = options_.opt_gsa; - -if options_gsa_.pprior, - namfile=[fname_,'_prior']; -else - namfile=[fname_,'_mc']; -end -load([OutDir,'/',namfile],'lpmat', 'lpmat0', 'istable') -% load(options_.mode_file) -%% -%% -%% -x=[lpmat0(istable,:) lpmat(istable,:)]; -clear lpmat lpmat0 istable %iunstable egg yys T -B = size(x,1); -[atT,innov,measurement_error,updated_variables,ys,trend_coeff, aK] = DsgeSmoother(x(1,:)',gend,data,data_index,missing_value); -n1=size(atT,1); - -nfil=B/40; -stock_smooth = zeros(M_.endo_nbr,gend,40); -stock_filter = zeros(M_.endo_nbr,gend+1,40); -stock_ys = zeros(40, M_.endo_nbr); -logpo2=zeros(B,1); -%% -h = waitbar(0,'MC smoother ...'); -delete([OutDir,'/',namfile,'_*.mat']) -ib=0; -ifil=0; -opt_gsa=options_.opt_gsa; - -for b=1:B - ib=ib+1; - deep = x(b,:)'; - set_all_parameters(deep); - dr = resol(oo_.steady_state,0); - %deep(1:offset) = xparam1(1:offset); - logpo2(b,1) = DsgeLikelihood(deep,gend,data,data_index,number_of_observations,no_more_missing_observations); - if opt_gsa.lik_only==0, - [atT,innov,measurement_error,updated_variables,ys,trend_coeff, aK] = DsgeSmoother(deep,gend,data,data_index,missing_value); - stock_smooth(:,:,ib)=atT(1:M_.endo_nbr,:); -% stock_filter(:,:,ib)=updated_variables(1:M_.endo_nbr,:); - stock_filter(:,:,ib)=aK(1,1:M_.endo_nbr,:); - stock_ys(ib,:)=ys'; - if ib==40, - ib=0; - ifil=ifil+1; - save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys') - stock_smooth = zeros(M_.endo_nbr,gend,40); - stock_filter = zeros(M_.endo_nbr,gend+1,40); - stock_ys = zeros(40, M_.endo_nbr); - end - end - waitbar(b/B,h,['MC smoother ...',num2str(b),'/',num2str(B)]); -end -close(h) -if opt_gsa.lik_only==0, -if ib>0, - ifil=ifil+1; - stock_smooth = stock_smooth(:,:,1:ib); - stock_filter = stock_filter(:,:,1:ib); - stock_ys = stock_ys(1:ib,:); - save([OutDir,'/',namfile,'_',num2str(ifil)],'stock_smooth','stock_filter','stock_ys') -end -end -stock_gend=gend; -stock_data=data; -save([OutDir,'/',namfile],'x','logpo2','stock_gend','stock_data','-append') diff --git a/GSA_distrib/4.2/fdjac.m b/GSA_distrib/4.2/fdjac.m deleted file mode 100644 index 2ff746531..000000000 --- a/GSA_distrib/4.2/fdjac.m +++ /dev/null @@ -1,37 +0,0 @@ -% FDJAC Computes two-sided finite difference Jacobian -% USAGE -% fjac = fdjac(f,x,P1,P2,...) -% INPUTS -% f : name of function of form fval = f(x) -% x : evaluation point -% P1,P2,... : additional arguments for f (optional) -% OUTPUT -% fjac : finite differnce Jacobian -% -% USER OPTIONS (SET WITH OPSET) -% tol : a factor used in setting the step size -% increase if f is inaccurately computed - -% Copyright (c) 1997-2002, Paul L. Fackler & Mario J. Miranda -% paul_fackler@ncsu.edu, miranda.4@osu.edu - -function fjac = fdjac(f,x,varargin) - -tol = optget(mfilename,'tol',eps.^(1/3)); - -h = tol.*max(abs(x),1); -xh1=x+h; xh0=x-h; -h=xh1-xh0; -for j=1:length(x); - xx = x; - xx(j) = xh1(j); f1=feval(f,xx,varargin{:}); - xx(j) = xh0(j); f0=feval(f,xx,varargin{:}); - fjac(:,j) = (f1-f0)/h(j); -% v = (f1-f0); -% k = find(abs(v) < 1e-8); -% v(k) = 0; -% -% fjac(:,j) = v/h(j); -end - -feval(f,x,varargin{:}); \ No newline at end of file diff --git a/GSA_distrib/4.2/filt_mc_.m b/GSA_distrib/4.2/filt_mc_.m deleted file mode 100644 index ba582de37..000000000 --- a/GSA_distrib/4.2/filt_mc_.m +++ /dev/null @@ -1,687 +0,0 @@ -function [rmse_MC, ixx] = filt_mc_(OutDir,data_info) -% function [rmse_MC, ixx] = filt_mc_(OutDir) -% copyright Marco Ratto 2006 -% inputs (from opt_gsa structure) -% vvarvecm = options_gsa_.var_rmse; -% loadSA = options_gsa_.load_rmse; -% pfilt = options_gsa_.pfilt_rmse; -% alpha = options_gsa_.alpha_rmse; -% alpha2 = options_gsa_.alpha2_rmse; -% istart = options_gsa_.istart_rmse; -% alphaPC = 0.5; -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global bayestopt_ estim_params_ M_ options_ oo_ - -options_gsa_=options_.opt_gsa; -vvarvecm = options_gsa_.var_rmse; -loadSA = options_gsa_.load_rmse; -pfilt = options_gsa_.pfilt_rmse; -alpha = options_gsa_.alpha_rmse; -alpha2 = options_gsa_.alpha2_rmse; -istart = options_gsa_.istart_rmse; -alphaPC = 0.5; - -fname_ = M_.fname; -lgy_ = M_.endo_names; -dr_ = oo_.dr; - -disp(' ') -disp(' ') -disp('Starting sensitivity analysis') -disp('for the fit of EACH observed series ...') -disp(' ') -disp('Deleting old SA figures...') -a=dir([OutDir,'/*.*']); -tmp1='0'; -if options_.opt_gsa.ppost, - tmp=['_rmse_post']; -else - if options_.opt_gsa.pprior - tmp=['_rmse_prior']; - else - tmp=['_rmse_mc']; - end - if options_gsa_.lik_only, - tmp1 = [tmp,'_post_SA']; - tmp = [tmp,'_lik_SA']; - end -end -for j=1:length(a), - if strmatch([fname_,tmp],a(j).name), - disp(a(j).name) - delete([OutDir,'/',a(j).name]) - end, - if strmatch([fname_,tmp1],a(j).name), - disp(a(j).name) - delete([OutDir,'/',a(j).name]) - end, -end -disp('done !') - - -nshock=estim_params_.nvx + estim_params_.nvn + estim_params_.ncx + estim_params_.ncn; -npar=estim_params_.np; -if ~isempty(options_.mode_file), - load(options_.mode_file,'xparam1'), -end -if options_.opt_gsa.ppost, - c=load([fname_,'_mean'],'xparam1'); - xparam1_mean=c.xparam1; - clear c -elseif ~isempty(options_.mode_file) & ~isempty(ls([fname_,'_mean.mat'])) - c=load([fname_,'_mean'],'xparam1'); - xparam1_mean=c.xparam1; - clear c -end - -if options_.opt_gsa.ppost, - fnamtmp=[fname_,'_post']; - DirectoryName = CheckPath('metropolis'); -else - if options_.opt_gsa.pprior - fnamtmp=[fname_,'_prior']; - DirectoryName = CheckPath(['gsa' filesep 'prior']); - else - fnamtmp=[fname_,'_mc']; - DirectoryName = CheckPath(['gsa' filesep 'mc']); - end -end -if ~loadSA, - if exist('xparam1','var') - set_all_parameters(xparam1); - steady_; - ys_mode=oo_.steady_state; - end - if exist('xparam1_mean','var') - set_all_parameters(xparam1_mean); - steady_; - ys_mean=oo_.steady_state; - end - % eval(options_.datafile) - obs = dat_fil_(options_.datafile); - %stock_gend=data_info.gend; - %stock_data = data_info.data; - load([DirectoryName '/' M_.fname '_data.mat']); filfilt = dir([DirectoryName '/' M_.fname '_filter_step_ahead*.mat']); - filparam = dir([DirectoryName '/' M_.fname '_param*.mat']); - x=[]; - logpo2=[]; - sto_ys=[]; - for j=1:length(filparam), - %load([DirectoryName '/' M_.fname '_param',int2str(j),'.mat']); - if isempty(strmatch([M_.fname '_param_irf'],filparam(j).name)) - load([DirectoryName '/' filparam(j).name]); - x=[x; stock]; - logpo2=[logpo2; stock_logpo]; - sto_ys=[sto_ys; stock_ys]; - clear stock stock_logpo stock_ys; - end - end - nruns=size(x,1); - nfilt=floor(pfilt*nruns); - if options_.opt_gsa.ppost || (options_.opt_gsa.ppost==0 && options_.opt_gsa.lik_only==0) - disp(' ') - disp('Computing RMSE''s...') - fobs = options_.first_obs; - nobs=options_.nobs; - for i=1:size(vvarvecm,1), - vj=deblank(vvarvecm(i,:)); - eval(['vobs =obs.',vj,'(fobs:fobs-1+nobs);']) - if options_.prefilter == 1 - %eval([vj,'=',vj,'-bayestopt_.mean_varobs(i);']) - %eval([vj,'=',vj,'-mean(',vj,',1);']) - vobs = vobs-mean(vobs,1); - end - - jxj = strmatch(vj,lgy_(dr_.order_var,:),'exact'); - js = strmatch(vj,lgy_,'exact'); - if exist('xparam1','var') - % if isfield(oo_,'FilteredVariables') - % eval(['rmse_mode(i) = sqrt(mean((vobs(istart:end)-oo_.steady_state(js)-oo_.FilteredVariables.',vj,'(istart:end-1)).^2));']) - % else - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,stock_gend,stock_data,{},0); - y0 = squeeze(aK(1,jxj,:)) + ... - kron(ys_mode(js,:),ones(size(aK,3),1)); - % y0 = ahat(jxj,:)' + ... - % kron(ys_mode(js,:),ones(size(ahat,2),1)); - rmse_mode(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2)); - % end - end - y0=zeros(nobs+1,nruns); - nbb=0; - for j=1:length(filfilt), - load([DirectoryName '/' M_.fname '_filter_step_ahead',num2str(j),'.mat']); - nb = size(stock,4); - % y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,:,:)) + ... - % kron(sto_ys(nbb+1:nbb+nb,js)',ones(size(stock,3),1)); - y0(:,nbb+1:nbb+nb)=squeeze(stock(1,js,1:nobs+1,:)) + ... - kron(sto_ys(nbb+1:nbb+nb,js)',ones(nobs+1,1)); - %y0(:,:,size(y0,3):size(y0,3)+size(stock,3))=stock; - nbb=nbb+nb; - clear stock; - end - y0M=mean(y0,2); - for j=1:nruns, - rmse_MC(j,i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1,j)).^2)); - end - if exist('xparam1_mean','var') - %eval(['rmse_pmean(i) = sqrt(mean((',vj,'(fobs-1+istart:fobs-1+nobs)-y0M(istart:end-1)).^2));']) - [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1_mean,stock_gend,stock_data,{},0); - y0 = squeeze(aK(1,jxj,:)) + ... - kron(ys_mean(js,:),ones(size(aK,3),1)); - % y0 = ahat(jxj,:)' + ... - % kron(ys_mean(js,:),ones(size(ahat,2),1)); - rmse_pmean(i) = sqrt(mean((vobs(istart:end)-y0(istart:end-1)).^2)); - end - end - clear stock_filter; - end - for j=1:nruns, - lnprior(j,1) = priordens(x(j,:)',bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4); - end - likelihood=logpo2(:)-lnprior(:); - disp('... done!') - - if options_.opt_gsa.ppost - save([OutDir,'/',fnamtmp], 'x', 'logpo2', 'likelihood', 'rmse_MC', 'rmse_mode','rmse_pmean') - else - if options_.opt_gsa.lik_only - save([OutDir,'/',fnamtmp], 'likelihood', '-append') - else - save([OutDir,'/',fnamtmp], 'likelihood', 'rmse_MC','-append') - if exist('xparam1_mean','var') - save([OutDir,'/',fnamtmp], 'rmse_pmean','-append') - end - if exist('xparam1','var') - save([OutDir,'/',fnamtmp], 'rmse_mode','-append') - end - end - end -else - if options_.opt_gsa.lik_only & options_.opt_gsa.ppost==0 - load([OutDir,'/',fnamtmp],'x','logpo2','likelihood'); - else - load([OutDir,'/',fnamtmp],'x','logpo2','likelihood','rmse_MC','rmse_mode','rmse_pmean'); - end - lnprior=logpo2(:)-likelihood(:); - nruns=size(x,1); - nfilt=floor(pfilt*nruns); -end -% smirnov tests -nfilt0=nfilt*ones(size(vvarvecm,1),1); -logpo2=logpo2(:); -if ~options_.opt_gsa.ppost - [dum, ipost]=sort(-logpo2); - [dum, ilik]=sort(-likelihood); -end -if ~options_.opt_gsa.ppost & options_.opt_gsa.lik_only - if options_.opt_gsa.pprior - anam='rmse_prior_post'; - else - anam='rmse_mc_post'; - end - stab_map_1(x, ipost(1:nfilt), ipost(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ipost(1:nfilt),:),alpha2,anam, OutDir); - if options_.opt_gsa.pprior - anam='rmse_prior_lik'; - else - anam='rmse_mc_lik'; - end - stab_map_1(x, ilik(1:nfilt), ilik(nfilt+1:end), anam, 1,[],OutDir); - stab_map_2(x(ilik(1:nfilt),:),alpha2,anam, OutDir); -else - for i=1:size(vvarvecm,1), - [dum, ixx(:,i)]=sort(rmse_MC(:,i)); - if options_.opt_gsa.ppost, - %nfilt0(i)=length(find(rmse_MC(:,i)0.0001 ); - vvarvecm=vvarvecm(ivar,:); - rmse_MC=rmse_MC(:,ivar); - - disp(' ') - % if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior, - disp(['Sample filtered the ',num2str(pfilt*100),'% best RMSE''s for each observed series ...' ]) - % else - % disp(['Sample filtered the best RMSE''s smaller than RMSE at the posterior mean ...' ]) - % end - % figure, boxplot(rmse_MC) - % set(gca,'xticklabel',vvarvecm) - % saveas(gcf,[fname_,'_SA_RMSE']) - - disp(' ') - disp(' ') - disp('RMSE ranges after filtering:') - if options_.opt_gsa.ppost==0 & options_.opt_gsa.pprior, - disp([' best ',num2str(pfilt*100),'% filtered remaining 90%']) - disp([' min max min max posterior mode']) - else - disp([' best filtered remaining ']) - disp([' min max min max posterior mean']) - end - for j=1:size(vvarvecm,1), - disp([vvarvecm(j,:), sprintf('%15.5g',[min(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - max(rmse_MC(ixx(1:nfilt0(j),j),j)) ... - min(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - max(rmse_MC(ixx(nfilt0(j)+1:end,j),j)) ... - rmse_txt(j)])]) - % disp([vvarvecm(j,:), sprintf('%15.5g',[min(logpo2(ixx(1:nfilt,j))) ... - % max(logpo2(ixx(1:nfilt,j))) ... - % min(logpo2(ixx(nfilt+1:end,j))) ... - % max(logpo2(ixx(nfilt+1:end,j)))])]) - end - - SP=zeros(npar+nshock,size(vvarvecm,1)); - for j=1:size(vvarvecm,1), - ns=find(PP(:,j)1),:); - snam=param_names(find(nsp>0),:); - % snam0=bayestopt_.name(find(nsp==0)); - % snam1=bayestopt_.name(find(nsp==1)); - % snam2=bayestopt_.name(find(nsp>1)); - % snam=bayestopt_.name(find(nsp>0)); - nsnam=(find(nsp>1)); - - disp(' ') - disp(' ') - disp('These parameters do not affect significantly the fit of ANY observed series:') - disp(snam0) - disp(' ') - disp('These parameters affect ONE single observed series:') - disp(snam1) - disp(' ') - disp('These parameters affect MORE THAN ONE observed series: trade off exists!') - disp(snam2) - - - %pnam=bayestopt_.name(end-estim_params_.np+1:end); - pnam=bayestopt_.name; - - % plot trade-offs - a00=jet(size(vvarvecm,1)); - for ix=1:ceil(length(nsnam)/5), - figure, - for j=1+5*(ix-1):min(size(snam2,1),5*ix), - subplot(2,3,j-5*(ix-1)) - %h0=cumplot(x(:,nsnam(j)+nshock)); - h0=cumplot(x(:,nsnam(j))); - set(h0,'color',[0 0 0]) - hold on, - np=find(SP(nsnam(j),:)); - %a0=jet(nsp(nsnam(j))); - a0=a00(np,:); - for i=1:nsp(nsnam(j)), %size(vvarvecm,1), - %h0=cumplot(x(ixx(1:nfilt,np(i)),nsnam(j)+nshock)); - h0=cumplot(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j))); - set(h0,'color',a0(i,:)) - end - ydum=get(gca,'ylim'); - %xdum=xparam1(nshock+nsnam(j)); - if exist('xparam1') - xdum=xparam1(nsnam(j)); - h1=plot([xdum xdum],ydum); - set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - end - xlabel('') - title([pnam{nsnam(j)}],'interpreter','none') - end - %subplot(3,2,6) - h0=legend(str2mat('base',vvarvecm(np,:)),0); - set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none') - %h0=legend({'base',vnam{np}}',0); - %set(findobj(get(h0,'children'),'type','text'),'interpreter','none') - if options_.opt_gsa.ppost - saveas(gcf,[OutDir,'/',fname_,'_rmse_post_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_' int2str(ix)]); - else - if options_.opt_gsa.pprior - saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_' int2str(ix)]); - else - saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_' int2str(ix)]); - end - end - end - close all - - for j=1:size(SP,2), - nsx(j)=length(find(SP(:,j))); - end - - number_of_grid_points = 2^9; % 2^9 = 512 !... Must be a power of two. - bandwidth = 0; % Rule of thumb optimal bandwidth parameter. - kernel_function = 'gaussian'; % Gaussian kernel for Fast Fourrier Transform approximaton. - %kernel_function = 'uniform'; % Gaussian kernel for Fast Fourrier Transform approximaton. - - for ix=1:ceil(length(nsnam)/5), - figure, - for j=1+5*(ix-1):min(size(snam2,1),5*ix), - subplot(2,3,j-5*(ix-1)) - optimal_bandwidth = mh_optimal_bandwidth(x(:,nsnam(j)),size(x,1),bandwidth,kernel_function); - [x1,f1] = kernel_density_estimate(x(:,nsnam(j)),number_of_grid_points,... - size(x,1),optimal_bandwidth,kernel_function); - h0 = plot(x1, f1,'k'); - hold on, - np=find(SP(nsnam(j),:)); - %a0=jet(nsp(nsnam(j))); - a0=a00(np,:); - for i=1:nsp(nsnam(j)), %size(vvarvecm,1), - optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),nfilt,bandwidth,kernel_function); - [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt0(np(i)),np(i)),nsnam(j)),number_of_grid_points,... - nfilt, optimal_bandwidth,kernel_function); - h0 = plot(x1, f1); - set(h0,'color',a0(i,:)) - end - ydum=get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]); - if exist('xparam1') - %xdum=xparam1(nshock+nsnam(j)); - xdum=xparam1(nsnam(j)); - h1=plot([xdum xdum],[0 ydum(2)]); - set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - end - xlabel('') - title([pnam{nsnam(j)}],'interpreter','none') - end - h0=legend(str2mat('base',vvarvecm(np,:)),0); - set(h0,'fontsize',6,'position',[0.7 0.1 0.2 0.3],'interpreter','none') - %h0=legend({'base',vnam{np}}',0); - %set(findobj(get(h0,'children'),'type','text'),'interpreter','none') - if options_.opt_gsa.ppost - saveas(gcf,[OutDir,'/',fname_,'_rmse_post_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_post_dens_' int2str(ix)]); - else - if options_.opt_gsa.pprior - saveas(gcf,[OutDir,'/',fname_,'_rmse_prior_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_prior_dens_' int2str(ix)]); - else - saveas(gcf,[OutDir,'/',fname_,'_rmse_mc_dens_',num2str(ix)]) - eval(['print -depsc2 ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]); - eval(['print -dpdf ' OutDir '/' fname_ '_rmse_mc_dens_' int2str(ix)]); - end - end - end - close all - - % for j=1:size(SP,2), - % nfig=0; - % np=find(SP(:,j)); - % for i=1:nsx(j), %size(vvarvecm,1), - % if mod(i,12)==1, - % nfig=nfig+1; - % %figure('name',['Sensitivity of fit of ',vnam{j}]), - % figure('name',['Sensitivity of fit of ',deblank(vvarvecm(j,:)),' ',num2str(nfig)]), - % end - % - % subplot(3,4,i-12*(nfig-1)) - % optimal_bandwidth = mh_optimal_bandwidth(x(ixx(1:nfilt,j),np(i)),nfilt,bandwidth,kernel_function); - % [x1,f1] = kernel_density_estimate(x(ixx(1:nfilt,j),np(i)),number_of_grid_points,... - % nfilt, optimal_bandwidth,kernel_function); - % plot(x1, f1,':k','linewidth',2) - % optimal_bandwidth = mh_optimal_bandwidth(x(ixx(nfilt+1:end,j),np(i)),nruns-nfilt,bandwidth,kernel_function); - % [x1,f1] = kernel_density_estimate(x(ixx(nfilt+1:end,j),np(i)),number_of_grid_points,... - % nruns-nfilt,optimal_bandwidth,kernel_function); - % hold on, plot(x1, f1,'k','linewidth',2) - % ydum=get(gca,'ylim'); - % %xdum=xparam1(nshock+np(i)); - % xdum=xparam1(np(i)); - % h1=plot([xdum xdum],ydum); - % set(h1,'color',[0.85 0.85 0.85],'linewidth',2) - % %xdum1=mean(x(ixx(1:nfilt,j),np(i)+nshock)); - % xdum1=mean(x(ixx(1:nfilt,j),np(i))); - % h2=plot([xdum1 xdum1],ydum); - % set(h2,'color',[0 1 0],'linewidth',2) - % % h0=cumplot(x(nfilt+1:end,np(i)+nshock)); - % % set(h0,'color',[1 1 1]) - % % hold on, - % % h0=cumplot(x(ixx(1:nfilt,j),np(i)+nshock)); - % % set(h0,'linestyle',':','color',[1 1 1]) - % %title([pnam{np(i)}]) - % title([pnam{np(i)},'. K-S prob ', num2str(PP(np(i),j))],'interpreter','none') - % xlabel('') - % if mod(i,12)==0 | i==nsx(j), - % saveas(gcf,[fname_,'_rmse_',deblank(vvarvecm(j,:)),'_',int2str(nfig)]) - % close(gcf) - % end - % end - % end - - - disp(' ') - disp(' ') - disp('Sensitivity table (significance and direction):') - vav=char(zeros(1, size(param_names,2)+3 )); - ibl = 12-size(vvarvecm,2); - for j=1:size(vvarvecm,1), - vav = [vav, char(zeros(1,ibl)),vvarvecm(j,:)]; - end - disp(vav) - for j=1:npar+nshock, %estim_params_.np, - %disp([param_names(j,:), sprintf('%8.5g',SP(j,:))]) - disp([param_names(j,:),' ', sprintf('%12.3g',PP(j,:))]) - disp([char(zeros(1, size(param_names,2)+3 )),sprintf(' (%6g)',SS(j,:))]) - end - - - disp(' ') - disp(' ') - disp('Starting bivariate analysis:') - - for i=1:size(vvarvecm,1) - if options_.opt_gsa.ppost - fnam = ['rmse_post_',deblank(vvarvecm(i,:))]; - else - if options_.opt_gsa.pprior - fnam = ['rmse_prior_',deblank(vvarvecm(i,:))]; - else - fnam = ['rmse_mc_',deblank(vvarvecm(i,:))]; - end - end - stab_map_2(x(ixx(1:nfilt0(i),i),:),alpha2,fnam, OutDir); - - % [pc,latent,explained] = pcacov(c0); - % %figure, bar([explained cumsum(explained)]) - % ifig=0; - % j2=0; - % for j=1:npar+nshock, - % i2=find(abs(pc(:,j))>alphaPC); - % if ~isempty(i2), - % j2=j2+1; - % if mod(j2,12)==1, - % ifig=ifig+1; - % figure('name',['PCA of the filtered sample ',deblank(vvarvecm(i,:)),' ',num2str(ifig)]), - % end - % subplot(3,4,j2-(ifig-1)*12) - % bar(pc(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - % title(['PC ',num2str(j),'. Explained ',num2str(explained(j)),'%']) - % end - % if (mod(j2,12)==0 | j==(npar+nshock)) & j2, - % saveas(gcf,[fname_,'_SA_PCA_',deblank(vvarvecm(i,:)),'_',int2str(ifig)]) - % end - % end - % close all - end - -end \ No newline at end of file diff --git a/GSA_distrib/4.2/gamm_cdf.m b/GSA_distrib/4.2/gamm_cdf.m deleted file mode 100644 index a11d0962a..000000000 --- a/GSA_distrib/4.2/gamm_cdf.m +++ /dev/null @@ -1,27 +0,0 @@ -function cdf = gamm_cdf (x, a) -% PURPOSE: returns the cdf at x of the gamma(a) distribution -%--------------------------------------------------- -% USAGE: cdf = gamm_cdf(x,a) -% where: x = a vector -% a = a scalar gamma(a) -%--------------------------------------------------- -% RETURNS: -% a vector of cdf at each element of x of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_inv -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg - -if nargin ~= 2 -error('Wrong # of arguments to gamm_cdf'); -end; - -if any(any(a<=0)) - error('gamm_cdf: parameter a is wrong') -end - -cdf = gammainc(x,a); -I0 = find(x<0); -cdf(I0) = zeros(size(I0)); diff --git a/GSA_distrib/4.2/gamm_inv.m b/GSA_distrib/4.2/gamm_inv.m deleted file mode 100644 index 3bede95ba..000000000 --- a/GSA_distrib/4.2/gamm_inv.m +++ /dev/null @@ -1,50 +0,0 @@ -function x = gamm_inv(p,a,b) -% PURPOSE: returns the inverse of the cdf at p of the gamma(a,b) distribution -%--------------------------------------------------- -% USAGE: x = gamm_inv(p,a) -% where: p = a vector of probabilities -% a = a scalar parameter gamma(a) -% b = scaling factor for gamma -%--------------------------------------------------- -% RETURNS: -% a vector x of the quantile at each element of p of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_d, gamm_pdf, gamm_rnd, gamm_cdf -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg -% documentation modified by LeSage to fit the format -% of the econometrics toolbox - - if (nargin < 2 | isempty(b)) - b=1; - end - - if (nargin > 3) - error('Wrong # of arguments to gamm_inv'); - end - - -if any(any(abs(2*p-1)>1)) - error('gamm_inv: a probability should be 0<=p<=1') -end -if any(any(a<=0)) - error('gamma_inv: parameter a is wrong') -end - -x = max(a-1,0.1); -dx = 1; -while any(any(abs(dx)>256*eps*max(x,1))) - dx = (gamm_cdf(x,a) - p) ./ gamm_pdf(x,a); - x = x - dx; - x = x + (dx - x) / 2 .* (x<0); -end - -I0 = find(p==0); -x(I0) = zeros(size(I0)); -I1 = find(p==1); -x(I1) = zeros(size(I0)) + Inf; - - -x=x.*b; diff --git a/GSA_distrib/4.2/gamm_pdf.m b/GSA_distrib/4.2/gamm_pdf.m deleted file mode 100644 index 86f4ffb1d..000000000 --- a/GSA_distrib/4.2/gamm_pdf.m +++ /dev/null @@ -1,27 +0,0 @@ -function f = gamm_pdf (x, a) -% PURPOSE: returns the pdf at x of the gamma(a) distribution -%--------------------------------------------------- -% USAGE: pdf = gamm_pdf(x,a) -% where: x = a vector -% a = a scalar for gamma(a) -%--------------------------------------------------- -% RETURNS: -% a vector of pdf at each element of x of the gamma(a) distribution -% -------------------------------------------------- -% SEE ALSO: gamm_cdf, gamm_rnd, gamm_inv -%--------------------------------------------------- - -% Anders Holtsberg, 18-11-93 -% Copyright (c) Anders Holtsberg - -if nargin ~= 2 -error('Wrong # of arguments to gamm_cdf'); -end; - -if any(any(a<=0)) - error('gamm_pdf: parameter a is wrong') -end - -f = x .^ (a-1) .* exp(-x) ./ gamma(a); -I0 = find(x<0); -f(I0) = zeros(size(I0)); diff --git a/GSA_distrib/4.2/ghx2transition.m b/GSA_distrib/4.2/ghx2transition.m deleted file mode 100644 index ad3cf110a..000000000 --- a/GSA_distrib/4.2/ghx2transition.m +++ /dev/null @@ -1,54 +0,0 @@ -function [A,B] = ghx2transition(mm,iv,ic,aux) -% [A,B] = ghx2transition(mm,iv,ic,aux) -% -% Adapted by M. Ratto from kalman_transition_matrix.m -% (kalman_transition_matrix.m is part of DYNARE, copyright M. Juillard) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global oo_ M_ - - [nr1, nc1] = size(mm); - ghx = mm(:, [1:(nc1-M_.exo_nbr)]); - ghu = mm(:, [(nc1-M_.exo_nbr+1):end] ); - if nargin == 1 - oo_.dr.ghx = ghx; - oo_.dr.ghu = ghu; - endo_nbr = M_.endo_nbr; - nstatic = oo_.dr.nstatic; - npred = oo_.dr.npred; - iv = (1:endo_nbr)'; - ic = [ nstatic+(1:npred) endo_nbr+(1:size(oo_.dr.ghx,2)-npred) ]'; - aux = oo_.dr.transition_auxiliary_variables; - k = find(aux(:,2) > npred); - aux(:,2) = aux(:,2) + nstatic; - aux(k,2) = aux(k,2) + oo_.dr.nfwrd; - end - n_iv = length(iv); - n_ir1 = size(aux,1); - nr = n_iv + n_ir1; - - A = zeros(nr,nr); - B = zeros(nr,M_.exo_nbr); - - i_n_iv = 1:n_iv; - A(i_n_iv,ic) = ghx(iv,:); - if n_ir1 > 0 - A(n_iv+1:end,:) = sparse(aux(:,1),aux(:,2),ones(n_ir1,1),n_ir1,nr); - end - - B(i_n_iv,:) = ghu(iv,:); diff --git a/GSA_distrib/4.2/log_trans_.m b/GSA_distrib/4.2/log_trans_.m deleted file mode 100644 index b0ff26ddf..000000000 --- a/GSA_distrib/4.2/log_trans_.m +++ /dev/null @@ -1,54 +0,0 @@ -function [yy, xdir, isig, lam]=log_trans_(y0,xdir0) - -if nargin==1, - xdir0=''; -end -f=inline('skewness(log(y+lam))','lam','y'); -isig=1; -if ~(max(y0)<0 | min(y0)>0) - if skewness(y0)<0, - isig=-1; - y0=-y0; - end - n=hist(y0,10); - if n(1)>20*n(end), - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+abs(median(y0))],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))0 - %yy=log(y0); - xdir=[xdir0,'_log']; - end - try lam=fzero(f,[-min(y0)+10*eps -min(y0)+median(y0)],[],y0); - catch - yl(1)=f(-min(y0)+10*eps,y0); - yl(2)=f(-min(y0)+abs(median(y0)),y0); - if abs(yl(1))1, - ifig=0; - for j=1:M_.exo_nbr, - if mod(j,6)==1 - figure('name',['Variance decomposition shocks']); - ifig=ifig+1; - iplo=0; - end - iplo=iplo+1; - subplot(2,3,iplo) - myboxplot(squeeze(vdec(:,j,:))',[],'.',[],10) - % boxplot(squeeze(vdec(:,j,:))','whis',10,'symbol','.r') - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:size(options_.varobs,1)]) - set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5]) - set(gca,'ylim',[-2 102]) - for ip=1:size(options_.varobs,1), - text(ip,-4,deblank(options_.varobs(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - ylabel(' ') - title(M_.exo_names(j,:),'interpreter','none') - if mod(j,6)==0 | j==M_.exo_nbr, - saveas(gcf,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)]) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_vdec_exo_',int2str(ifig)]); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_vdec_exo_',int2str(ifig)]); - close(gcf), - end - end - end - for j=1:size(cc,1) - cc(j,j,:)=stand_(squeeze(log(cc(j,j,:))))./2; - end - [vdec, j0, ir_vdec, ic_vdec] = teff(vdec,Nsam,istable); - [cc, j0, ir_cc, ic_cc] = teff(cc,Nsam,istable); - [ac, j0, ir_ac, ic_ac] = teff(ac,Nsam,istable); - - [nr1, nc1, nnn] = size(T); - endo_nbr = M_.endo_nbr; - nstatic = oo_.dr.nstatic; - npred = oo_.dr.npred; - iv = (1:endo_nbr)'; - ic = [ nstatic+(1:npred) endo_nbr+(1:size(oo_.dr.ghx,2)-npred) ]'; - aux = oo_.dr.transition_auxiliary_variables; - k = find(aux(:,2) > npred); - aux(:,2) = aux(:,2) + nstatic; - aux(k,2) = aux(k,2) + oo_.dr.nfwrd; - - dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],1); - dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], 1); - [Aa,Bb] = kalman_transition_matrix(dr, ... - iv, ic, aux, M_.exo_nbr); -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux, M_.exo_nbr); - A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable)); - % Sig(estim_params_.var_exo(:,1))=lpmatx(1,:).^2; - set_shocks_param(lpmatx(1,:)); - A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; - for j=2:length(istable), - dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],j); - dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], j); - [Aa,Bb] = kalman_transition_matrix(dr, ... - iv, ic, aux, M_.exo_nbr); -% bayestopt_.restrict_var_list, ... -% bayestopt_.restrict_columns, ... -% bayestopt_.restrict_aux, M_.exo_nbr); - set_shocks_param(lpmatx(j,:)); - A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')]; - end - clear T; - clear lpmatx; - - [nr,nc,nn]=size(A); - io=bayestopt_.mf2; - % T1=A(io,1:nr,:); - % ino=find(~ismember([1:nr],io)); - % T2=A(ino,1:nr,:); - R=A(:,nr+1:nc,:); -% [tadj, iff] = speed(A(1:nr,1:nr,:),R,io,0.5); -% [tadj, j0, ir_tadj, ic_tadj] = teff(tadj,Nsam,istable); -% [iff, j0, ir_if, ic_if] = teff(iff,Nsam,istable); - - - [yt, j0]=teff(A,Nsam,istable); - yt = [yys yt]; - if opt_gsa.morris==2, -% iii=find(std(yt(istable,:))>1.e-8); -% if max(max(abs(TAU-yt(istable,iii)')))<= 1.e-8, -% err = max(max(abs(TAU-yt(istable,iii)'))); -% disp(['Model check OK ',num2str(err)]), - clear TAU A -% end - else - clear A, - end - % [yt1, j01]=teff(T1,Nsam,istable); - % [yt2, j02]=teff(T2,Nsam,istable); - % [ytr, j0r]=teff(R,Nsam,istable); - % - % yt=[yt1 yt2 ytr]; - save([OutputDirectoryName,'/',fname_,'_main_eff'],'ac','cc','vdec','yt','mss') -else - if opt_gsa.morris==2, -% [pdraws, TAU, GAM] = dynare_identification([1:npT]); %,[lpmatx lpmat(istable,:)]); - [pdraws, TAU, GAM] = dynare_identification(options_.options_ident); - end - load([OutputDirectoryName,'/',fname_,'_main_eff'],'ac','cc','vdec','yt','mss') -end - -% for j=1:nr, -% for i=1:nc, -% y0=squeeze(A(j,i,:)); -% if max(y0)-min(y0)>1.e-10, -% j0=j0+1; -% y1=ones(size(lpmat,1),1)*NaN; -% y1(istable,1)=y0; -% yt(:,j0)=y1; -% end -% end -% end -% yt = yt(:,j0); - -if opt_gsa.morris==1, - %OutputDir = CheckPath('GSA/SCREEN'); - if ~isempty(vdec), - if opt_gsa.load_ident_files==0, - SAMorris = []; - for i=1:size(vdec,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv); - end - SAvdec = squeeze(SAMorris(:,1,:))'; - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec') - end - - figure, -% boxplot(SAvdec,'whis',10,'symbol','r.') - myboxplot(SAvdec,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('All variance decomposition') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec']); - close(gcf) - else - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'vdec') - - end - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET variance decomposition observed variables']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],3) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]); -% close(gcf) -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET variance decomposition shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],3) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - - if opt_gsa.load_ident_files==0, - SAMorris = []; - ccac = [mss cc ac]; - for i=1:size(ccac,2), - [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv); - end - SAcc = squeeze(SAMorris(:,1,:))'; - SAcc = SAcc./(max(SAcc')'*ones(1,npT)); - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc','-append') - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac','-append') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc') - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac') - end - - figure, -% boxplot(SAcc,'whis',10,'symbol','r.') - myboxplot(SAcc,[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('EET All moments') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_moments']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_moments']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_moments']); -% close(gcf), - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% MORRIS FOR DERIVATIVES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% if opt_gsa.load_ident_files==0, -% for j=1:npT, -% SAMorris = []; -% ddd=NaN(size(lpmat,1),size(JJ,1)); -% ddd(istable,:) = squeeze(JJ(:,j,:))'; -% for i=1:size(ddd,2), -% [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ddd(:,i)],nliv); -% end -% SAddd(:,:,j) = squeeze(SAMorris(:,1,:))'; -% SAddd(:,:,j) = SAddd(:,:,j)./(max(SAddd(:,:,j)')'*ones(1,npT)); -% sad(:,j) = median(SAddd(find(~isnan(squeeze(SAddd(:,1,j)))),:,j))'; -% end -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad') -% end -% figure, -% contourf(sad,10), colorbar -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'yticklabel',' ','fontsize',10,'ytick',[1:npT]) -% for ip=1:npT, -% text(ip,0.9,['D(',bayestopt_.name{ip},')'],'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(0.9,ip,[bayestopt_.name{ip}],'rotation',0,'HorizontalAlignment','right','interpreter','none') -% end -% [m,im]=max(sad); -% iii = find((im-[1:npT])==0); -% disp('Most identified params') -% disp(bayestopt_.name(iii)) - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% END OF MORRIS FOR DERIVATIVES -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET cross-correlations']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_cc==j); -% iv = [iv; find(ic_cc==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAcc(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAcc(iv,:),[],'.',[],3) -% else -% plot(SAcc(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_cc_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]); -% close(gcf), -% end -% end - - -% if opt_gsa.load_ident_files==0, -% SAMorris = []; -% for i=1:size(ac,2), -% [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], ac(:,i),nliv); -% end -% %end -% SAac = squeeze(SAMorris(:,1,:))'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac') -% end -% figure, -% % boxplot(SAac,'whis',10,'symbol','r.') -% myboxplot(SAac,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('EET All auto-correlations') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac']); -% close(gcf), - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET auto-correlations']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_ac==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAac(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAac(iv,:),[],'.',[],3) -% else -% plot(SAac(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]); -% close(gcf), -% end -% end - -% if opt_gsa.load_ident_files==0, -% js=0; -% %for j=1:size(tadj,1), -% SAMorris = []; -% for i=1:size(tadj,2), -% js=js+1; -% [SAmeas, SAMorris(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], tadj(:,i),nliv); -% end -% %end -% SAM = squeeze(SAMorris(nshock+1:end,1,:)); -% for j=1:js, -% SAtadj(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); -% end -% SAtadj = SAtadj'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj') -% end -% if opt_gsa.load_ident_files==0, -% js=0; -% SAMorris = []; -% for i=1:size(iff,2), -% js=js+1; -% [SAmeas, SAMorriss(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], iff(:,i),nliv); -% end -% SAM = squeeze(SAMorriss(nshock+1:end,1,:)); -% for j=1:js, -% SAIF(:,j)=SAM(:,j)./(max(SAM(:,j))+eps); -% end -% SAIF = SAIF'; -% save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if') -% end -% figure, -% %bar(SAtadj), -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAtadj,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title('All half-life') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj']); -% close(gcf), - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET speed of adjustment observed variables']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],3) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end - -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET speed of adjustment shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],3) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - -% figure, -% %bar(SAIF), -% % boxplot(SAIF,'whis',10,'symbol','r.') -% myboxplot(SAIF,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% set(gca,'ylim',[0 1]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% ylabel('Elementary Effects') -% title('Steady state gains (impact factors)') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain']) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain']); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain']); -% close(gcf), - %figure, bar(SAIF'), title('All Gain Relationships') -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['EET steady state gain observed series']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAIF(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAIF(iv,:),[],'.',[],10) -% else -% plot(SAIF(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['EET steady state gain shocks']); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAIF(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAIF(iv,:),[],'.',[],3) -% else -% plot(SAIF(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - - if opt_gsa.load_ident_files==0, - SAMorris = []; - for j=1:j0, - [SAmeas, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv); - end - -% SAM = squeeze(SAMorris(nshock+1:end,1,:)); - SAM = squeeze(SAMorris(1:end,1,:)); - for j=1:j0 - SAnorm(:,j)=SAM(:,j)./max(SAM(:,j)); - irex(j)=length(find(SAnorm(:,j)>0.01)); - end - [dum, irel]=sort(irex); - -% SAMmu = squeeze(SAMorris(nshock+1:end,2,:)); - SAMmu = squeeze(SAMorris(1:end,2,:)); - for j=1:j0 - SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j)); % normalised w.r.t. mu* - end -% SAMsig = squeeze(SAMorris(nshock+1:end,3,:)); - SAMsig = squeeze(SAMorris(1:end,3,:)); - for j=1:j0 - SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j)); - end - save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm','-append') - else - load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm') - end - figure, %bar(SAnorm(:,irel)) -% boxplot(SAnorm','whis',10,'symbol','r.') - myboxplot(SAnorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('Elementary effects in the model') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_par']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_par']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_par']); - - figure, %bar(SAmunorm(:,irel)) -% boxplot(SAmunorm','whis',10,'symbol','r.') - myboxplot(SAmunorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[-1 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('\mu in the model') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morrismu_par']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morrismu_par']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morrismu_par']); - close(gcf), - - figure, %bar(SAsignorm(:,irel)) -% boxplot(SAsignorm','whis',10,'symbol','r.') - myboxplot(SAsignorm',[],'.',[],10) - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - set(gca,'ylim',[0 1]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - xlabel(' ') - for ip=1:npT, - text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title('\sigma in the model') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_morrissig_par']) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morrissig_par']); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morrissig_par']); - close(gcf), - - % figure, bar(SAnorm(:,irel)') - % set(gca,'xtick',[1:j0]) - % set(gca,'xlim',[0.5 j0+0.5]) - % title('Elementary effects relationships') - % saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_redform']) - % eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_redform']); - % eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_redform']); - -elseif opt_gsa.morris==3, - np=estim_params_.np; - na=(4*np+1)*opt_gsa.Nsam; - for j=1:j0, - [idex(j,:), yd(j,:)] = spop_ide(lpmat, yt(:,j), opt_gsa.Nsam, 5-1); - end - iok=find(~isnan(yt(1:opt_gsa.Nsam,1))); - yr=NaN*ones(size(lpmat,1),j0); - for j=1:j0, - ys(j,:)=yd(j,:)./max(yd(j,:)); - [dum, is]=sort(yt(iok,j)); - yr(iok(is),j)=[1:length(iok)]'./length(iok); - yr(istable(length(iok)+1:end),j) = interp1(yt(iok,j),yr(iok,j),yt(istable(length(iok)+1:end),j),'','extrap'); - ineg=find(yr(:,j)<0); - if any(ineg), - [dum, is]=sort(yr(ineg,j)); - yr(ineg(is),j)=-[length(ineg):-1:1]./length(iok); - - end - [idex_r(j,:), yd_r(j,:)] = spop_ide(lpmat, yr(:,j), opt_gsa.Nsam, 5-1); - ys_r(j,:)=yd_r(j,:)./max(yd_r(j,:)); - - end, - figure, bar((idex.*ys)./opt_gsa.Nsam), title('Relationships') - figure, bar((idex.*ys)'./opt_gsa.Nsam), title('Parameters') - figure, bar((idex_r.*ys_r)./opt_gsa.Nsam), title('Relationships rank') - figure, bar((idex_r.*ys_r)'./opt_gsa.Nsam), title('Parameters rank') - [v0,d0]=eig(corrcoef(yt(iok,:))); - ee=diag(d0); - ee=ee([end:-1:1])./j0; - i0=length(find(ee>0.01)); - v0=v0(:,[end:-1:1]); - for j=1:i0, - [idex_pc(j,:), yd_pc(j,:)] = spop_ide(lpmat, yt*v0(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:i0, - ys_pc(j,:)=yd_pc(j,:)./max(yd_pc(j,:)); - end, - figure, bar((idex_pc.*ys_pc)./opt_gsa.Nsam), title('Relationships PCA') - figure, bar((idex_pc.*ys_pc)'./opt_gsa.Nsam), title('Parameters PCA') - - [vr,dr]=eig(corrcoef(yr(iok,:))); - er=diag(dr); - er=er([end:-1:1])./j0; - ir0=length(find(er>0.01)); - vr=vr(:,[end:-1:1]); - for j=1:ir0, - [idex_pcr(j,:), yd_pcr(j,:)] = spop_ide(lpmat, yr*vr(:,j), opt_gsa.Nsam, 5-1); - end - for j=1:ir0, - ys_pcr(j,:)=yd_pcr(j,:)./max(yd_pcr(j,:)); - end, - figure, bar((idex_pcr.*ys_pcr)./opt_gsa.Nsam), title('Relationships rank PCA') - figure, bar((idex_pcr.*ys_pcr)'./opt_gsa.Nsam), title('Parameters rank PCA') - -elseif opt_gsa.morris==2, % ISKREV staff - return, - - -else, % main effects analysis - - if itrans==0, - fsuffix = ''; - elseif itrans==1, - fsuffix = '_log'; - else - fsuffix = '_rank'; - end - - imap=[1:npT]; - - x0=[lpmat0(istable,:), lpmat(istable,:)]; - nrun=length(istable); - nest=min(250,nrun); - nfit=min(1000,nrun); - -% opt_gsa.load_ident_files=0; - -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec'); -% catch -% EET=[]; -% end -% SAvdec=zeros(size(vdec,2),npT); -% -% for j=1:size(vdec,2), -% if itrans==0, -% y0 = vdec(istable,j); -% elseif itrans==1, -% y0 = log_trans_(vdec(istable,j)); -% else -% y0 = trank(vdec(istable,j)); -% end -% if ~isempty(EET), -% % imap=find(EET.SAvdec(j,:)); -% % [dum, isort]=sort(-EET.SAvdec(j,:)); -% imap=find(EET.SAvdec(j,:) >= (0.1.*max(EET.SAvdec(j,:))) ); -% end -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames); -% end -% -% SAvdec(j,imap)=gsa_(j).si; -% imap_vdec{j}=imap; -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec') -% end -% figure, -% % boxplot(SAvdec,'whis',10,'symbol','r.') -% myboxplot(SAvdec,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects variance decomposition ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed variance decomposition ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],10) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks variance decomposition ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_vdec==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAvdec(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAvdec(iv,:),[],'.',[],10) -% else -% plot(SAvdec(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',3,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(M_.exo_names(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==M_.exo_nbr -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end - - if opt_gsa.load_ident_files==0, - try - EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAcc','ir_cc','ic_cc'); - catch - EET=[]; - end - ccac = stand_([mss cc ac]); - [pcc, dd] = eig(cov(ccac(istable,:))); - [latent, isort] = sort(-diag(dd)); - latent = -latent; - figure, bar(latent) - title('Eigenvalues in PCA') - pcc=pcc(:,isort); - ccac = ccac*pcc; -% npca = min(40, max(find(cumsum(latent)./length(latent)<0.99))+1); - npca = max(find(cumsum(latent)./length(latent)<0.99))+1; - siPCA = (EET.SAcc'*abs(pcc'))'; -% siPCA = siPCA./(max(siPCA')'*ones(1,npT)).*(latent*ones(1,npT)); - siPCA = siPCA./(max(siPCA')'*ones(1,npT)); -% siPCA = sum(siPCA,1); -% siPCA = siPCA./max(siPCA); - SAcc=zeros(size(ccac,2),npT); - for j=1:npca, %size(ccac,2), - if itrans==0, - y0 = ccac(istable,j); - elseif itrans==1, - y0 = log_trans_(ccac(istable,j)); - else - y0 = trank(ccac(istable,j)); - end - if ~isempty(EET), -% imap=find(EET.SAvdec(j,:)); -% [dum, isort]=sort(-EET.SAvdec(j,:)); - imap=find(siPCA(j,:) >= (0.1.*max(siPCA(j,:))) ); -% imap=find(EET.SAcc(j,:) >= (0.1.*max(EET.SAcc(j,:))) ); - end - gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... - 2, [],[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames); -% end - SAcc(j,imap)=gsa_(j).si; - imap_cc{j}=imap; - - end - save([OutputDirectoryName,'/map_cc',fsuffix],'gsa_') - save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac','-append') - else - load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac') - - end -% figure, -% % boxplot(SAcc,'whis',10,'symbol','r.') -% myboxplot(SAcc,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% ylabel(' ') -% title(['Main effects moments''s PCA ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% close(gcf), - -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects cross-covariances ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_cc==j); -% iv = [iv; find(ic_cc==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAcc(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAcc(iv,:),[],'.',[],10) -% else -% plot(SAcc(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(options_.varobs(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix,'_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAac','ir_ac','ic_ac'); -% catch -% EET=[]; -% end -% SAac=zeros(size(ac,2),npT); -% for j=1:size(ac,2), -% if itrans==0, -% y0 = ac(istable,j); -% elseif itrans==1, -% y0 = log_trans_(ac(istable,j)); -% else -% y0 = trank(ac(istable,j)); -% end -% if ~isempty(EET), -% imap=find(EET.SAac(j,:) >= (0.1.*max(EET.SAac(j,:))) ); -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames); -% end -% SAac(j,imap)=gsa_(j).si; -% imap_ac{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac') -% end -% -% figure, -% % boxplot(SAac,'whis',10,'symbol','r.') -% myboxplot(SAac,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects 1 lag auto-covariances ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects auto-covariances ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_ac==j); -% %iv = [iv; find(ic_ac==j)]; -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAac(iv,:),'whis',10,'symbol','r.'); -% myboxplot(SAac(iv,:),[],'.',[],10) -% else -% plot(SAac(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:npT, -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% set(gca,'fontsize',10) -% end -% title(options_.varobs(j,:),'interpreter','none','fontsize',10) -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix,'_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]); -% close(gcf), -% end -% end - -% x0=x0(:,nshock+1:end); - imap=[1:npT]; - -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAtadj','ir_tadj','ic_tadj'); -% ny=size(EET.SAtadj,1); -% catch -% EET=[]; -% end -% SAtadj=zeros(size(tadj,2),np); -% for j=1:size(tadj,2), -% if itrans==0, -% y0 = tadj(istable,j); -% elseif itrans==1, -% y0 = log_trans_(tadj(istable,j)); -% else -% y0 = trank(tadj(istable,j)); -% end -% if ~isempty(EET), -% if size(tadj,2)~=ny, -% jj=find(EET.ir_tadj==ir_tadj(j)); -% jj=jj(find(EET.ic_tadj(jj)==ic_tadj(j))); -% if ~isempty(jj), -% imap=find(EET.SAtadj(jj,:) >= (0.1.*max(EET.SAtadj(jj,:))) ); -% else -% imap=[1:np]; -% end -% else -% imap=find(EET.SAtadj(j,:) >= (0.1.*max(EET.SAtadj(j,:))) ); -% end -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames); -% end -% SAtadj(j,imap)=gsa_(j).si; -% imap_tadj{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj') -% end -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAtadj,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects speed of adjustment ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed speed adjustment ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],10) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks speed of adjustment ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_tadj==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAtadj(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAtadj(iv,:),[],'.',[],10) -% else -% plot(SAtadj(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr, -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% -% if opt_gsa.load_ident_files==0, -% try -% EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAIF','ir_if','ic_if'); -% catch -% EET=[]; -% end -% SAif=zeros(size(iff,2),np); -% for j=1:size(iff,2), -% if itrans==0, -% y0 = iff(istable,j); -% elseif itrans==1, -% y0 = log_trans_(iff(istable,j)); -% else -% y0 = trank(iff(istable,j)); -% end -% if ~isempty(EET), -% imap=find(EET.SAIF(j,:) >= (0.1.*max(EET.SAIF(j,:))) ); -% end -% % gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ... -% % gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ... -% 2, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% if nfit>nest, -% gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ... -% -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames); -% end -% SAif(j,imap)=gsa_(j).si; -% imap_if{j}=imap; -% -% end -% save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if','-append') -% else -% load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if') -% end -% -% figure, -% % boxplot(SAif,'whis',10,'symbol','r.') -% myboxplot(SAif,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects impact factors ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]); -% close(gcf), -% -% ifig = 0; -% for j=1:size(options_.varobs,1) -% if mod(j,6)==1 -% figure('name',['Main effects observed impact factors ',fsuffix]); -% ifig=ifig+1; -% iplo = 0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ir_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAif(iv,:),[],'.',[],10) -% else -% plot(SAif(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(options_.varobs(j,:),'interpreter','none') -% if mod(j,6)==0 | j==size(options_.varobs,1) -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_varobs_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]); -% close(gcf), -% end -% end -% -% ifig = 0; -% for j=1:M_.exo_nbr, -% if mod(j,6)==1 -% figure('name',['Main effects shocks impact factors ',fsuffix]); -% ifig=ifig+1; -% iplo=0; -% end -% iplo=iplo+1; -% subplot(3,2,iplo) -% iv = find(ic_if==j); -% if ~isempty(iv) -% if length(iv)>1 -% % boxplot(SAif(iv,:),'whis',3,'symbol','r.'); -% myboxplot(SAif(iv,:),[],'.',[],10) -% else -% plot(SAif(iv,:),'r.'); -% end -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% end -% title(M_.exo_names(j,:),'interpreter','none') -% if mod(j,6)==0 | j==M_.exo_nbr -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_exo_',int2str(ifig)]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]); -% close(gcf), -% end -% end -% SAmom = [SAvdec' SAcc' SAac']'; -% SAdyn = [SAtadj' SAif']'; -% SAall = [SAmom(:,nshock+1:end)' SAdyn']'; -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAmom,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) -% set(gca,'xlim',[0.5 npT+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:npT, -% % text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects theoretical moments ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_moments',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]); -% % close(gcf), -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAdyn,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects short-long term dynamics ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_dynamics',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]); -% % close(gcf), -% -% figure, -% % boxplot(SAtadj,'whis',10,'symbol','r.') -% myboxplot(SAall,[],'.',[],10) -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -% set(gca,'xlim',[0.5 np+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:np, -% text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Main effects all ',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ALL',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]); -% % close(gcf), - -% for j=1:size(SAall,1), -% SAallN(j,:)=SAall(j,:)./max(SAall(j,:)); -% end -% SAmean=mean(SAallN); -% for j=1:size(SAmom,1), -% SAmomN(j,:)=SAmom(j,1:nshock)./max(SAmom(j,1:nshock)); -% end -% SAmomN(find(isnan(SAmomN)))=0; -% SAmeanexo=mean(SAmomN(:,1:nshock)); - -% figure, bar(latent'*SAcc), - figure, bar(sum(SAcc)), - set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT]) - set(gca,'xlim',[0.5 npT+0.5]) - ydum = get(gca,'ylim'); - set(gca,'ylim',[0 ydum(2)]) - set(gca,'position',[0.13 0.2 0.775 0.7]) - for ip=1:npT, - text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - % text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - xlabel(' ') - title(['Identifiability indices in the ',fsuffix,' moments.'],'interpreter','none') - saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix]) - eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_ALL',fsuffix]); - eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_ALL',fsuffix]); - -% figure, bar(SAmeanexo), -% set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:nshock]) -% set(gca,'xlim',[0.5 nshock+0.5]) -% ydum = get(gca,'ylim'); -% set(gca,'ylim',[0 ydum(2)]) -% set(gca,'position',[0.13 0.2 0.775 0.7]) -% for ip=1:nshock, -% % text(ip,-0.02*(ydum(2)),deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -% text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none') -% end -% xlabel(' ') -% title(['Identifiability indices for shocks',fsuffix],'interpreter','none') -% saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_SHOCKS',fsuffix]) -% eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); -% eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]); -end - -return diff --git a/GSA_distrib/4.2/mc_moments.m b/GSA_distrib/4.2/mc_moments.m deleted file mode 100644 index 0f38ff6a6..000000000 --- a/GSA_distrib/4.2/mc_moments.m +++ /dev/null @@ -1,25 +0,0 @@ -function [vdec, cc, ac] = mc_moments(mm, ss, dr) -global options_ M_ - - [nr1, nc1, nsam] = size(mm); - disp('Computing theoretical moments ...') - h = waitbar(0,'Theoretical moments ...'); - - for j=1:nsam, - dr.ghx = mm(:, [1:(nc1-M_.exo_nbr)],j); - dr.ghu = mm(:, [(nc1-M_.exo_nbr+1):end], j); - if ~isempty(ss), - set_shocks_param(ss(j,:)); - end - [vdec(:,:,j), corr, autocorr, z, zz] = th_moments(dr,options_.varobs); - cc(:,:,j)=triu(corr); - dum=[]; - for i=1:options_.ar - dum=[dum, autocorr{i}]; - end - ac(:,:,j)=dum; - waitbar(j/nsam,h) - end - close(h) - disp(' ') - disp('... done !') diff --git a/GSA_distrib/4.2/myboxplot.m b/GSA_distrib/4.2/myboxplot.m deleted file mode 100644 index 096d1a854..000000000 --- a/GSA_distrib/4.2/myboxplot.m +++ /dev/null @@ -1,158 +0,0 @@ - -function sout = myboxplot (data,notched,symbol,vertical,maxwhisker) - -% sout = myboxplot (data,notched,symbol,vertical,maxwhisker) - -% % % % endif -if nargin < 5 | isempty(maxwhisker), maxwhisker = 1.5; end -if nargin < 4 | isempty(vertical), vertical = 1; end -if nargin < 3 | isempty(symbol), symbol = ['+','o']; end -if nargin < 2 | isempty(notched), notched = 0; end - -if length(symbol)==1, symbol(2)=symbol(1); end - -if notched==1, notched=0.25; end -a=1-notched; - -% ## figure out how many data sets we have -if iscell(data), - nc = length(data); -else -% if isvector(data), data = data(:); end - nc = size(data,2); -end - -% ## compute statistics -% ## s will contain -% ## 1,5 min and max -% ## 2,3,4 1st, 2nd and 3rd quartile -% ## 6,7 lower and upper confidence intervals for median -s = zeros(7,nc); -box = zeros(1,nc); -whisker_x = ones(2,1)*[1:nc,1:nc]; -whisker_y = zeros(2,2*nc); -outliers_x = []; -outliers_y = []; -outliers2_x = []; -outliers2_y = []; - -for i=1:nc - % ## Get the next data set from the array or cell array - if iscell(data) - col = data{i}(:); - else - col = data(:,i); - end -% ## Skip missing data -% % % % % % % col(isnan(col) | isna (col)) = []; - col(isnan(col)) = []; - - % ## Remember the data length - nd = length(col); - box(i) = nd; - if (nd > 1) -% ## min,max and quartiles -% s(1:5,i) = statistics(col)(1:5); -s(1,i)=min(col); -s(5,i)=max(col); -s(2,i)=myprctilecol(col,25); -s(3,i)=myprctilecol(col,50); -s(4,i)=myprctilecol(col,75); - - - - - - - - -% ## confidence interval for the median - est = 1.57*(s(4,i)-s(2,i))/sqrt(nd); - s(6,i) = max([s(3,i)-est, s(2,i)]); - s(7,i) = min([s(3,i)+est, s(4,i)]); -% ## whiskers out to the last point within the desired inter-quartile range - IQR = maxwhisker*(s(4,i)-s(2,i)); - whisker_y(:,i) = [min(col(col >= s(2,i)-IQR)); s(2,i)]; - whisker_y(:,nc+i) = [max(col(col <= s(4,i)+IQR)); s(4,i)]; -% ## outliers beyond 1 and 2 inter-quartile ranges - outliers = col((col < s(2,i)-IQR & col >= s(2,i)-2*IQR) | (col > s(4,i)+IQR & col <= s(4,i)+2*IQR)); - outliers2 = col(col < s(2,i)-2*IQR | col > s(4,i)+2*IQR); - outliers_x = [outliers_x; i*ones(size(outliers))]; - outliers_y = [outliers_y; outliers]; - outliers2_x = [outliers2_x; i*ones(size(outliers2))]; - outliers2_y = [outliers2_y; outliers2]; - elseif (nd == 1) -% ## all statistics collapse to the value of the point - s(:,i) = col; -% ## single point data sets are plotted as outliers. - outliers_x = [outliers_x; i]; - outliers_y = [outliers_y; col]; - else -% ## no statistics if no points - s(:,i) = NaN; - end -end -% % % % if isempty(outliers2_y) -% % % % outliers2_y= -% ## Note which boxes don't have enough stats -chop = find(box <= 1); - -% ## Draw a box around the quartiles, with width proportional to the number of -% ## items in the box. Draw notches if desired. -box = box*0.23/max(box); -quartile_x = ones(11,1)*[1:nc] + [-a;-1;-1;1;1;a;1;1;-1;-1;-a]*box; -quartile_y = s([3,7,4,4,7,3,6,2,2,6,3],:); - -% ## Draw a line through the median -median_x = ones(2,1)*[1:nc] + [-a;+a]*box; -% median_x=median(col); -median_y = s([3,3],:); - -% ## Chop all boxes which don't have enough stats -quartile_x(:,chop) = []; -quartile_y(:,chop) = []; -whisker_x(:,[chop,chop+nc]) = []; -whisker_y(:,[chop,chop+nc]) = []; -median_x(:,chop) = []; -median_y(:,chop) = []; -% % % % -% ## Add caps to the remaining whiskers -cap_x = whisker_x; -cap_x(1,:) =cap_x(1,:)- 0.05; -cap_x(2,:) =cap_x(2,:)+ 0.05; -cap_y = whisker_y([1,1],:); - -% #quartile_x,quartile_y -% #whisker_x,whisker_y -% #median_x,median_y -% #cap_x,cap_y -% -% ## Do the plot - -mm=min(min(data)); -MM=max(max(data)); - -if vertical - plot (quartile_x, quartile_y, 'b', ... - whisker_x, whisker_y, 'b--', ... - cap_x, cap_y, 'k', ... - median_x, median_y, 'r', ... - outliers_x, outliers_y, [symbol(1),'r'], ... - outliers2_x, outliers2_y, [symbol(2),'r']); - set(gca,'XTick',1:nc); - set(gca, 'XLim', [0.5, nc+0.5]); - set(gca, 'YLim', [mm-(MM-mm)*0.05-eps, MM+(MM-mm)*0.05+eps]); - -else -% % % % % plot (quartile_y, quartile_x, "b;;", -% % % % % whisker_y, whisker_x, "b;;", -% % % % % cap_y, cap_x, "b;;", -% % % % % median_y, median_x, "r;;", -% % % % % outliers_y, outliers_x, [symbol(1),"r;;"], -% % % % % outliers2_y, outliers2_x, [symbol(2),"r;;"]); -end - -if nargout, - sout=s; -end -% % % endfunction \ No newline at end of file diff --git a/GSA_distrib/4.2/myprctilecol.m b/GSA_distrib/4.2/myprctilecol.m deleted file mode 100644 index d99d5ad50..000000000 --- a/GSA_distrib/4.2/myprctilecol.m +++ /dev/null @@ -1,20 +0,0 @@ -function y = myprctilecol(x,p); -xx = sort(x); -[m,n] = size(x); - -if m==1 | n==1 - m = max(m,n); - if m == 1, - y = x*ones(length(p),1); - return; - end - n = 1; - q = 100*(0.5:m - 0.5)./m; - xx = [min(x); xx(:); max(x)]; -else - q = 100*(0.5:m - 0.5)./m; - xx = [min(x); xx; max(x)]; -end - -q = [0 q 100]; -y = interp1(q,xx,p); \ No newline at end of file diff --git a/GSA_distrib/4.2/norm_inv.m b/GSA_distrib/4.2/norm_inv.m deleted file mode 100644 index e676be94e..000000000 --- a/GSA_distrib/4.2/norm_inv.m +++ /dev/null @@ -1,49 +0,0 @@ -function invp = norm_inv(x, m, sd) -% PURPOSE: computes the quantile (inverse of the CDF) -% for each component of x with mean m, standard deviation sd -%--------------------------------------------------- -% USAGE: invp = norm_inv(x,m,v) -% where: x = variable vector (nx1) -% m = mean vector (default=0) -% sd = standard deviation vector (default=1) -%--------------------------------------------------- -% RETURNS: invp (nx1) vector -%--------------------------------------------------- -% SEE ALSO: norm_d, norm_rnd, norm_inv, norm_cdf -%--------------------------------------------------- - -% Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Oct 26, 1994 -% Copyright Dept of Probability Theory and Statistics TU Wien -% Converted to MATLAB by JP LeSage, jpl@jpl.econ.utoledo.edu - - if nargin > 3 - error ('Wrong # of arguments to norm_inv'); - end - - [r, c] = size (x); - s = r * c; - - if (nargin == 1) - m = zeros(1,s); - sd = ones(1,s); - end - - - if length(m)==1, - m = repmat(m,1,s); - end - if length(sd)==1, - sd = repmat(sd,1,s); - end - x = reshape(x,1,s); - m = reshape(m,1,s); - sd = reshape(sd,1,s); - - invp = zeros (1,s); - - invp = m + sd .* (sqrt(2) * erfinv(2 * x - 1)); - - - - invp = reshape (invp, r, c); - diff --git a/GSA_distrib/4.2/optget.m b/GSA_distrib/4.2/optget.m deleted file mode 100644 index b2893e2ce..000000000 --- a/GSA_distrib/4.2/optget.m +++ /dev/null @@ -1,39 +0,0 @@ -% OPTGET Utility to get previously set function default values -% USAGE -% optvalue=optget(funcname,optname,optvalue); -% INPUTS -% funcname : name of function -% optname : name of option -% optval : option value -% OUTPUT -% optval : the current value of the option -% -% If the named field is not already defined, it will be set to -% optvalue, but optvalue has no effect if the field has already -% been set. Use OPTSET to change a previously set field. -% -% optget(funcname) returns the current values of the options structure. - -% Copyright (c) 1997-2000, Paul L. Fackler & Mario J. Miranda -% paul_fackler@ncsu.edu, miranda.4@osu.edu - -function optvalue = optget(funcname,optname,optvalue) - -funcname = lower(funcname); -optvar=[funcname '_options']; -eval(['global ' optvar]) % declare a global variable - -if nargin==1 % return the whole option structure - optvalue=(eval(optvar)); - return -end - -optname = lower(optname); -% if structure is empty or the named field does not exist -% set to the value passed -if isempty(eval(optvar)) | ~isfield(eval(optvar),optname) - eval([optvar '.' optname '=optvalue;']); -% otherwise return the value in the field -else - optvalue = eval([optvar '.' optname]); -end diff --git a/GSA_distrib/4.2/prior_draw_gsa.m b/GSA_distrib/4.2/prior_draw_gsa.m deleted file mode 100644 index 278e1e237..000000000 --- a/GSA_distrib/4.2/prior_draw_gsa.m +++ /dev/null @@ -1,105 +0,0 @@ -function pdraw = prior_draw_gsa(init,rdraw) -% Draws from the prior distributions -% Adapted by M. Ratto from prior_draw (of DYNARE, copyright M. Juillard), -% for use with Sensitivity Toolbox for DYNARE -% -% -% INPUTS -% o init [integer] scalar equal to 1 (first call) or 0. -% o rdraw -% -% OUTPUTS -% o pdraw [double] draw from the joint prior density. -% -% ALGORITHM -% ... -% -% SPECIAL REQUIREMENTS -% MATLAB Statistics Toolbox -% -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -% global M_ options_ estim_params_ bayestopt_ -global bayestopt_ -persistent npar pshape p6 p7 p3 p4 lbcum ubcum - -if init - pshape = bayestopt_.pshape; - p6 = bayestopt_.p6; - p7 = bayestopt_.p7; - p3 = bayestopt_.p3; - p4 = bayestopt_.p4; - npar = length(p6); - pdraw = zeros(npar,1); - lbcum = zeros(npar,1); - ubcum = ones(npar,1); - - % set bounds for cumulative probabilities - for i = 1:npar - switch pshape(i) - case 5% Uniform prior. - p4(i) = min(p4(i),bayestopt_.ub(i)); - p3(i) = max(p3(i),bayestopt_.lb(i)); - case 3% Gaussian prior. - lbcum(i) = 0.5 * erfc(-(bayestopt_.lb(i)-p6(i))/p7(i) ./ sqrt(2));; - ubcum(i) = 0.5 * erfc(-(bayestopt_.ub(i)-p6(i))/p7(i) ./ sqrt(2));; - case 2% Gamma prior. - lbcum(i) = gamm_cdf((bayestopt_.lb(i)-p3(i))/p7(i),p6(i)); - ubcum(i) = gamm_cdf((bayestopt_.ub(i)-p3(i))/p7(i),p6(i)); - case 1% Beta distribution (TODO: generalized beta distribution) - lbcum(i) = betainc((bayestopt_.lb(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); - ubcum(i) = betainc((bayestopt_.ub(i)-p3(i))./(p4(i)-p3(i)),p6(i),p7(i)); - case 4% INV-GAMMA1 distribution - % TO BE CHECKED - lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i))^2)/(2/p6(i)),p7(i)/2); - ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i))^2)/(2/p6(i)),p7(i)/2); - case 6% INV-GAMMA2 distribution - % TO BE CHECKED - lbcum(i) = gamm_cdf((1/(bayestopt_.ub(i)-p3(i)))/(2/p6(i)),p7(i)/2); - ubcum(i) = gamm_cdf((1/(bayestopt_.lb(i)-p3(i)))/(2/p6(i)),p7(i)/2); - otherwise - % Nothing to do here. - end - end - return -end - - -for i = 1:npar - rdraw(:,i) = rdraw(:,i).*(ubcum(i)-lbcum(i))+lbcum(i); - switch pshape(i) - case 5% Uniform prior. - pdraw(:,i) = rdraw(:,i)*(p4(i)-p3(i)) + p3(i); - case 3% Gaussian prior. - pdraw(:,i) = norm_inv(rdraw(:,i),p6(i),p7(i)); - case 2% Gamma prior. - pdraw(:,i) = gamm_inv(rdraw(:,i),p6(i),p7(i))+p3(i); - case 1% Beta distribution (TODO: generalized beta distribution) - pdraw(:,i) = beta_inv(rdraw(:,i),p6(i),p7(i))*(p4(i)-p3(i))+p3(i); - case 4% INV-GAMMA1 distribution - % TO BE CHECKED - pdraw(:,i) = sqrt(1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i)))+p3(i); - case 6% INV-GAMMA2 distribution - % TO BE CHECKED - pdraw(:,i) = 1./gamm_inv(rdraw(:,i),p7(i)/2,2/p6(i))+p3(i); - otherwise - % Nothing to do here. - end -end - - diff --git a/GSA_distrib/4.2/priorcdf.m b/GSA_distrib/4.2/priorcdf.m deleted file mode 100644 index 53d8ec34d..000000000 --- a/GSA_distrib/4.2/priorcdf.m +++ /dev/null @@ -1,50 +0,0 @@ -function [xcum] = priorcdf(para, pshape, p6, p7, p3, p4) -% This procedure transforms x vectors into cumulative values -% pshape: 0 is point mass, both para and p2 are ignored -% 1 is BETA(mean,stdd) -% 2 is GAMMA(mean,stdd) -% 3 is NORMAL(mean,stdd) -% 4 is INVGAMMA(s^2,nu) -% 5 is UNIFORM [p1,p2] -% Adapted by M. Ratto from MJ priordens.m - -nprio = length(pshape); - -i = 1; -while i <= nprio; - a = 0; - b = 0; - if pshape(i) == 1; % (generalized) BETA Prior -% mu = (p1(i)-p3(i))/(p4(i)-p3(i)); -% stdd = p2(i)/(p4(i)-p3(i)); -% a = (1-mu)*mu^2/stdd^2 - mu; -% b = a*(1/mu - 1); - %lnprior = lnprior + lpdfgbeta(para(i),a,b,p3(i),p4(i)) ; - para(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i)); -% xcum(:,i) = betacdf(para(:,i),a,b) ; - xcum(:,i) = betainc(para(:,i),p6(i),p7(i)); - elseif pshape(i) == 2; % GAMMA PRIOR -% b = p2(i)^2/(p1(i)-p3(i)); -% a = (p1(i)-p3(i))/b; - %lnprior = lnprior + lpdfgam(para(i)-p3(i),a,b); -% xcum(:,i) = gamcdf(para(:,i)-p3(i),a,b); - xcum(:,i) = gamm_cdf((para(:,i)-p3(i))./p7(i),p6(i)); - elseif pshape(i) == 3; % GAUSSIAN PRIOR - %lnprior = lnprior + lpdfnorm(para(i),p1(i),p2(i)); -% xcum(:,i) = normcdf(para(:,i),p1(i),p2(i)); - xcum(:,i) = 0.5 * erfc(-(para(:,i)-p6(i))/p7(i) ./ sqrt(2)); - elseif pshape(i) == 4; % INVGAMMA1 PRIOR - %lnprior = lnprior + lpdfig1(para(i),p1(i),p2(i)); -% xcum(:,i) = gamcdf(1/para(:,i).^2,p2(i)/2,2/p1(i)); - xcum(:,i) = gamm_cdf((1./(para(:,i)-p3(i)).^2)/(2/p6(i)),p7(i)/2); - elseif pshape(i) == 5; % UNIFORM PRIOR - %lnprior = lnprior + log(1/(p2(i)-p1(i))); - xcum(:,i) = (para(:,i)-p3(i))./(p4(i)-p3(i)); - elseif pshape(i) == 6; % INVGAMMA2 PRIOR -% lnprior = lnprior + lpdfig2(para(i),p1(i),p2(i)); -% xcum(:,i) = gamcdf(1/para(:,i),p2(i)/2,2/p1(i)); - xcum(:,i) = gamm_cdf((1./(para(:,i)-p3(i)))./(2/p6(i)),p7(i)/2); - end; - i = i+1; -end; - diff --git a/GSA_distrib/4.2/read_data.m b/GSA_distrib/4.2/read_data.m deleted file mode 100644 index f54f66cb6..000000000 --- a/GSA_distrib/4.2/read_data.m +++ /dev/null @@ -1,39 +0,0 @@ -function [gend, data] = read_data -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global options_ bayestopt_ - -rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range); - -options_ = set_default_option(options_,'nobs',size(rawdata,1)-options_.first_obs+1); -gend = options_.nobs; - -rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:); -if options_.loglinear == 1 & ~options_.logdata - rawdata = log(rawdata); -end -if options_.prefilter == 1 - bayestopt_.mean_varobs = mean(rawdata,1); - data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs); -else - data = transpose(rawdata); -end - -if ~isreal(rawdata) - error(['There are complex values in the data. Probably a wrong' ... - ' transformation']) -end diff --git a/GSA_distrib/4.2/redform_map.m b/GSA_distrib/4.2/redform_map.m deleted file mode 100644 index 2350c5993..000000000 --- a/GSA_distrib/4.2/redform_map.m +++ /dev/null @@ -1,351 +0,0 @@ -function redform_map(dirname) -%function redform_map(dirname) -% inputs (from opt_gsa structure -% anamendo = options_gsa_.namendo; -% anamlagendo = options_gsa_.namlagendo; -% anamexo = options_gsa_.namexo; -% iload = options_gsa_.load_redform; -% pprior = options_gsa_.pprior; -% ilog = options_gsa_.logtrans_redform; -% threshold = options_gsa_.threshold_redform; -% ksstat = options_gsa_.ksstat_redform; -% alpha2 = options_gsa_.alpha2_redform; -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global M_ oo_ estim_params_ options_ bayestopt_ - -options_gsa_ = options_.opt_gsa; - -anamendo = options_gsa_.namendo; -anamlagendo = options_gsa_.namlagendo; -anamexo = options_gsa_.namexo; -iload = options_gsa_.load_redform; -pprior = options_gsa_.pprior; -ilog = options_gsa_.logtrans_redform; -threshold = options_gsa_.threshold_redform; -ksstat = options_gsa_.ksstat_redform; -alpha2 = options_gsa_.alpha2_redform; - -pnames = M_.param_names(estim_params_.param_vals(:,1),:); -if nargin==0, - dirname=''; -end - -if pprior - load([dirname,'/',M_.fname,'_prior']); - adir=[dirname '/redform_stab']; -else - load([dirname,'/',M_.fname,'_mc']); - adir=[dirname '/redform_mc']; -end -if ~exist('T') - stab_map_(dirname); -if pprior - load([dirname,'/',M_.fname,'_prior'],'T'); -else - load([dirname,'/',M_.fname,'_mc'],'T'); -end -end -if isempty(dir(adir)) - mkdir(adir) -end -adir0=pwd; -%cd(adir) - -nspred=size(T,2)-M_.exo_nbr; -x0=lpmat(istable,:); -[kn, np]=size(x0); -offset = length(bayestopt_.pshape)-np; -if options_gsa_.prior_range, - pshape=5*(ones(np,1)); - pd = [NaN(np,1) NaN(np,1) bayestopt_.lb(offset+1:end) bayestopt_.ub(offset+1:end)]; -else - pshape = bayestopt_.pshape(offset+1:end); - pd = [bayestopt_.p6(offset+1:end) bayestopt_.p7(offset+1:end) bayestopt_.p3(offset+1:end) bayestopt_.p4(offset+1:end)]; -end - -nsok = length(find(M_.lead_lag_incidence(M_.maximum_lag,:))); -clear lpmat lpmat0 egg iunstable yys -js=0; -for j=1:size(anamendo,1) - namendo=deblank(anamendo(j,:)); - iendo=strmatch(namendo,M_.endo_names(oo_.dr.order_var,:),'exact'); - ifig=0; - iplo=0; - for jx=1:size(anamexo,1) - namexo=deblank(anamexo(jx,:)); - iexo=strmatch(namexo,M_.exo_names,'exact'); - - if ~isempty(iexo), - %y0=squeeze(T(iendo,iexo+nspred,istable)); - y0=squeeze(T(iendo,iexo+nspred,:)); - if (max(y0)-min(y0))>1.e-10, - if mod(iplo,9)==0, - ifig=ifig+1; - hfig = figure('name',[namendo,' vs. shocks ',int2str(ifig)]); - iplo=0; - end - iplo=iplo+1; - js=js+1; - xdir0 = [adir,'/',namendo,'_vs_', namexo]; - if ilog==0, - if isempty(threshold) - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namexo, xdir0); - else - iy=find( (y0>threshold(1)) & (y0=threshold(2))); - xdir = [xdir0,'_cut']; - if ~isempty(iy), - si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir); - end - if ~isempty(iy) & ~isempty(iyc) - delete([xdir, '/*cut*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0); - indsmirnov = find(dproba>ksstat); - stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir); - stab_map_2(x0(iy,:),alpha2,'cut',xdir) - stab_map_2(x0(iyc,:),alpha2,'trim',xdir) - end - end - else - [yy, xdir] = log_trans_(y0,xdir0); - silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namexo, xdir); - end - - figure(hfig) - subplot(3,3,iplo), - if ilog, - [saso, iso] = sort(-silog(:,js)); - bar([silog(iso(1:min(np,10)),js)]) - logflag='log'; - else - [saso, iso] = sort(-si(:,js)); - bar(si(iso(1:min(np,10)),js)) - logflag=''; - end - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([logflag,' ',namendo,' vs. ',namexo],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - close(gcf) - end - - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_shocks_',logflag,num2str(ifig)]); - close(gcf) - end - ifig=0; - iplo=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - %y0=squeeze(T(iendo,ilagendo,istable)); - y0=squeeze(T(iendo,ilagendo,:)); - if (max(y0)-min(y0))>1.e-10, - if mod(iplo,9)==0, - ifig=ifig+1; - hfig = figure('name',[namendo,' vs. lags ',int2str(ifig)]); - iplo=0; - end - iplo=iplo+1; - js=js+1; - xdir0 = [adir,'/',namendo,'_vs_', namlagendo]; - if ilog==0, - if isempty(threshold) - si(:,js) = redform_private(x0, y0, pshape, pd, iload, pnames, namendo, namlagendo, xdir0); - else - iy=find( (y0>threshold(1)) & (y0=threshold(2))); - xdir = [xdir0,'_cut']; - if ~isempty(iy) - si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir); - end - if ~isempty(iy) & ~isempty(iyc), - delete([xdir, '/*cut*.*']) - [proba, dproba] = stab_map_1(x0, iy, iyc, 'cut',0); - indsmirnov = find(dproba>ksstat); - stab_map_1(x0, iy, iyc, 'cut',1,indsmirnov,xdir); - stab_map_2(x0(iy,:),alpha2,'cut',xdir) - stab_map_2(x0(iyc,:),alpha2,'trim',xdir) - end - end - else - [yy, xdir] = log_trans_(y0,xdir0); - silog(:,js) = redform_private(x0, yy, pshape, pd, iload, pnames, namendo, namlagendo, xdir); - end - - figure(hfig), - subplot(3,3,iplo), - if ilog, - [saso, iso] = sort(-silog(:,js)); - bar([silog(iso(1:min(np,10)),js)]) - logflag='log'; - else - [saso, iso] = sort(-si(:,js)); - bar(si(iso(1:min(np,10)),js)) - logflag=''; - end - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - title([logflag,' ',namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - close(gcf) - end - - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_', namendo,'_vs_lags_',logflag,num2str(ifig)]); - close(gcf) - end -end - -if ilog==0, -figure, %bar(si) -% boxplot(si','whis',10,'symbol','r.') -myboxplot(si',[],'.',[],10) -xlabel(' ') -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -title('Reduced form GSA') - -saveas(gcf,[dirname,'/',M_.fname,'_redform_gsa']) -eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_gsa']); -eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_gsa']); - -else -figure, %bar(silog) -% boxplot(silog','whis',10,'symbol','r.') -myboxplot(silog',[],'.',[],10) -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -xlabel(' ') -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -title('Reduced form GSA - Log-transformed elements') - -saveas(gcf,[dirname,'/',M_.fname,'_redform_gsa_log']) -eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_gsa_log']); -eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_gsa_log']); - -end -function si = redform_private(x0, y0, pshape, pd, iload, pnames, namy, namx, xdir) -global bayestopt_ options_ - -opt_gsa=options_.opt_gsa; -np=size(x0,2); -x00=x0; - if opt_gsa.prior_range, - for j=1:np, - x0(:,j)=(x0(:,j)-pd(j,3))./(pd(j,4)-pd(j,3)); - end - else - x0=priorcdf(x0,pshape, pd(:,1), pd(:,2), pd(:,3), pd(:,4)); - end - -fname=[xdir,'/map']; -if iload==0, - figure, hist(y0,30), title([namy,' vs. ', namx]) - if isempty(dir(xdir)) - mkdir(xdir) - end - saveas(gcf,[xdir,'/', namy,'_vs_', namx]) - eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx]); - eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx]); - close(gcf) -% gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames); - nrun=length(y0); - nest=min(250,nrun); - nfit=min(1000,nrun); -% dotheplots = (nfit<=nest); - gsa_ = gsa_sdp(y0(1:nest), x0(1:nest,:), 2, [],[-1 -1 -1 -1 -1 0],[],0,[fname,'_est'], pnames); - if nfit>nest, - gsa_ = gsa_sdp(y0(1:nfit), x0(1:nfit,:), -2, gsa_.nvr*nest^3/nfit^3,[-1 -1 -1 -1 -1 0],[],0,fname, pnames); - end - save([fname,'.mat'],'gsa_') - [sidum, iii]=sort(-gsa_.si); - gsa_.x0=x00(1:nfit,:); - hfig=gsa_sdp_plot(gsa_,fname,pnames,iii(1:min(12,np))); - close(hfig); - gsa_.x0=x0(1:nfit,:); -% copyfile([fname,'_est.mat'],[fname,'.mat']) - figure, - plot(y0(1:nfit),[gsa_.fit y0(1:nfit)],'.'), - title([namy,' vs. ', namx,' fit']) - saveas(gcf,[xdir,'/', namy,'_vs_', namx,'_fit']) - eval(['print -depsc2 ' xdir,'/', namy,'_vs_', namx,'_fit']); - eval(['print -dpdf ' xdir,'/', namy,'_vs_', namx,'_fit']); - close(gcf) - if nfit0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_shocks_',num2str(ifig)]); - close(gcf) - end - - iplo=0; - ifig=0; - for je=1:size(anamlagendo,1) - namlagendo=deblank(anamlagendo(je,:)); - ilagendo=strmatch(namlagendo,M_.endo_names(oo_.dr.order_var(oo_.dr.nstatic+1:oo_.dr.nstatic+nsok),:),'exact'); - - if ~isempty(ilagendo), - y0=teff(T(iendo,ilagendo,:),kn,istable); - if ~isempty(y0), - if mod(iplo,9)==0, - ifig=ifig+1; - figure('name',[namendo,' vs. lagged endogenous ',int2str(ifig)]), - iplo=0; - end - iplo=iplo+1; - js=js+1; - subplot(3,3,iplo), - [SAmeas, SAMorris] = Morris_Measure_Groups(np+nshock, [lpmat0 lpmat], y0,nliv); - SAM = squeeze(SAMorris(nshock+1:end,1)); - SA(:,js)=SAM./(max(SAM)+eps); - [saso, iso] = sort(-SA(:,js)); - bar(SA(iso(1:min(np,10)),js)) - %set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8) - set(gca,'xticklabel',' ','fontsize',10) - set(gca,'xlim',[0.5 10.5]) - for ip=1:min(np,10), - text(ip,-0.02,deblank(pnames(iso(ip),:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') - end - - title([namendo,' vs. ',namlagendo,'(-1)'],'interpreter','none') - if iplo==9, - saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - close(gcf) - end - end - end - end - if iplo<9 & iplo>0 & ifig, - saveas(gcf,[dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]) - eval(['print -depsc2 ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - eval(['print -dpdf ' dirname,'/',M_.fname,'_', namendo,'_vs_lags_',num2str(ifig)]); - close(gcf) - end -end - -figure, -%bar(SA) -% boxplot(SA','whis',10,'symbol','r.') -myboxplot(SA',[],'.',[],10) -set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np]) -set(gca,'xlim',[0.5 np+0.5]) -set(gca,'ylim',[0 1]) -set(gca,'position',[0.13 0.2 0.775 0.7]) -for ip=1:np, - text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none') -end -xlabel(' ') -ylabel('Elementary Effects') -title('Reduced form screening') - -saveas(gcf,[dirname,'/',M_.fname,'_redform_screen']) -eval(['print -depsc2 ' dirname,'/',M_.fname,'_redform_screen']); -eval(['print -dpdf ' dirname,'/',M_.fname,'_redform_screen']); - diff --git a/GSA_distrib/4.2/set_shocks_param.m b/GSA_distrib/4.2/set_shocks_param.m deleted file mode 100644 index f84247d29..000000000 --- a/GSA_distrib/4.2/set_shocks_param.m +++ /dev/null @@ -1,30 +0,0 @@ -function set_shocks_param(xparam1) - global estim_params_ M_ - - nvx = estim_params_.nvx; - ncx = estim_params_.ncx; - np = estim_params_.np; - Sigma_e = M_.Sigma_e; - offset = 0; - if nvx - offset = offset + nvx; - var_exo = estim_params_.var_exo; - for i=1:nvx - k = var_exo(i,1); - Sigma_e(k,k) = xparam1(i)^2; - end - end - - if ncx - offset = offset + estim_params_.nvn; - corrx = estim_params_.corrx; - for i=1:ncx - k1 = corrx(i,1); - k2 = corrx(i,2); - Sigma_e(k1,k2) = xparam1(i+offset)*sqrt(Sigma_e_(k1,k1)*Sigma_e_(k2,k2)); - Sigma_e(k2,k1) = Sigma_e_(k1,k2); - end - end - - - M_.Sigma_e = Sigma_e; \ No newline at end of file diff --git a/GSA_distrib/4.2/skewness.m b/GSA_distrib/4.2/skewness.m deleted file mode 100644 index 19ce487ab..000000000 --- a/GSA_distrib/4.2/skewness.m +++ /dev/null @@ -1,7 +0,0 @@ -function s=skewness(y), - -% y=stand_(y); -% s=mean(y.^3); - m2=mean((y-mean(y)).^2); - m3=mean((y-mean(y)).^3); - s=m3/m2^1.5; \ No newline at end of file diff --git a/GSA_distrib/4.2/smirnov.m b/GSA_distrib/4.2/smirnov.m deleted file mode 100644 index bc068aeb1..000000000 --- a/GSA_distrib/4.2/smirnov.m +++ /dev/null @@ -1,73 +0,0 @@ -function [H,prob,d] = smirnov(x1 , x2 , alpha, iflag ) -% Smirnov test for 2 distributions -% [H,prob,d] = smirnov(x1 , x2 , alpha, iflag ) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - - - -if nargin<3 - alpha = 0.05; -end -if nargin<4, - iflag=0; -end - -% empirical cdfs. -xmix= [x1;x2]; -bin = [-inf ; sort(xmix) ; inf]; - -ncount1 = histc (x1 , bin); -ncount1 = ncount1(:); -ncount2 = histc (x2 , bin); -ncount2 = ncount2(:); - -cum1 = cumsum(ncount1)./sum(ncount1); -cum1 = cum1(1:end-1); - -cum2 = cumsum(ncount2)./sum(ncount2); -cum2 = cum2(1:end-1); - -n1= length(x1); -n2= length(x2); -n = n1*n2 /(n1+n2); - -% Compute the d(n1,n2) statistics. - -if iflag==0, - d = max(abs(cum1 - cum2)); -elseif iflag==-1 - d = max(cum2 - cum1); -elseif iflag==1 - d = max(cum1 - cum2); -end -% -% Compute P-value check H0 hypothesis -% - -lam = max((sqrt(n) + 0.12 + 0.11/sqrt(n)) * d , 0); -if iflag == 0 - j = [1:101]'; - prob = 2 * sum((-1).^(j-1).*exp(-2*lam*lam*j.^2)); - - prob=max(prob,0); - prob=min(1,prob); -else - prob = exp(-2*lam*lam); -end - -H = (alpha >= prob); diff --git a/GSA_distrib/4.2/speed.m b/GSA_distrib/4.2/speed.m deleted file mode 100644 index faaa1de86..000000000 --- a/GSA_distrib/4.2/speed.m +++ /dev/null @@ -1,52 +0,0 @@ -function [tadj, iff] = speed(A,B,mf,p), -% [tadj, iff] = speed(A,B,mf,p), -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -nvar=length(mf); -nstate= size(A,1); -nshock = size(B,2); -nrun=size(B,3); - -iff=zeros(nvar,nshock,nrun); -tadj=iff; -disp('Computing speed of adjustement ...') -h = waitbar(0,'Speed of adjustement...'); - -for i=1:nrun, - irf=zeros(nvar,nshock); - a=squeeze(A(:,:,i)); - b=squeeze(B(:,:,i)); - IFF=inv(eye(nstate)-a)*b; - iff(:,:,i)=IFF(mf,:); - IF=IFF-b; - - t=0; - while any(any(irf<0.5)) - t=t+1; - IFT=((eye(nstate)-a^(t+1))*inv(eye(nstate)-a))*b-b; - irf=IFT(mf,:)./(IF(mf,:)+eps); - irf = irf.*(abs(IF(mf,:))>1.e-7)+(abs(IF(mf,:))<=1.e-7); - %irf=ft(mf,:); - tt=(irf>0.5).*t; - tadj(:,:,i)=((tt-tadj(:,:,i))==tt).*tt+tadj(:,:,i); - end - waitbar(i/nrun,h) -end -disp(' ') -disp('.. done !') -close(h) diff --git a/GSA_distrib/4.2/stab_map_.m b/GSA_distrib/4.2/stab_map_.m deleted file mode 100644 index 2142ec234..000000000 --- a/GSA_distrib/4.2/stab_map_.m +++ /dev/null @@ -1,548 +0,0 @@ -function x0 = stab_map_(OutputDirectoryName) -% -% function x0 = stab_map_(OutputDirectoryName) -% -% Mapping of stability regions in the prior ranges applying -% Monte Carlo filtering techniques. -% -% INPUTS (from opt_gsa structure) -% Nsam = MC sample size -% fload = 0 to run new MC; 1 to load prevoiusly generated analysis -% alpha2 = significance level for bivariate sensitivity analysis -% [abs(corrcoef) > alpha2] -% prepSA = 1: save transition matrices for mapping reduced form -% = 0: no transition matrix saved (default) -% pprior = 1: sample from prior ranges (default): sample saved in -% _prior.mat file -% = 0: sample from posterior ranges: sample saved in -% _mc.mat file -% OUTPUT: -% x0: one parameter vector for which the model is stable. -% -% GRAPHS -% 1) Pdf's of marginal distributions under the stability (dotted -% lines) and unstability (solid lines) regions -% 2) Cumulative distributions of: -% - stable subset (dotted lines) -% - unacceptable subset (solid lines) -% 3) Bivariate plots of significant correlation patterns -% ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets -% -% USES lptauSEQ, -% stab_map_1, stab_map_2 -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -%global bayestopt_ estim_params_ dr_ options_ ys_ fname_ -global bayestopt_ estim_params_ options_ oo_ M_ - -opt_gsa=options_.opt_gsa; - -Nsam = opt_gsa.Nsam; -fload = opt_gsa.load_stab; -ksstat = opt_gsa.ksstat; -alpha2 = opt_gsa.alpha2_stab; -prepSA = (opt_gsa.redform | opt_gsa.identification); -pprior = opt_gsa.pprior; -ilptau = opt_gsa.ilptau; -nliv = opt_gsa.morris_nliv; -ntra = opt_gsa.morris_ntra; - -dr_ = oo_.dr; -%if isfield(dr_,'ghx'), -ys_ = oo_.dr.ys; -nspred = dr_.nspred; %size(dr_.ghx,2); -nboth = dr_.nboth; -nfwrd = dr_.nfwrd; -%end -fname_ = M_.fname; - -np = estim_params_.np; -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; -lpmat0=[]; - -pshape = bayestopt_.pshape(nshock+1:end); -p1 = bayestopt_.p1(nshock+1:end); -p2 = bayestopt_.p2(nshock+1:end); -p3 = bayestopt_.p3(nshock+1:end); -p4 = bayestopt_.p4(nshock+1:end); - -if nargin==0, - OutputDirectoryName=''; -end - -opt=options_; -options_.periods=0; -options_.nomoments=1; -options_.irf=0; -options_.noprint=1; -options_.simul=0; -if fload==0, - % if prepSA - % T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam/2); - % end - - if isfield(dr_,'ghx'), - egg=zeros(length(dr_.eigval),Nsam); - end - yys=zeros(length(dr_.ys),Nsam); - - if opt_gsa.morris == 1 - [lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []); - lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2; - Nsam=size(lpmat,1); - lpmat0 = lpmat(:,1:nshock); - lpmat = lpmat(:,nshock+1:end); - elseif opt_gsa.morris==3, - lpmat = prep_ide(Nsam,np,5); - Nsam=size(lpmat,1); - else - if np<52 & ilptau>0, - [lpmat] = lptauSEQ(Nsam,np); % lptau - if np>30 | ilptau==2, % scrambled lptau - for j=1:np, - lpmat(:,j)=lpmat(randperm(Nsam),j); - end - end - else %ilptau==0 - %[lpmat] = rand(Nsam,np); - for j=1:np, - lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - end - - end - end - % try - dummy=prior_draw_gsa(1); - % catch - % if pprior, - % if opt_gsa.prior_range==0; - % error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!'); - % end - % end - % - % end - if pprior, - for j=1:nshock, - if opt_gsa.morris~=1, - lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - end - if opt_gsa.prior_range - lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j); - end - end - if opt_gsa.prior_range - % if opt_gsa.identification, - % deltx=min(0.001, 1/Nsam/2); - % for j=1:np, - % xdelt(:,:,j)=prior_draw_gsa(0,[lpmat0 lpmat]+deltx); - % end - % end - for j=1:np, - lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock); - end - else - xx=prior_draw_gsa(0,[lpmat0 lpmat]); - % if opt_gsa.identification, - % deltx=min(0.001, 1/Nsam/2); - % ldum=[lpmat0 lpmat]; - % ldum = prior_draw_gsa(0,ldum+deltx); - % for j=1:nshock+np, - % xdelt(:,:,j)=xx; - % xdelt(:,j,j)=ldum(:,j); - % end - % clear ldum - % end - lpmat0=xx(:,1:nshock); - lpmat=xx(:,nshock+1:end); - clear xx; - end - else - % for j=1:nshock, - % xparam1(j) = oo_.posterior_mode.shocks_std.(bayestopt_.name{j}); - % sd(j) = oo_.posterior_std.shocks_std.(bayestopt_.name{j}); - % lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube - % lb = max(bayestopt_.lb(j), xparam1(j)-2*sd(j)); - % ub1=xparam1(j)+(xparam1(j) - lb); % define symmetric range around the mode! - % ub = min(bayestopt_.ub(j),ub1); - % if ub30 & np<52 - % lpmat(:,j) = lpmat(randperm(Nsam),j).*(ub-lb)+lb; - % else - % lpmat(:,j) = lpmat(:,j).*(ub-lb)+lb; - % end - % end - %load([fname_,'_mode']) - eval(['load ' options_.mode_file ';']'); - d = chol(inv(hh)); - lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1'); - for j=1:Nsam*2, - lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub); - end - ireal=[1:2*Nsam]; - ireal=ireal(find(lnprior==0)); - lp=lp(ireal,:); - Nsam=min(Nsam, length(ireal)); - lpmat0=lp(1:Nsam,1:nshock); - lpmat=lp(1:Nsam,nshock+1:end); - clear lp lnprior ireal; - end - % - h = waitbar(0,'Please wait...'); - istable=[1:Nsam]; - jstab=0; - iunstable=[1:Nsam]; - iindeterm=zeros(1,Nsam); - iwrong=zeros(1,Nsam); - for j=1:Nsam, - M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)'; - %try stoch_simul([]); - try - [Tt,Rr,SteadyState,infox{j}] = dynare_resolve('restrict'); - if infox{j}(1)==0 && ~exist('T'), - dr_=oo_.dr; - T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam); - egg=zeros(length(dr_.eigval),Nsam); - end - if infox{j}, - disp('no solution'), - if isfield(oo_.dr,'ghx'), - oo_.dr=rmfield(oo_.dr,'ghx'); - end - end - catch - if isfield(oo_.dr,'eigval'), - oo_.dr=rmfield(oo_.dr,'eigval'); - end - if isfield(oo_.dr,'ghx'), - oo_.dr=rmfield(oo_.dr,'ghx'); - end - disp('No solution could be found'), - end - dr_ = oo_.dr; - if isfield(dr_,'ghx'), - egg(:,j) = sort(dr_.eigval); - iunstable(j)=0; - if prepSA - jstab=jstab+1; - T(:,:,jstab) = [dr_.ghx dr_.ghu]; - % [A,B] = ghx2transition(squeeze(T(:,:,jstab)), ... - % bayestopt_.restrict_var_list, ... - % bayestopt_.restrict_columns, ... - % bayestopt_.restrict_aux); - end - if ~exist('nspred'), - nspred = dr_.nspred; %size(dr_.ghx,2); - nboth = dr_.nboth; - nfwrd = dr_.nfwrd; - end - else - istable(j)=0; - if isfield(dr_,'eigval') - egg(:,j) = sort(dr_.eigval); - if exist('nspred') - if any(isnan(egg(1:nspred,j))) - iwrong(j)=j; - else - if (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium, - iindeterm(j)=j; - end - end - end - else - if exist('egg'), - egg(:,j)=ones(size(egg,1),1).*NaN; - end - iwrong(j)=j; - end - end - ys_=real(dr_.ys); - yys(:,j) = ys_; - ys_=yys(:,1); - waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)]) - end - close(h) - if prepSA, - T=T(:,:,1:jstab); - end - istable=istable(find(istable)); % stable params - iunstable=iunstable(find(iunstable)); % unstable params - iindeterm=iindeterm(find(iindeterm)); % indeterminacy - iwrong=iwrong(find(iwrong)); % dynare could not find solution - - % % map stable samples - % istable=[1:Nsam]; - % for j=1:Nsam, - % if any(isnan(egg(1:nspred,j))) - % istable(j)=0; - % else - % if abs(egg(nspred,j))>=options_.qz_criterium; %(1-(options_.qz_criterium-1)); %1-1.e-5; - % istable(j)=0; - % %elseif (dr_.nboth | dr_.nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5; - % elseif (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5; - % istable(j)=0; - % end - % end - % end - % istable=istable(find(istable)); % stable params - % - % % map unstable samples - % iunstable=[1:Nsam]; - % for j=1:Nsam, - % %if abs(egg(dr_.npred+1,j))>1+1.e-5 & abs(egg(dr_.npred,j))<1-1.e-5; - % %if (dr_.nboth | dr_.nfwrd), - % if ~any(isnan(egg(1:5,j))) - % if (nboth | nfwrd), - % if abs(egg(nspred+1,j))>options_.qz_criterium & abs(egg(nspred,j))0 & length(iunstable)ksstat); - disp('Smirnov statistics in driving acceptable behaviour') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indstab) - stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName); - end - ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong]))); - if ~isempty(iindeterm), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'],0); - indindet=find(dproba>ksstat); - disp('Smirnov statistics in driving indeterminacy') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indindet) - stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'], 1, indindet, OutputDirectoryName); - end - end - - if ~isempty(ixun), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'],0); - indunst=find(dproba>ksstat); - disp('Smirnov statistics in driving instability') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indunst) - stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'], 1, indunst, OutputDirectoryName); - end - end - - if ~isempty(iwrong), - [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'],0); - indwrong=find(dproba>ksstat); - disp('Smirnov statistics in driving no solution') - for j=1:np, - disp([M_.param_names(estim_params_.param_vals(j,1),:),' d-stat = ', num2str(dproba(j),3)]) - end - disp(' '); - if ~isempty(indwrong) - stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'], 1, indwrong, OutputDirectoryName); - end - end - - disp(' ') - disp('Starting bivariate analysis:') - - c0=corrcoef(lpmat(istable,:)); - c00=tril(c0,-1); - - stab_map_2(lpmat(istable,:),alpha2, asname, OutputDirectoryName); - if length(iunstable)>10, - stab_map_2(lpmat(iunstable,:),alpha2, auname, OutputDirectoryName); - end - if length(iindeterm)>10, - stab_map_2(lpmat(iindeterm,:),alpha2, aindname, OutputDirectoryName); - end - if length(ixun)>10, - stab_map_2(lpmat(ixun,:),alpha2, aunstname, OutputDirectoryName); - end - if length(iwrong)>10, - stab_map_2(lpmat(iwrong,:),alpha2, awrongname, OutputDirectoryName); - end - - x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock); - x0 = [x0; lpmat(istable(1),:)']; - if istable(end)~=Nsam - M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)'; - [oo_.dr, info] = resol(oo_.steady_state,0); - % stoch_simul([]); - end -else - if length(iunstable)==0, - disp('All parameter values in the specified ranges are stable!') - x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock); - x0 = [x0; lpmat(istable(1),:)']; - else - disp('All parameter values in the specified ranges are not acceptable!') - x0=[]; - end - -end - - -options_.periods=opt.periods; -if isfield(opt,'nomoments'), - options_.nomoments=opt.nomoments; -end -options_.irf=opt.irf; -options_.noprint=opt.noprint; -if isfield(opt,'simul'), - options_.simul=opt.simul; -end - - - diff --git a/GSA_distrib/4.2/stab_map_1.m b/GSA_distrib/4.2/stab_map_1.m deleted file mode 100644 index 8813fa572..000000000 --- a/GSA_distrib/4.2/stab_map_1.m +++ /dev/null @@ -1,87 +0,0 @@ -function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname) -%function [proba, dproba] = stab_map_1(lpmat, ibehaviour, inonbehaviour, aname, iplot, ipar, dirname) -% -% lpmat = Monte Carlo matrix -% ibehaviour = index of behavioural runs -% inonbehaviour = index of non-behavioural runs -% aname = label of the analysis -% iplot = 1 plot cumulative distributions (default) -% iplot = 0 no plots -% ipar = index array of parameters to plot -% dirname = (OPTIONAL) path of the directory where to save -% (default: current directory) -% -% Plots: dotted lines for BEHAVIOURAL -% solid lines for NON BEHAVIOURAL -% USES smirnov -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -global estim_params_ bayestopt_ M_ options_ - -if nargin<5, - iplot=1; -end -fname_ = M_.fname; -if nargin<7, - dirname='';; -end - -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; - -npar=size(lpmat,2); -ishock= npar>estim_params_.np; - -if nargin<6 | isempty(ipar), - ipar=[1:npar]; -end -nparplot=length(ipar); - -% Smirnov test for Blanchard; -for j=1:npar, - [H,P,KSSTAT] = smirnov(lpmat(ibehaviour,j),lpmat(inonbehaviour,j)); - proba(j)=P; - dproba(j)=KSSTAT; -end -if iplot - lpmat=lpmat(:,ipar); - ftit=bayestopt_.name(ipar+nshock*(1-ishock)); - -for i=1:ceil(nparplot/12), - figure('name',aname), - for j=1+12*(i-1):min(nparplot,12*i), - subplot(3,4,j-12*(i-1)) - if ~isempty(ibehaviour), - h=cumplot(lpmat(ibehaviour,j)); - set(h,'color',[0 0 0], 'linestyle',':') - end - hold on, - if ~isempty(inonbehaviour), - h=cumplot(lpmat(inonbehaviour,j)); - set(h,'color',[0 0 0]) - end - title([ftit{j},'. D-stat ', num2str(dproba(ipar(j)),2)],'interpreter','none') - end - saveas(gcf,[dirname,'/',fname_,'_',aname,'_SA_',int2str(i)]) - eval(['print -depsc2 ' dirname '/' fname_ '_' aname '_SA_' int2str(i)]); - eval(['print -dpdf ' dirname '/' fname_ '_' aname '_SA_' int2str(i)]); - if options_.nograph, close(gcf), end -end -end diff --git a/GSA_distrib/4.2/stab_map_2.m b/GSA_distrib/4.2/stab_map_2.m deleted file mode 100644 index 3d1a8fa9c..000000000 --- a/GSA_distrib/4.2/stab_map_2.m +++ /dev/null @@ -1,97 +0,0 @@ -%function stab_map_2(x,alpha2,istab,fnam) -function stab_map_2(x,alpha2,fnam, dirname) -% function stab_map_2(x,alpha2,fnam, dirname) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -%global bayestopt_ estim_params_ dr_ options_ ys_ fname_ -global bayestopt_ estim_params_ options_ oo_ M_ - -npar=size(x,2); -ishock= npar>estim_params_.np; -if nargin<3, - fnam=''; -end -if nargin<4, - dirname=''; -end - -ys_ = oo_.dr.ys; -dr_ = oo_.dr; -fname_ = M_.fname; -nshock = estim_params_.nvx; -nshock = nshock + estim_params_.nvn; -nshock = nshock + estim_params_.ncx; -nshock = nshock + estim_params_.ncn; - -c0=corrcoef(x); -c00=tril(c0,-1); -fig_nam_=[fname_,'_',fnam,'_corr_']; - -ifig=0; -j2=0; -if ishock==0 - npar=estim_params_.np; -else - npar=estim_params_.np+nshock; -end -for j=1:npar, - i2=find(abs(c00(:,j))>alpha2); - if length(i2)>0, - for jx=1:length(i2), - j2=j2+1; - if mod(j2,12)==1, - ifig=ifig+1; - figure('name',['Correlations in the ',fnam,' sample ', num2str(ifig)]), - end - subplot(3,4,j2-(ifig-1)*12) - % bar(c0(i2,j)), - % set(gca,'xticklabel',bayestopt_.name(i2)), - % set(gca,'xtick',[1:length(i2)]) - %plot(stock_par(ixx(nfilt+1:end,i),j),stock_par(ixx(nfilt+1:end,i),i2(jx)),'.k') - %hold on, - plot(x(:,j),x(:,i2(jx)),'.') - % xlabel(deblank(estim_params_.param_names(j,:)),'interpreter','none'), - % ylabel(deblank(estim_params_.param_names(i2(jx),:)),'interpreter','none'), - if ishock, - xlabel(bayestopt_.name{j},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)},'interpreter','none'), - else - xlabel(bayestopt_.name{j+nshock},'interpreter','none'), - ylabel(bayestopt_.name{i2(jx)+nshock},'interpreter','none'), - end - title(['cc = ',num2str(c0(i2(jx),j))]) - if (mod(j2,12)==0) & j2>0, - saveas(gcf,[dirname,'/',fig_nam_,int2str(ifig)]) - eval(['print -depsc2 ' dirname '/' fig_nam_ int2str(ifig)]); - eval(['print -dpdf ' dirname '/' fig_nam_ int2str(ifig)]); - if options_.nograph, close(gcf), end - end - end - end - if (j==(npar)) & j2>0, - saveas(gcf,[dirname,'/',fig_nam_,int2str(ifig)]) - eval(['print -depsc2 ' dirname '/' fig_nam_ int2str(ifig)]); - eval(['print -dpdf ' dirname '/' fig_nam_ int2str(ifig)]); - if options_.nograph, close(gcf), end - end - -end -if ifig==0, - disp(['No correlation term >', num2str(alpha2),' found for ',fnam]) -end -%close all diff --git a/GSA_distrib/4.2/stand_.m b/GSA_distrib/4.2/stand_.m deleted file mode 100644 index fb0b3fda3..000000000 --- a/GSA_distrib/4.2/stand_.m +++ /dev/null @@ -1,25 +0,0 @@ -function [y, meany, stdy] = stand_(x) -% STAND_ Standardise a matrix by columns -% -% [x,my,sy]=stand(y) -% -% y: Time series (column matrix) -% -% x: standardised equivalent of y -% my: Vector of mean values for each column of y -% sy: Vector of standard deviations for each column of y -% -% Copyright (c) 2006 by JRC, European Commission, United Kingdom -% Author : Marco Ratto - - -if nargin==0, - return; -end - -for j=1:size(x,2); -meany(j)=mean(x(find(~isnan(x(:,j))),j)); -stdy(j)=std(x(find(~isnan(x(:,j))),j)); - y(:,j)=(x(:,j)-meany(j))./stdy(j); -end -% end of m-file \ No newline at end of file diff --git a/GSA_distrib/4.2/teff.m b/GSA_distrib/4.2/teff.m deleted file mode 100644 index 6c33706e5..000000000 --- a/GSA_distrib/4.2/teff.m +++ /dev/null @@ -1,51 +0,0 @@ -function [yt, j0, ir, ic]=teff(T,Nsam,istable) -% -% [yt, j0, ir, ic]=teff(T,Nsam,istable) -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -ndim = (length(size(T))); -if ndim==3, -if nargin==1, - Nsam=size(T,3); - istable = [1:Nsam]'; -end -tmax=max(T,[],3); -tmin=min(T,[],3); -[ir, ic]=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=zeros(Nsam, j0); - -for j=1:j0, - y0=squeeze(T(ir(j),ic(j),:)); - %y1=ones(size(lpmat,1),1)*NaN; - y1=ones(Nsam,1)*NaN; - y1(istable,1)=y0; - yt(:,j)=y1; -end - -else -tmax=max(T,[],2); -tmin=min(T,[],2); -ir=(find( (tmax-tmin)>1.e-8)); -j0 = length(ir); -yt=NaN(Nsam, j0); -yt(istable,:)=T(ir,:)'; - - -end -%clear y0 y1; diff --git a/GSA_distrib/4.2/th_moments.m b/GSA_distrib/4.2/th_moments.m deleted file mode 100644 index 41bb18d78..000000000 --- a/GSA_distrib/4.2/th_moments.m +++ /dev/null @@ -1,66 +0,0 @@ -% Copyright (C) 2001 Michel Juillard -% -function [vdec, corr, autocorr, z, zz] = th_moments(dr,var_list) - global M_ oo_ options_ - - nvar = size(var_list,1); - if nvar == 0 - nvar = length(dr.order_var); - ivar = [1:nvar]'; - else - ivar=zeros(nvar,1); - for i=1:nvar - i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact'); - if isempty(i_tmp) - error (['One of the variable specified does not exist']) ; - else - ivar(i) = i_tmp; - end - end - end - - [gamma_y,ivar] = th_autocovariances(dr,ivar,M_, options_); - m = dr.ys(ivar); - - - i1 = find(abs(diag(gamma_y{1})) > 1e-12); - s2 = diag(gamma_y{1}); - sd = sqrt(s2); - - - z = [ m sd s2 ]; - mean = m; - var = gamma_y{1}; - - -%'THEORETICAL MOMENTS'; -%'MEAN','STD. DEV.','VARIANCE'); -z; - -%'VARIANCE DECOMPOSITION (in percent)'; -if M_.exo_nbr>1, -vdec = 100*gamma_y{options_.ar+2}(i1,:); -else -vdec = 100*ones(size(gamma_y{1}(i1,1))); -end -%'MATRIX OF CORRELATIONS'; -if options_.opt_gsa.useautocorr, - corr = gamma_y{1}(i1,i1)./(sd(i1)*sd(i1)'); - corr = corr-diag(diag(corr))+diag(diag(gamma_y{1}(i1,i1))); -else - corr = gamma_y{1}(i1,i1); -end - if options_.ar > 0 -%'COEFFICIENTS OF AUTOCORRELATION'; - for i=1:options_.ar - if options_.opt_gsa.useautocorr, - autocorr{i} = gamma_y{i+1}(i1,i1); - else - autocorr{i} = gamma_y{i+1}(i1,i1).*(sd(i1)*sd(i1)'); - end - zz(:,i) = diag(gamma_y{i+1}(i1,i1)); - end - end - - - \ No newline at end of file diff --git a/GSA_distrib/4.2/thet2tau.m b/GSA_distrib/4.2/thet2tau.m deleted file mode 100644 index d0a8d0ed4..000000000 --- a/GSA_distrib/4.2/thet2tau.m +++ /dev/null @@ -1,45 +0,0 @@ -function tau = thet2tau(params, indx, indexo, flagmoments,mf,nlags,useautocorr) -global M_ oo_ options_ - -if nargin==1, - indx = [1:M_.param_nbr]; - indexo = []; -end - -if nargin<4, - flagmoments=0; -end -if nargin<7 | isempty(useautocorr), - useautocorr=0; -end - -M_.params(indx) = params(length(indexo)+1:end); -if ~isempty(indexo) - M_.Sigma_e(indexo,indexo) = diag(params(1:length(indexo)).^2); -end -% [A(oo_.dr.order_var,oo_.dr.order_var),B(oo_.dr.order_var,:)]=dynare_resolve; -[A,B]=dynare_resolve; -if flagmoments==0, -tau = [oo_.dr.ys(oo_.dr.order_var); A(:); dyn_vech(B*M_.Sigma_e*B')]; -else -GAM = lyapunov_symm(A,B*M_.Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold); -k = find(abs(GAM) < 1e-12); -GAM(k) = 0; -if useautocorr, - sy = sqrt(diag(GAM)); - sy = sy*sy'; - sy0 = sy-diag(diag(sy))+eye(length(sy)); - dum = GAM./sy0; - tau = dyn_vech(dum(mf,mf)); -else - tau = dyn_vech(GAM(mf,mf)); -end -for ii = 1:nlags - dum = A^(ii)*GAM; - if useautocorr, - dum = dum./sy; - end - tau = [tau;vec(dum(mf,mf))]; -end -tau = [ oo_.dr.ys(oo_.dr.order_var(mf)); tau]; -end \ No newline at end of file diff --git a/GSA_distrib/4.2/trank.m b/GSA_distrib/4.2/trank.m deleted file mode 100644 index a0c5bda99..000000000 --- a/GSA_distrib/4.2/trank.m +++ /dev/null @@ -1,25 +0,0 @@ -function yr = trank(y); -% yr = trank(y); -% yr is the rank transformation of y -% -% Part of the Sensitivity Analysis Toolbox for DYNARE -% -% Written by Marco Ratto, 2006 -% Joint Research Centre, The European Commission, -% (http://eemc.jrc.ec.europa.eu/), -% marco.ratto@jrc.it -% -% Disclaimer: This software is not subject to copyright protection and is in the public domain. -% It is an experimental system. The Joint Research Centre of European Commission -% assumes no responsibility whatsoever for its use by other parties -% and makes no guarantees, expressed or implied, about its quality, reliability, or any other -% characteristic. We would appreciate acknowledgement if the software is used. -% Reference: -% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006. -% - -[nr, nc] = size(y); -for j=1:nc, - [dum, is]=sort(y(:,j)); - yr(is,j)=[1:nr]'./nr; -end