Esempio n. 1
0
def covariance(*stack):
    items = checkParams(stack, 'plural')
    
    X = average(items['Xi'])
    Y = average(items['Yi'])
    
    return items['XiYiFi']/items['Fi'] - X*Y
Esempio n. 2
0
def variance(*items):
    items = checkParams(items, 'single')
    
    count = 0
    count2 = 0
    for item in items.keys():
        count += item**2 * items[item]
        count2 += items[item]
    return count / count2 - average(items)**2
Esempio n. 3
0
def average(*items):
    items = checkParams(items, 'single')
    
    X = 0
    count = 0
    for item in items.keys():
        X += item * items[item]
        count += items[item]
    return X / count
Esempio n. 4
0
def varianceB(*items):
    items = checkParams(items, 'single')
    
    count = 0
    count2 = 0
    mean = average(items)
    for item in items.keys():
        count += ((item - mean)**2)*items[item]
        count2 += items[item]
    return count / count2
Esempio n. 5
0
def regressionLine(value, *stack):
    items = checkParams(stack, 'plural')
    value = {k.lower(): v for k,v in value.items()}
    
    if 'x' in value:
        diff = covariance(items)/varianceB(items['Xi'])
        return diff*value['x']-diff*average(items['Xi'])+average(items['Yi'])
        
    if 'y' in value:
        diff = covariance(items)/varianceB(items['Yi'])
        return diff*value['y']-diff*average(items['Yi'])+average(items['Xi'])
Esempio n. 6
0
def correlationCoefficient(*stack):
    items = checkParams(stack, 'plural')
    
    return covariance(items)/(sqrt(varianceB(items['Xi']))*sqrt(varianceB(items['Yi'])))
Esempio n. 7
0
def percentile(P, *items):
    items = checkParams(items, 'single')
    
    items = items.copy()
    items, Fi = givePositions(items)
    return getPosition(items, P*Fi/100)
Esempio n. 8
0
def quartile(Q, *items):
    items = checkParams(items, 'single')
    
    items = items.copy()
    items, Fi = givePositions(items)
    return getPosition(items, Q*Fi/4)
Esempio n. 9
0
def median(*items):
    items = checkParams(items, 'single')
    
    items = items.copy()
    items, Fi = givePositions(items)
    return getPosition(items, Fi/2)