Пример #1
0

def l(x, y):
    s_xy = 0.0
    for i in range(len(x)):
        s_xy += (x[i] * y[i])
    return s_xy - sum(x) * sum(y) / len(x)


def age(stats):
    x = []
    y = []
    for s in stats:
        x.append(s[-2])
        y.append(s[4])
    lxy = l(x, y)
    lxx = l(x, x)
    b = lxy / lxx
    ybar = mean(y)
    xbar = mean(x)
    a = ybar - b * xbar
    # difference
    st = sum([(yi - ybar) ** 2 for yi in y])
    yesit = [a + b * xi for xi in x]
    sr = sum([(ye - ybar) ** 2 for ye in yesit])
    return [a, b, sr / st]


if __name__ == '__main__':
    print(age(get_data()))
Пример #2
0
from statistic.test.independ import indep

__author__ = 'zzt'


def add_data(m, a):
    if 5 < m <= 10:
        m *= 4.33

    if 25 < m <= 37:
        a[0] += 1
    elif 37 < m <= 40:
        a[1] += 1
    elif 40 < m < 49:
        a[2] += 1


def first_sec(stats):
    obs = [[0, 0, 0], [0, 0, 0]]
    for l in stats:
        if l[5] == 1:
            add_data(l[2], obs[0])
        else:
            add_data(l[2], obs[1])

    return chi2_contingency(obs)[0:2]
    # return indep(obs)

if __name__ == '__main__':
    print(first_sec(get_data()))
Пример #3
0

def l(x, y):
    s_xy = 0.0
    for i in range(len(x)):
        s_xy += (x[i] * y[i])
    return s_xy - sum(x) * sum(y) / len(x)


def age(stats):
    x = []
    y = []
    for s in stats:
        x.append(s[-2])
        y.append(s[4])
    lxy = l(x, y)
    lxx = l(x, x)
    b = lxy / lxx
    ybar = mean(y)
    xbar = mean(x)
    a = ybar - b * xbar
    # difference
    st = sum([(yi - ybar)**2 for yi in y])
    yesit = [a + b * xi for xi in x]
    sr = sum([(ye - ybar)**2 for ye in yesit])
    return [a, b, sr / st]


if __name__ == '__main__':
    print(age(get_data()))