%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This script is used to run the statistical analysis for the baseline
% 1980-2011 for the different sets of natural hazards as reported in:
%
% Daniel Nohrstedt, Maurizio Mazzoleni, Charles F. Parker, and Giuliano Di
% Baldassarre. Policy change after natural hazard
% events, Nature Communication
%
% This script was prepared by Maurizio Mazzoleni
% Uppsala University, 2020
% mail to: maurizio.mazzoleni@geo.uu.se
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
significance=0.05;
%Preallocation
pval_tot=zeros(4,4);
sen_tot=zeros(4,4);
for ii=1:4
%%Define input scatter plot
x = (Analysis_mean(:,ii));
y = (Analysis_mean(:,5));
cls = Income_2015(:,2);
%%Split the data in different income groups
x_L = x(cls==1);
y_L = y(cls==1);
x_LM = x(cls==2);
y_LM = y(cls==2);
x_UM = x(cls==3);
y_UM = y(cls==3);
x_H = x(cls==4);
y_H = y(cls==4);
x_NaN = x(cls==5);
y_NaN = y(cls==5);
vec_L=[x_L,y_L];
vec_LM=[x_LM,y_LM];
vec_UM=[x_UM,y_UM];
vec_H=[x_H,y_H];
%%Correlation analysis
[taub_L,tau_L,h_L,sig_L,sen_L] = ktaub(vec_L,significance,0);
[taub_LM,tau_LM,h_LM,sig_LM,sen_LM] = ktaub(vec_LM,significance,0);
[taub_UM,tau_UM,h_UM,sig_UM,sen_UM] = ktaub(vec_UM,significance,0);
[taub_H,tau_H,h_H,sig_H,sen_H] = ktaub(vec_H,significance,0);
%%Save results
pval_tot(1,ii)=sig_L;
pval_tot(2,ii)=sig_LM;
pval_tot(3,ii)=sig_UM;
pval_tot(4,ii)=sig_H;
sen_tot(1,ii)=sen_L;
sen_tot(2,ii)=sen_LM;
sen_tot(3,ii)=sen_UM;
sen_tot(4,ii)=sen_H;
end