import numpy as np
import scipy as sp
import pandas as pd
import sys
print(np.version.version)
print(sp.version.version)
print(pd.__version__)
print(sys.version)
import os
cwd = os.getcwd()
cwd
# t-Test using lists
import statistics as st
N = 20
control = [12,13,14,15,16,12,13,14,15,16,13,14,15,16,17,13,14,15,16,17]
treatment = [13,14,15,16,17,13,14,15,16,17,14,15,16,17,18,14,15,16,17,18]
# print(control)
# print(treatment)
mC = st.mean(control)
mT = st.mean(treatment)
sC = st.stdev(control)
sT = st.stdev(treatment)
print('Mean Control:',mC,'StDev Control:', round(sC,4))
print('Mean Treatment:',mT,'StDev Treatment:',round(sT,4))
#----------------------------------------------------------------
import scipy.stats as stats
print('Normality Control:', round(stats.shapiro(control)[1],4))
print('Normality Treatment:',round(stats.shapiro(treatment)[1],4))
print('Between Group Variance:',stats.levene(control,treatment)[1])
t, p = stats.ttest_ind(control, treatment)
print('t = ',round(t,4),'p = ',round(p,4))
if p<=0.05:
print('Sig.')
# small <= 0.2 Medium <=0.8 LARGE
es = abs(mC-mT)/sC
print('Effect size = ',round(es,4))
# --- Numpy arrays -----------
# --- Vectorization
import numpy as np
ar1 = np.array([1,2,3,4])
ar2 = np.array([5,6,7,8])
print(ar1 + ar2)
# --- Numpy arrays -----------
alist = [[i+k for k in range(3)] for i in range(4)]
print(alist)
ar1 = np.array(alist)
print(ar1, ar1[2][1])
ar2 = np.arange(16).reshape(2,4,2)
print(ar2)
print(ar2[0,1])
ar3 = np.linspace(0,1,11,True)
print(ar3)
# Scalar programming (βαθμωτός προγραμματισμός)
# Ο τελεστής '+' επιδρά σε βαθμωτά μεγέθη
x = 1
y = 2
asum = x+y
# Vector programming (διανυσματικός προγραμματισμός)
# Ο τελεστής '+' επιδρά σε πίνακα & βαθμωτό μεγέθη
ar4 = ar3+1
print(ar4)
# Ο τελεστής '+' επιδρά σε πίνακες (διανυσματικά μεγέθη)
ar5 = ar3+ar4
print(ar5)
# -- Drawing with matplotlib -----
import matplotlib.pyplot as plt
%matplotlib inline
x = np.linspace(0,2*np.pi,100)
y = np.sin(x)
p = plt.plot(x,y)
#plt.show()
# --- t-Test using numpy arrays ---------------
import numpy as np
import statistics as st
N = 20
control = np.array([12,13,14,15,16,12,13,14,15,16,13,14,15,16,17,13,14,15,16,17])
treatment = np.array([13,14,15,16,17,13,14,15,16,17,14,15,16,17,18,14,15,16,17,18])
# print(control)
# print(treatment)
mC = st.mean(control)
mT = st.mean(treatment)
sC = st.stdev(control)
sT = st.stdev(treatment)
print('Mean Control:',mC,'StDev Control:', round(sC,4))
print('Mean Treatment:',mT,'StDev Treatment:',round(sT,4))
#----------------------------------------------------------------
import scipy.stats as stats
print('Normality Control:', round(stats.shapiro(control)[1],4))
print('Normality Treatment:',round(stats.shapiro(treatment)[1],4))
print('Between Group Variance:',stats.levene(control,treatment)[1])
t, p = stats.ttest_ind(control, treatment)
print('t = ',round(t,4),'p = ',round(p,4))
if p<=0.05:
print('Sig.')
es = abs(mC-mT)/sC
print('Effect size = ',round(es,4))
# --- Graph drawing with matplotlib ----------------------
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
% matplotlib inline
control = np.array([12,13,14,15,16,12,13,14,15,16,13,14,15,16,17,13,14,15,16,17])
treatment = np.array([13,14,15,16,17,13,14,15,16,17,14,15,16,17,18,14,15,16,17,18])
# --- Boxplot -------------------
bplot = [control,treatment]
bpl = plt.boxplot(bplot)
plt.ylim(10,20)
plt.show()
# --- histogram ------------------
#n, bins, patches = plt.hist(control, 6, color='cyan', align='left', alpha=0.5)
arfreq = stats.itemfreq(control)
barloc = np.arange(control.min(),len(arfreq)+control.min())
freqsC = np.array([arfreq[x][1] for x in range(len(arfreq))])
width = 0.5
histpl= plt.bar(barloc, freqsC, width, align='center', color='c')
plt.show()
# --- Διάβασμα δεδομένων από αρχείο
# --- Κάθε απλό δεδομένο είναι σε ξεχωριστή σειρά
with open('control.txt', 'r') as f:
control = []
for grade in f:
control.append(float(grade))
print(control)
with open('treatment.txt', 'r') as f:
treatment = []
for grade in f:
treatment.append(float(grade))
print(treatment)