# -*- coding: utf-8 -*-
"""
Created on Tue Dec  7 16:54:28 2021

@author: Sim
"""
import pandas as pd
from statsmodels.formula.api import ols
import statsmodels.api as sm

df=pd.DataFrame({'구더기': [99, 113, 99, 89, 84, 82],
                 'Vancomycin': [105, 105, 128, 123, 62, 103],
                 'Teicolanin': [91, 95, 120, 55, 101, 100],
                 'Linezolid': [91, 80, 79, 130, 103, 87]})

col = ['response'+ str(i) for i in range(6)]
dfT = df.T 
dfT['trt'] = dfT.index
dfT.columns = col + ['trt']
dfl = pd.wide_to_long(dfT, stubnames='response', i='trt', j='obs')
dfl = dfl.reset_index()
dfl = dfl.drop(columns=['obs'])
print(dfl)

lm1 = ols('response~C(trt)', data=dfl)
res1=lm1.fit()
aov_table1 = sm.stats.anova_lm(res1, type=3)
print(aov_table1)
#---------------------------------------------------------
import matplotlib.pyplot
matplotlib.rcParams.update({'font.family' : 'Gulim'})                           
dfl.boxplot('response', by='trt', figsize=(8, 5))
#-------------------------------------------------------
print(res1.fvalue)
print(res1.f_pvalue)
#--------------------------------------------------------
coef = res1.params
print(coef)
#--------------------------------------------------------
mm = dfl.groupby('trt').mean()
print(mm)
print(mm- mm.loc['Linezolid'])


