% Transformations for all characteristics measured

clear

% Transformation data root
tf_root='/Users/Colin/Documents/MATLAB/DFlow/influences_chap2/transform/';

% QAR root
qar_root = ['/Users/Colin/Documents/MATLAB/DFlow/influences_chap2/'...
    'multi_regress/'];

% Load transformation data
% Column 1 - Total Area km^2
% Column 2 - FP Area km^2
% Column 3 - Inset Area km^2
% Column 4 - Island Area km^2
% Column 5 - Channel Area km^2
% Column 6 - Channel Width km
% Column 7 - FP Width km
% Column 8 - Bank Roughness
% Column 9 - FP Roughness
% Column 10 - Bank - Channel Elevation
% Column 11 - FP - Channel Elevation
% Column 12 - WSE - bank
% Column 13 - WSE - FP
% Column 14 - Slope
% Column 15 - Fraction of area inundated at baseflow
load(strcat(tf_root,'char1000m_s180.mat'));
load(strcat(tf_root,'char1000m_s180log.mat'));
load(strcat(tf_root,'char1000m_s180exp.mat'));
load(strcat(tf_root,'char1000m_s300.mat'));
load(strcat(tf_root,'char1000m_s300log.mat'));
load(strcat(tf_root,'char1000m_s300exp.mat'));

% Load qar data
load(strcat(qar_root,'qar_rate1000s180.mat'));
load(strcat(qar_root,'qar_rate1000s300.mat'));

[~,num_var] = size(char1000m_s180);
r2ord_1x1 = zeros(num_var,2);
r2adj_1x1 = zeros(num_var,2);
r2ord_exp = zeros(num_var,2);
r2adj_exp = zeros(num_var,2);
r2ord_log = zeros(num_var,2);
r2adj_log = zeros(num_var,2);
r2ord_logy = zeros(num_var,2);
r2adj_logy = zeros(num_var,2);
for i = 1:num_var
    mdl = fitlm(char1000m_s180(:,i),qar_rate1000s180(:,1));
    r2ord_1x1(i,1) = mdl.Rsquared.Ordinary;
    r2adj_1x1(i,1) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s300(:,i),qar_rate1000s300(:,1));
    r2ord_1x1(i,2) = mdl.Rsquared.Ordinary;
    r2adj_1x1(i,2) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s180log(:,i),qar_rate1000s180(:,1));
    r2ord_log(i,1) = mdl.Rsquared.Ordinary;
    r2adj_log(i,1) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s300log(:,i),qar_rate1000s300(:,1));
    r2ord_log(i,2) = mdl.Rsquared.Ordinary;
    r2adj_log(i,2) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s180exp(:,i),qar_rate1000s180(:,1));
    r2ord_exp(i,1) = mdl.Rsquared.Ordinary;
    r2adj_exp(i,1) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s300exp(:,i),qar_rate1000s300(:,1));
    r2ord_exp(i,2) = mdl.Rsquared.Ordinary;
    r2adj_exp(i,2) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s180(:,i),log(qar_rate1000s180(:,1)));
    r2ord_logy(i,1) = mdl.Rsquared.Ordinary;
    r2adj_logy(i,1) = mdl.Rsquared.Adjusted;
    mdl = fitlm(char1000m_s300(:,i),log(qar_rate1000s300(:,1)));
    r2ord_logy(i,2) = mdl.Rsquared.Ordinary;
    r2adj_logy(i,2) = mdl.Rsquared.Adjusted;
end

matrix_lny_x_300matrix = char1000m_s300(:,[1 9 10 12 14 15]);
matrix_lny_x_180matrix = char1000m_s180(:,[5 8 11 13 14 15]);
ln_y180_matrix = log(qar_rate1000s180);
ln_y300_matrix = log(qar_rate1000s300);

% mdl_mult300 = fitlm(best_300matrix,ln_y300_matrix)

% Linear analysis
% figure(1)
% set(gcf,'color','white');
% plotmatrix(char1000m_s300);

% figure(2)
% set(gcf,'color','white');
% plotmatrix(char1000m_s300);
% 
% figure(3)
% set(gcf,'color','white');
% scatter(char1000m_s180(:,1),char1000m_s180(:,15),'bo');
% hold on
% scatter(char1000m_s300(:,1),char1000m_s300(:,15),'ro');
% 
% mdl180area_v_inun = fitlm(char1000m_s180(:,1),char1000m_s180(:,15))
% mdl300area_v_inun = fitlm(char1000m_s300(:,1),char1000m_s300(:,15))
