# -*- coding: utf-8 -*-
"""
Created on Wed Nov 10 15:17:50 2021

@author: Sim
"""
import scipy.stats as st
import numpy as np

before = np.array([ 5, 1, 0, 4, 4, 5, 3, 3, 2, 4])
after = np.array([ 4, 0, 0, 2, 1, 3, 3, 1, 2, 1])
diff = before - after

tval, pval = st.ttest_rel(before, after, alternative='greater')
print(tval, pval)

sem = np.sqrt(np.var(diff, ddof=1)/len(diff))
tval1 = np.mean(diff)/sem
print(tval1)
pval1 = 1-st.t.cdf(tval1, len(diff)-1) 
print(pval1)

# One sample t with diff

tval2, pval2 = st.ttest_1samp(diff, popmean=0, alternative='greater')
print('차에 대한 일표본 t 검정: ', tval, pval)
# 평균차의 신뢰구간

lbd = np.mean(diff) - st.t.ppf(.975, len(diff)-1) * sem
ubd = np.mean(diff) + st.t.ppf(.975, len(diff)-1) * sem
print(lbd, ubd)

cidiff = st.t.interval(0.95, len(diff)-1, loc=np.mean(diff), scale=sem)
print(cidiff)
