Untitled
unknown
plain_text
2 years ago
867 B
4
Indexable
import math
from scipy.stats import norm
class HypothesisTest:
def __init__(self, n, k, p0, alpha):
self.n = n
self.k = k
self.p0 = p0
self.alpha = alpha
self.p = self.k / self.n
self.z = norm.ppf(1 - self.alpha/2)
self.interval = self.calculate_interval()
def calculate_interval(self):
return (self.p - self.z*math.sqrt((self.p*(1-self.p))/self.n), self.p + self.z*math.sqrt((self.p*(1-self.p))/self.n))
def check_hypothesis(self):
if self.p0 >= self.interval[0] and self.p0 <= self.interval[1]:
return "Гипотеза совместима с данными"
else:
return "Отказ от гипотезы"
test = HypothesisTest(n=7280, k=3743, p0=0.515, alpha=0.02)
print(test.interval)
print(test.check_hypothesis())
Editor is loading...
Leave a Comment