Exemple #1
0
def covariance(*stack):
    items = checkParams(stack, 'plural')
    
    X = average(items['Xi'])
    Y = average(items['Yi'])
    
    return items['XiYiFi']/items['Fi'] - X*Y
Exemple #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
Exemple #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
Exemple #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
Exemple #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'])
Exemple #6
0
def correlationCoefficient(*stack):
    items = checkParams(stack, 'plural')
    
    return covariance(items)/(sqrt(varianceB(items['Xi']))*sqrt(varianceB(items['Yi'])))
Exemple #7
0
def percentile(P, *items):
    items = checkParams(items, 'single')
    
    items = items.copy()
    items, Fi = givePositions(items)
    return getPosition(items, P*Fi/100)
Exemple #8
0
def quartile(Q, *items):
    items = checkParams(items, 'single')
    
    items = items.copy()
    items, Fi = givePositions(items)
    return getPosition(items, Q*Fi/4)
Exemple #9
0
def median(*items):
    items = checkParams(items, 'single')
    
    items = items.copy()
    items, Fi = givePositions(items)
    return getPosition(items, Fi/2)