# -*- coding: utf-8 -*-
"""
Created on Wed Jan  5 17:27:08 2022

@author: Sim
"""
import pandas as pd 
from statsmodels.formula.api import ols
import statsmodels.api as sm
import matplotlib.pyplot as plt
import statsmodels.stats.multicomp as mc
import scipy.stats as st

drugA = [13,  10,  15,  9, 12, 11,  7]
drugB = [18, 10, 16, 12, 19, 14, 13, 12]
drugC = [8,  9,  4,  6, 13,  8, 12, 10, 2]

#dfw = pd.DataFrame({'drugA': drugA, 'drugB':drugB, 'drugC':drugC})

trt = ['drugA']*len(drugA) + ['drugB']*len(drugB) + ['drugC']*len(drugC)
dfl = pd.DataFrame({'trt': trt, 'response': drugA+drugB+drugC})
#----------------------------------------------------------------
res1 = ols('response~trt', data=dfl).fit()
aov_table1 = sm.stats.anova_lm(res1, type=3)
print(aov_table1)
#----------------------------------------------------------------
plt.boxplot([drugA, drugB, drugC])
plt.show()
#-----------------------------------------------------------
comp = mc.MultiComparison(dfl['response'],dfl['trt'])
hsd = comp.tukeyhsd(0.05)
print(hsd.summary())
#-------------------------------------------------
fig, ax = plt.subplots(1,1)
hsd.plot_simultaneous(ax=ax)
#-------------------------------------------------
bonf, a, b = comp.allpairtest(st.ttest_ind, method='bonf')
print(bonf)
