results = readtable('results.xlsx');

%% Setup anova for single cycle pulses
lytic = {'none','rt-PA'};
pressure = [0,25,30,35];
perfusate = [];
group = [];

for l = 1:length(lytic)
    for p = 1:length(pressure)
        groupname = sprintf('%s%iMPa',string(lytic(l)),pressure(p));
        tmpdata = results(results.PNP_MPa_==pressure(p) & strcmp(results.Arm,string(lytic(l))),:);
        tmpdata = tmpdata.Hemolysis; % Modify this to analyze other aspects of perfusate
        %Hemolysis
        %D_Dimer
        %MassLoss___
        perfusate = vertcat(perfusate, tmpdata);
        group = vertcat(group, repmat({groupname}, length(tmpdata),1));
    end
end

%% Setup anova for multi cycle comparison
lytic = {'none','rt-PA'};
arm = {'none','rt-PA','5cycle','20cycle'};
perfusate = [];
group = [];

for l = 1:length(lytic)
    for a = 1:length(arm)
        groupname = sprintf('%s%s',string(lytic(l)),string(arm(a)));
        tmpdata = results(strcmp(results.Lytic,string(lytic(l))) & strcmp(results.Arm,string(arm(a))) & results.PNP_MPa_==35,:);
        tmpdata = tmpdata.Hemolysis; % Modify this to analyze other aspects of perfusate
        %Hemolysis
        %D_Dimer
        %MassLoss___
        perfusate = vertcat(perfusate, tmpdata);
        group = vertcat(group, repmat({groupname}, length(tmpdata),1));
    end
end
%% Test for normality 
uniquegroups = unique(group);
for i=1:length(uniquegroups)
    index = find(strcmp(string(uniquegroups(i)),group));
    H = swtest(nanmean(perfusate(index))-perfusate(index));
    
    if (H == 0)
        fprintf('Group %s satisfies normality \n',string(uniquegroups(i)));
    else
        fprintf('Group %s does NOT satisfy normality \n',string(uniquegroups(i)));
    end
end

%% Test for equal variances
vartestn(perfusate,group,'TestType','LeveneAbsolute');


%% Cacluate ANOVA
close all
[p,t,stats] = anova1(perfusate, group, 'nodisplay');

[c,m,h,nms] = multcompare(stats, 'CType', 'hsd');

