%% Run through the high pass and look at the spectrum afterwards
pop_editoptions('option_single', false, 'option_savetwofiles', false);

%% Specify collection files, legends and colors for the comparison
% statFiles = {
%     'N:\\ARLAnalysis\\VEP\\VEP_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\VEP\\VEPMastoid_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\VEP\\VEPAverage_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\VEP\\VEPRobust_1Hz_Post_Median_Unfiltered_Report\\dataStatistics.mat'};
% 
% legendString = {'B64_org ', 'B64_mas ', 'B64_ave ', 'B64_rob' };
% collectionColors =   [0, 0, 0.9; 0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0];
% collectionMarkers = {'o', 'o', 'x', 's'}; 

% statFiles = { ...
%     'N:\\ARLAnalysis\\Shooter\\Shooter_Average_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\Shooter\\ShooterRobust_1Hz_Unfiltered_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\Shooter\\Shooter_Mastoid_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\Shooter\\Shooter_Average_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\Shooter\\ShooterRobust_1Hz_Unfiltered_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\NCTU\\NCTU_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\NCTU\\NCTU_Average_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\NCTU\\NCTURobust_1Hz_New\\dataStatistics.mat'; ...;
%     'N:\\ARLAnalysis\\VEP\\VEPMastoid_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\VEP\\VEPAverage_1Hz_Report\\dataStatistics.mat'; ...
%     'N:\\ARLAnalysis\\VEP\\VEPRobust_1Hz_Post_Median_Unfiltered_Report\\dataStatistics.mat'};
% 
% legendString = {'N40_mas', 'N40_ave', 'N40_rob', ...
%                 'N32_mas', 'N32_ave', 'N32_rob', ...
%                 'B64_mas ','B64_ave', 'B64_rob' };
% collectionColors =   [0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0; ...
%                       0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0; ...
%                       0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0
%                      ];
% collectionMarkers = {'^', '^', '^', 's', 's', 's', 'o', 'o', 'o'}; 

statFiles = { ...
    'N:\\BCI2000\\BCI2000_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\BCI2000\\BCI2000_Average_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\BCI2000\\BCI2000Robust_1Hz_Unfiltered_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\Shooter\\Shooter_Mastoid_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\Shooter\\Shooter_Average_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\Shooter\\ShooterRobust_1Hz_Unfiltered_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\NCTU\\NCTU_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\NCTU\\NCTU_Average_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\NCTU\\NCTURobust_1Hz_New\\dataStatistics.mat'; ...;
    'N:\\ARLAnalysis\\VEP\\VEPMastoid_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\VEP\\VEPAverage_1Hz_Report\\dataStatistics.mat'; ...
    'N:\\ARLAnalysis\\VEP\\VEPRobust_1Hz_Post_Median_Unfiltered_Report\\dataStatistics.mat'};

legendString = { 'C64_mas', 'C64_ave', 'C64_rob', ...
                 'N40_mas', 'N40_ave', 'N40_rob', ...
                'N32_mas', 'N32_ave', 'N32_rob', ...
                'B64_mas ','B64_ave', 'B64_rob' };
collectionColors =   [0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0; ...
                      0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0; ...
                      0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0; ...
                      0, 1, 0; 0.75, 0.75, 0.75; 0, 0, 0
                     ];
collectionMarkers = {'v', 'v', 'v', '^', '^', '^', 's', 's', 's', 'o', 'o', 'o'};
%% Consolidate the collection statistics from files 
collections = getCollections(statFiles);

%% Compare statistics for different collections using scatterplots
showCollectionStatistics(collections, legendString, collectionColors, ...
            collectionMarkers);

%% Show collection boxplots
showCollectionBoxplots(collections, legendString, collectionColors)

%% 
%%% Rank significance of the channel deviations
[dataGroups1, dataPoints1] = getDataGroups(collections, 'medDev');
significance.medDev = getRankSignificance(dataGroups1, dataPoints1, legendString);
[dataGroups2, dataPoints2] = getDataGroups(collections, 'rSDDev');
significance.rSDDev = getRankSignificance(dataGroups2, ...
    dataPoints2, legendString);
significance.devRatio = getRankSignificance(dataGroups2, ...
    dataPoints2./dataPoints1, legendString);
[dataGroups1, dataPoints1] = getDataGroups(collections, 'medWinDev');
significance.medWinDev = getRankSignificance(dataGroups1, ...
    dataPoints1, legendString);
[dataGroups2, dataPoints2] = getDataGroups(collections, 'rSDWinDev');
significance.rSDWinDev = getRankSignificance(dataGroups2, ...
    dataPoints2, legendString);
significance.devWinRatio = getRankSignificance(dataGroups2, ...
    dataPoints2./dataPoints1, legendString);

%% Rank significance of the channel HFNoise
[dataGroups1, dataPoints1] = getDataGroups(collections, 'medHF');
significance.medHF = getRankSignificance(dataGroups1, ...
    dataPoints1, legendString);
[dataGroups2, dataPoints2] = getDataGroups(collections, 'rSDHF');
significance.rSDHF  = getRankSignificance(dataGroups2, ...
    dataPoints2, legendString);
significance.HFRatio = getRankSignificance(dataGroups2, ...
    dataPoints2./dataPoints1, legendString);
[dataGroups1, dataPoints1] = getDataGroups(collections, 'medWinHF');
significance.medWinHF  = getRankSignificance(dataGroups1, ...
    dataPoints1, legendString);
[dataGroups2, dataPoints2] = getDataGroups(collections, 'rSDWinHF');
significance.rSDWinHF  = getRankSignificance(dataGroups2, ...
    dataPoints2, legendString);
significance.HFWinRatio = getRankSignificance(dataGroups2, ...
    dataPoints2./dataPoints1, legendString);

%% Rank significance of correlation
[dataGroups, dataPoints] = getDataGroups(collections, 'medCor');
significance.medCor = getRankSignificance(dataGroups, dataPoints, legendString);
[dataGroups, dataPoints] = getDataGroups(collections, 'aveCor');
significance.aveCor = getRankSignificance(dataGroups, dataPoints, legendString);