-
Notifications
You must be signed in to change notification settings - Fork 1
/
stat_util.py
54 lines (54 loc) · 1.72 KB
/
stat_util.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
import scipy
from scipy import stats
import numpy as np
import pandas as pd
def moving_average(x, w):
"""
Moving average of a sequence
:param x: array_like, sequence of values
:param w: int, window size
:return: array_like, moving average of x
"""
return np.convolve(x, np.ones(w), 'valid') / w
def exponential_moving_average(x, alpha):
"""
Exponential moving average of a sequence
:param x: array_like, sequence of values
:param alpha: float, smoothing factor
:return: array_like, exponential moving average of x
"""
x = pd.Series(x)
smoothed = x.ewm(alpha=alpha).mean()
return np.array(smoothed).tolist()
def student_t_test(x, y):
"""
Student's t-test for two independent samples of scores
:param x: array_like, sample of scores
:param y: array_like, sample of scores
:return: t-value and p-value
"""
return stats.ttest_ind(x, y)
def paired_student_t_test(x, y):
"""
Student's t-test for two paired samples of scores
:param x: array_like, sample of scores
:param y: array_like, sample of scores
:return: t-value and p-value
"""
return stats.ttest_rel(x, y)
def wilcoxon_signed_rank_test(x, y):
"""
Wilcoxon signed-rank test for two paired samples of scores
:param x: array_like, sample of scores
:param y: array_like, sample of scores
:return: t-value and p-value
"""
return stats.wilcoxon(x, y)
def main():
x = "0.7376685844 0.6846897442 0.7123568159 0.7445031563 0.7098522955".split()
x = [float(i) for i in x]
y = "0.8537637012 0.6963595123 0.7467978729 0.7289618752 0.821170706".split()
y = [float(i) for i in y]
print(paired_student_t_test(x, y))
if __name__ == '__main__':
main()