-
Notifications
You must be signed in to change notification settings - Fork 0
/
countMeasures.py
1712 lines (1306 loc) · 67.8 KB
/
countMeasures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import math
import tkinter as tk
import numpy as np
from math import sqrt
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg)
from matplotlib.figure import Figure
from scipy import special
from scipy import stats
import matplotlib.pyplot as plt
import pandas as pd
from statsmodels.stats.descriptivestats import sign_test
import seaborn as sns
import statistics as statistics_native
import app
import start as st
import oneInput as oi
import twoInputs as ti
def takeResultFromFile():
result = []
with open(app.tempFile, 'r') as file1:
lines = file1.readlines()
for line in lines:
result.append(float(line))
return result
def takeResultFromFile2Lines():
result, result1 = [], []
with open(app.tempFile, 'r') as file1:
lines = file1.readlines()
for line in lines:
x = line.split(' ')
result.append(float(x[0]))
result1.append(float(x[1]))
return result, result1
class ShapiroWilkTest(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Shapiro_Wilk Test:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.answer2 = tk.Label(self)
self.answer2.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.stat, self.pvalue = stats.shapiro(self.df)
print("Shapiro_Wilk Test:", str(self.stat), str(self.pvalue))
self.answer.config(text="Statistic: " + str(self.stat), font="none 14 bold")
self.answer2.config(text="Pvalue: " + str(self.pvalue), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class StandardDeviation(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Standard deviation:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.result = stats.tstd(self.df)
self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
print("Standard deviation:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class PopulationStandardDeviation(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Population standard deviation:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.result = stats.tstd(self.df, ddof=0)
self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
print("Population standard deviation:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class MeanAbsoluteDeviation(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Mean Absolute Deviation:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.mean = stats.tmean(self.df)
self.sum = 0
for x in self.df:
self.sum += abs(x - self.mean)
self.result = self.sum / len(self.df)
self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
print("Mean Absolute Deviation:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class PoissonDistribution(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Poisson Distribution:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.t1 = tk.Label(self)
self.t1.pack(pady=10)
self.t2 = tk.Label(self)
self.t2.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=20)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df1, self.df2 = [], []
self.df1, self.df2 = takeResultFromFile2Lines()
if len(self.df1) == 1 & len(self.df2) == 1:
self.result = (np.power(self.df1[0], self.df2[0]) * np.exp(-self.df1[0])) / special.factorial(self.df2[0])
self.t1.config(text="Expected number of events : " + str(self.df1[0]), font="none 14 bold")
self.t2.config(text="Number of occurrences: " + str(self.df2[0]), font="none 14 bold")
print("Poisson Distribution:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be exactly one in each array", font="none 28 bold")
app.cleanFile(app.tempFile)
class Quantile(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Quantiles:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.result = np.quantile(self.df, [.25, .5, .75])
median = np.quantile(self.df, [.5])
tertile = np.quantile(self.df, [0.33, 0.66])
self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
self.answer.config(text="Quartile: " + str(self.result) + "Tertile: " + str(tertile) + "Median: " + str(median), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class LinearRegression(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Linear regression:", width=40, font="none 14 bold")
self.answer.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=10)
def countMeasures(self):
x, y = takeResultFromFile2Lines()
x = np.array(x)
y = np.array(y)
if len(x) >= 3:
res = stats.linregress(x,y)
fig = Figure(figsize=(5, 3))
ax = fig.add_subplot()
ax.plot(x, y, 'o', label='original data')
ax.plot(x, res.intercept + res.slope*x, 'r', label='fitted line')
ax.legend()
self.canvas = FigureCanvasTkAgg(fig, self)
self.canvas.draw()
self.canvas.get_tk_widget().pack()
self.answer.config(text="Linear regression formula: Y = " + "{:.2f}".format(res.slope) + " * X + " + "{:.2f}".format(res.intercept), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class PearsonCorrelation(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Pearson correlation:", width=40, font="none 14 bold")
self.answer.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=10)
def countMeasures(self):
x, y = takeResultFromFile2Lines()
x = np.array(x)
y = np.array(y)
if len(x) >= 3:
r, p = stats.pearsonr(x,y)
fig = Figure(figsize=(5, 3))
ax = fig.add_subplot()
ax.plot(x, y, 'o', label='original data')
ax.legend()
self.canvas = FigureCanvasTkAgg(fig, self)
self.canvas.draw()
self.canvas.get_tk_widget().pack()
self.answer.config(text="pearson correlation coefficient P(X,Y)= " + "{:.2f}".format(r), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class InterquartileRange(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Interquartile Range:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.answer2 = tk.Label(self)
self.answer2.pack(pady=10)
self.answer3 = tk.Label(self)
self.answer3.pack(pady=10)
self.count_measures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def count_measures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.q1 = np.percentile(self.df, 25)
self.q3 = np.percentile(self.df, 75)
self.result = self.q3-self.q1
print("Interquartile Range:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
self.answer2.config(text="Q1: " + str(self.q1), font="none 14 bold")
self.answer3.config(text="Q3: " + str(self.q3), font="none 14 bold")
else:
self.answer.config(text="Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class BoxPlot(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Box plot", width=40, font="none 14 bold")
self.answer.pack(pady=1)
self.count_measures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=10)
def count_measures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) >= 3:
self.answer2 = tk.Label(self)
self.answer2.pack(pady=1)
self.answer3 = tk.Label(self)
self.answer3.pack(pady=1)
fig = Figure(figsize=(5, 3))
ax = fig.add_subplot()
labels = ['Data']
ax.boxplot(self.df, labels=labels)
self.canvas = FigureCanvasTkAgg(fig, self)
self.canvas.draw()
self.canvas.get_tk_widget().pack()
self.q1 = np.percentile(self.df, 25)
self.q2 = np.percentile(self.df, 50)
self.q3 = np.percentile(self.df, 75)
self.answer2.config(text="Q1: " + str(self.q1) + " Q2 (Median): " + str(self.q2) + " Q3: " + str(self.q3), font="none 10 bold")
self.answer3.config(text="IQR (Q3-Q1): " + str(self.q3-self.q1), font="none 10 bold")
else:
self.answer.config(text="Amount of values need to be more than 3", font="none 28 bold")
app.cleanFile(app.tempFile)
class MinSampleCountForPopAVGStud_t(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Minimal sample count for population average\n(Student's t-distribution):", width=40, font="none 14 bold")
self.answer.pack(pady=30)
self.label2 = tk.Label(self, text='Margin of error (e.g. 0.45):')
self.label2.config(font=('helvetica', 10))
self.label2.pack()
self.entry_Mor = tk.Entry(self)
self.entry_Mor.pack()
self.label3 = tk.Label(self, text='Confidence level (e.g. 0.95 ; 95%):')
self.label3.config(font=('helvetica', 10))
self.label3.pack()
self.entry_cl = tk.Entry(self)
self.entry_cl.pack()
self.label4 = tk.Label(self, text='Standard deviation:')
self.label4.config(font=('helvetica', 10))
self.label4.pack()
self.entry_stdDev = tk.Entry(self)
self.entry_stdDev.pack()
self.label4 = tk.Label(self, text='Initial sample:')
self.label4.config(font=('helvetica', 10))
self.label4.pack()
self.entry_initSample = tk.Entry(self)
self.entry_initSample.pack()
self.button1 = tk.Button(self, text='Get minimal sample size', command=self.count_measures, bg='brown', fg='white')
self.button1.pack(pady=20)
self.answer2 = tk.Label(self)
self.answer2.pack(pady=20)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=10)
def count_measures(self):
self.df = []
self.df = takeResultFromFile()
str_cl = self.entry_cl.get()
str_mor = self.entry_Mor.get()
str_sdtdev = self.entry_stdDev.get()
str_initSample = self.entry_initSample.get()
if not str_cl or not str_mor or not str_sdtdev or not str_initSample:
self.answer2.config(text="!!! Fill all data !!!", font="none 14 bold")
else:
if "%" in str_cl:
self.cl = float(str_cl.replace("%", ""))
else:
self.cl = float(str_cl.replace(",", "."))*100
self.initSample = int(str_initSample)
self.mor = float(str_mor.replace(",", "."))
self.std_Deviation = float(str_sdtdev.replace(",", "."))
self.t_alfa = stats.t.ppf(1 - ((100 - self.cl) / 2 / 100), self.initSample - 1)
self.result = (self.t_alfa*(self.std_Deviation/self.mor))**2
self.answer2.config(text="Result: " + str(math.ceil(self.result)), font="none 14 bold")
app.cleanFile(app.tempFile)
class MinSampleCountForPopAVGNormal(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Minimal sample count for population average\n(Normal distribution):", width=40, font="none 14 bold")
self.answer.pack(pady=30)
self.label2 = tk.Label(self, text='Margin of error (e.g. 0.45):')
self.label2.config(font=('helvetica', 10))
self.label2.pack()
self.entry_Mor = tk.Entry(self)
self.entry_Mor.pack()
self.label3 = tk.Label(self, text='Confidence level (e.g. 0.95 ; 95%):')
self.label3.config(font=('helvetica', 10))
self.label3.pack()
self.entry_cl = tk.Entry(self)
self.entry_cl.pack()
self.label4 = tk.Label(self, text='Standard deviation:')
self.label4.config(font=('helvetica', 10))
self.label4.pack()
self.entry_stdDev = tk.Entry(self)
self.entry_stdDev.pack()
self.button1 = tk.Button(self, text='Get minimal sample size', command=self.count_measures, bg='brown', fg='white')
self.button1.pack(pady=20)
self.answer2 = tk.Label(self)
self.answer2.pack(pady=20)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=10)
def count_measures(self):
self.df = []
self.df = takeResultFromFile()
str_cl = self.entry_cl.get()
str_mor = self.entry_Mor.get()
str_sdtdev = self.entry_stdDev.get()
if not str_cl or not str_mor or not str_sdtdev:
self.answer2.config(text="!!! Fill all data !!!", font="none 14 bold")
else:
if "%" in str_cl:
self.cl = float(str_cl.replace("%", ""))/100.0
else:
self.cl = float(str_cl.replace(",", "."))
self.mor = float(str_mor.replace(",", "."))
self.std_Deviation = float(str_sdtdev.replace(",", "."))
self.z_alfa = stats.norm.ppf((1 + self.cl) / 2.)
self.result = (self.z_alfa*(self.std_Deviation/self.mor))**2
self.answer2.config(text="Result: " + str(math.ceil(self.result)), font="none 14 bold")
app.cleanFile(app.tempFile)
class ArithmeticMean(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Arithmetic mean:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) > 0:
self.result = np.mean(self.df)
self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
self.answer.config(text="Arithmetic Mean: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 0", font="none 28 bold")
app.cleanFile(app.tempFile)
class HarmonicMean(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Harmonic mean:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
self.correctValue = True
if len(self.df) > 0:
for x in self.df:
if x == 0.0:
self.correctValue = False
self.answer.config(text="Values must be not equal 0", font="none 28 bold")
if self.correctValue:
self.array = ""
for x in self.df:
if x == 0.0:
self.answer.config(text="Amount of values need to be more than 0", font="none 28 bold")
self.array += str(x) + "; "
self.result = stats.hmean(self.df)
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
self.answer.config(text="Harmonic Mean: " + str(round(self.result,4)), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 0", font="none 28 bold")
app.cleanFile(app.tempFile)
class VariationCoefficient(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Coefficient of variation:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df = takeResultFromFile()
if len(self.df) > 0:
self.mean = np.mean(self.df)
if self.mean == 0.0:
self.answer.config(text = "Wrong dataset, arithmetic mean = 0", font="none 28 bold")
else:
self.result = np.std(self.df)/self.mean
self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
self.answer.config(text="Coefficient of variation: " + str(round(self.result,4)), font="none 14 bold")
else:
self.answer.config(text = "Amount of values need to be more than 0", font="none 28 bold")
app.cleanFile(app.tempFile)
class StudentsTDistribution(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.fig = Figure(figsize=(5, 3))
self.ax = self.fig.add_subplot()
self.ax.set_title("Student's t-Distribution")
self.canvas = FigureCanvasTkAgg(self.fig, master=self)
self.answer = tk.Label(self, text="Student's t-Distribution:", width=40, font="none 14 bold")
self.answer.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.answer2 = tk.Label(self)
self.answer2.pack(pady=10)
self.values = []
self.label2 = tk.Label(self, text='Degrees of freedom:')
self.label2.config(font=('helvetica', 10))
self.label2.pack()
self.entry_df = tk.Entry(self)
self.entry_df.pack()
self.button1 = tk.Button(self, text='Draw the figure', command=self.countMeasures, bg='brown',
fg='white')
self.button1.pack(pady=10)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=10)
def countMeasures(self):
str_df = self.entry_df.get()
self.values.append(str_df)
self.canvas.get_tk_widget().pack_forget()
handles = []
lines = []
if (len(self.values) > 0):
#and str_df[0] != '-' and str_df[0] != '0'):
for i in self.values:
if int(i) > 0:
self.x = np.linspace(stats.t.ppf(0.01, float(i)), stats.t.ppf(0.99, float(i)), 100)
"""self.array = ""
for x in self.df:
self.array += str(x) + "; "
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")"""
line, = self.ax.plot(self.x, stats.t.pdf(self.x, float(i)))
handles.append(str("k = " + str(i)))
lines.append(line)
self.ax.legend(lines, handles)
self.canvas.draw()
self.canvas.get_tk_widget().pack()
else:
self.answer2.config(text="Wrong value - must be greater then 0", font="none 14 bold")
self.answer.config(text="Resize the window to see the figure", font="none 14 bold")
else:
self.answer.config(text = "Degrees of freedom must be not empty", font="none 18 bold")
app.cleanFile(app.tempFile)
class ChiSquaredTest(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Pearson Chi-squere test:", width=40, font="none 14 bold")
self.answer.pack(pady=20)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.arrayText2 = tk.Label(self)
self.arrayText2.pack(pady=10)
self.label2 = tk.Label(self, text='Trust level:')
self.label2.config(font=('helvetica', 10))
self.label2.pack()
self.entry_ddof = tk.Entry(self)
self.entry_ddof.pack()
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.button1 = tk.Button(self, text='Count Chi-square test', command=self.countMeasures, bg='brown',
fg='white')
self.button1.pack(pady=20)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df1, self.df2 = [], []
self.df1, self.df2 = takeResultFromFile2Lines()
str_ddof = self.entry_ddof.get()
if len(self.df1) > 0 and len(self.df2) > 0:
a,b = stats.chisquare(np.array(self.df1),np.array(self.df2),float(str_ddof))
self.array1 = ""
self.array2 = ""
for x in self.df1:
self.array1 += str(x) + "; "
for y in self.df2:
self.array2 += str(y) + "; "
self.arrayText.config(text="Array: " + str(self.array1), font="none 14 bold")
self.arrayText2.config(text="Array: " + str(self.array2), font="none 14 bold")
self.answer.config(text="The chi-squared test statistic: " + str(round(a,2)) + " and the p-value if the test is: " + str(round(b,4)), font="none 14 bold")
else:
self.answer.config(text = "Minimum one number in each array required", font="none 28 bold")
app.cleanFile(app.tempFile)
class SignTest(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Sign test:", width=40, font="none 14 bold")
self.answer.pack(pady=10)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.button = tk.Button(self, text="Insert data", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(oi.OneInput))
self.button.pack(pady=5)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = []
self.df= takeResultFromFile()
if len(self.df) > 3:
h_median = self.df[0]
self.df.pop(0)
data_set = self.df
result = sign_test(data_set, h_median)
if result[0] == 0:
self.result = "the number of values above and below the hypothetical median " + str(h_median) + " is is the same.\nIt means that this is the median of given sample and we cannot reject H0. "
else:
self.result = "The number of values above and below the hypothetical median " + str(h_median) + " is not the same."
if result[1] < 0.05:
self.result += "\nAssumming alpha = 0.05 we can reject H0, that number: " + str(h_median) + " is a median of given data set."
else:
self.result += "\nAssumming alpha = 0.05 we cannot reject H0, that number: " + str(h_median) + " is a median of given data set. "
# self.result += " " + str(result)
self.array = ""
iter = 6
for x in data_set:
self.array += str(x) + "; "
iter += 1
if iter % 8 == 0:
self.array += "\n"
self.arrayText.config(text="Given hypothetical median: " + str(h_median) + "\n\nGiven numbers to verify "
"hypothesis: " + str(
self.array), font="none 14 bold")
print("Sign test:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text="Sign test checks hypothesis if given number\nis a median of the data set.\n\n "
"Input format:\n - first number: hypothetical median\n - next numbers: data set"
"\nTest assumes alpha = 0.05",
font="none 14 bold", justify='left')
app.cleanFile(app.tempFile)
class ANOVA(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="ANOVA:", width=40, font="none 14 bold")
self.answer.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.arrayText1 = tk.Label(self)
self.arrayText1.pack(pady=10)
self.arrayText2 = tk.Label(self)
self.arrayText2.pack(pady=10)
self.countMeasures()
self.button = tk.Button(self, text="Insert data", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(ti.TwoInputs))
self.button.pack(pady=5)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df1, self.df2 = [], []
self.df1, self.df2 = takeResultFromFile2Lines()
if len(self.df1) > 2:
result = stats.f_oneway(self.df1, self.df2)
self.result = ""
if result[1] < 0.05:
self.result += "Assuming alpha = 0.05 we can reject H0, that given groups have the same population."
else:
self.result += "Assuming alpha = 0.05 we cannot reject H0, that given groups have the same population."
# self.result += " " + str(result)
self.array = ""
for x in self.df1:
self.array += str(x) + "; "
self.arrayText1.config(text="Given measures for first group: " + str(self.array), font="none 14 bold")
self.array = ""
for x in self.df2:
self.array += str(x) + "; "
self.arrayText2.config(text="Given measures for second group: " + str(self.array), font="none 14 bold")
print("ANOVA:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text="The one-way ANOVA tests H0 that two \ngroups have the same population mean.\n\n"
"Input format:\n - first column: measurements for first group\n"
" - second column: measurements for second group\n"
"Test assumes alpha = 0.05",
font="none 14 bold", justify='left')
app.cleanFile(app.tempFile)
class ChiSquared(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Chi squared distribution:", width=40, font="none 14 bold")
self.answer.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.arrayText1 = tk.Label(self)
self.arrayText1.pack(pady=10)
self.arrayText2 = tk.Label(self)
self.arrayText2.pack(pady=10)
self.countMeasures()
self.button = tk.Button(self, text="Insert data", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(ti.TwoInputs))
self.button.pack(pady=5)
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444", fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df1, self.df2 = [], []
self.df1, self.df2 = takeResultFromFile2Lines()
if len(self.df1) > 0:
result = stats.chisquare(self.df1, f_exp=self.df2)
self.result = ""
self.result += "degrees of freedom: " + str(len(self.df1)-1)
self.result += "\n" + str(result)
self.array = ""
for x in self.df1:
self.array += str(x) + "; "
self.arrayText1.config(text="Observed frequencies: " + str(self.array), font="none 14 bold")
self.array = ""
for x in self.df2:
self.array += str(x) + "; "
self.arrayText2.config(text="Expected frequencies: " + str(self.array), font="none 14 bold")
print("Chi squared:", str(self.result))
self.answer.config(text="Result: " + str(self.result), font="none 14 bold")
else:
self.answer.config(text="The chi-square test tests H0 that the categorical \n"
"data has the given frequencies.\n\n "
"Input format:\n - first column: observed frequencies\n"
" - second column: expected frequencies",
font="none 14 bold", justify='left')
app.cleanFile(app.tempFile)
class StandardizedThirdCentralMoment(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Standardized third central moment:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444",
fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = np.array(takeResultFromFile())
self.correctValue = True
if len(self.df) > 0:
self.array = ", ".join([str(i) for i in self.df])
self.result = stats.moment(self.df, moment=3) / (pow(self.df.std(), 3))
self.arrayText.config(text="Array: " + str(self.array), font="none 14 bold")
self.answer.config(text="Standardized third central moment: " + str(round(self.result, 4)), font="none 14 bold")
else:
self.answer.config(text="Amount of values need to be more than 0", font="none 28 bold")
app.cleanFile(app.tempFile)
class NonParametricSkew(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.answer = tk.Label(self, text="Nonparametric skew:", width=40, font="none 14 bold")
self.answer.pack(pady=50)
self.arrayText = tk.Label(self)
self.arrayText.pack(pady=10)
self.answer = tk.Label(self)
self.answer.pack(pady=10)
self.countMeasures()
self.buttonExit = tk.Button(self, text="Exit", width=14, height=1, font="none 14 bold", bg="#3e4444",
fg="white", command=lambda: master.switch_frame(st.StartPage))
self.buttonExit.pack(pady=40)
def countMeasures(self):
self.df = takeResultFromFile()
self.correctValue = True
if len(self.df) > 0:
self.array = ", ".join([str(i) for i in self.df])
self.result = stats.skew(self.df)