% BIOE xxxx Template for HW xxx
% Created On: 2016.04.25


% This is code to perform multivariable conparisions of the stock data 
% in the attached data set


%%%%%%
% Section 1. Load the data
% a good loader shouldn't care how many things we are comparing or
% what the exact names are. This load code will bring in all the *.csv
% files in the directory

[num, txt, raw] = xlsread('tomita_database.xlsx', 'A3:AB92');

clinicalPhenotype = raw(:, 16);
totalDiseaseDuration = cell2mat(raw(:, 12));
mainOutcome = cell2mat(raw(:, 13));


% get the unique clinical phenotypes
% this is an unblanced(anova)
p = anova1(totalDiseaseDuration, clinicalPhenotype);

% create sub arrays of total disease duratio
phenotypes = unique(clinicalPhenotype);
Np = length(phenotypes);

diseaseDuration = cell(1, Np);

for ii = 1: Np
   diseaseDuration{ii} = totalDiseaseDuration(strcmp(clinicalPhenotype, phenotypes{ii}));
    
end

figure;

for ii = 1:Np
    subplot(1, Np, ii);
    qqplot(diseaseDuration{ii});
    title(phenotypes{ii});
end

pvar = vartestn(totalDiseaseDuration, clinicalPhenotype);

[pvarK, tabK, statsK] = kruskalwallis(totalDiseaseDuration, clinicalPhenotype);

multcompare(statsK);

multcompare(statsK, 'ctype', 'lsd');
