-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhypotest.py
More file actions
48 lines (37 loc) · 1.11 KB
/
hypotest.py
File metadata and controls
48 lines (37 loc) · 1.11 KB
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
# Input: numpy vector a of scalar values, with k rows, 1 column
# numpy vector b of scalar values, with k rows, 1 column
# scalar alpha
# Output: reject (0 or 1)
class Hypotest():
def __init__(self, a, b, alpha):
self.a = a
self.b = b
self.alpha = alpha
def hypotest(self):
import math
k = len(self.a)
mu_1 = 0
mu_2 = 0
sigma_1 = 0
sigma_2 = 0
for i in range(k):
mu_1 += self.a[i]
mu_1 = (1 / float(k)) * mu_1
for i in range(k):
mu_2 += self.b[i]
mu_2 = (1 / float(k)) * mu_2
for i in range(k):
sigma_1 += (self.a[i] - mu_1) ** 2
sigma_1 = (1 / float(k)) * sigma_1
for i in range(k):
sigma_2 += (self.b[i] - mu_2) ** 2
sigma_2 = (1 / float(k)) * sigma_2
x = ((mu_1 - mu_2) * k ** 0.5) / (sigma_1 + sigma_2) ** 0.5
v = math.ceil(((sigma_1 + sigma_2) ** 2 * (k - 1)) / (sigma_1 ** 2 + sigma_2 ** 2))
from scipy.stats import t
x_alpha_v = t.ppf(1 - self.alpha, v)
if x > x_alpha_v:
reject = 1
else:
reject = 0
return reject