Example #1
0
def samplesizeKnownPop(data, confidence, error):
    z = division(confidence, 2)
    ztable_value = normalProbabilityDensity(z)
    standardDeviation = standard_deviation(data)
    ztableTimesStandard = product(ztable_value, standardDeviation)
    nextStep = division(ztableTimesStandard, error)
    sample_size = power(nextStep, 2)
    return sample_size
def sample_size_unknown(percent, confidence, width):
    confidence_int = division(confidence, 2)
    zscore = normalProbabilityDensity(confidence_int)
    error = division(width, 2)
    p = subtraction(1, percent)
    pTimesq = product(percent, p)
    zDivideError = division(zscore, error)
    powerZdivError = power(zDivideError, 2)
    return product(pTimesq, powerZdivError)
Example #3
0
def margin_error(data, sample_size):
    zscore = zScore(data)
    standardDeviation = standard_deviation(data)
    denominator = root(sample_size, 2)
    willMultiply = division(standardDeviation, denominator)
    marginOfError = product(zscore, willMultiply)
    return marginOfError
def pop_correlation_coefficient(data_x, data_y):
    x = pop_stand_dev(data_x)
    y = pop_stand_dev(data_y)
    divisor = multiplication(x, y)

    d = population_mean(data_x)
    e = population_mean(data_y)
    a = [(element - d) for element in data_x]
    b = [(element - e) for element in data_y]
    size = len(a)
    product = [a[i] * b[i] for i in range(size)]
    total = sum(product)
    covariance = division(size, total)

    d = division(divisor, covariance)
    return d
Example #5
0
def zScore(data):
    x = random.choice(data)
    meanData = mean(data)
    standardDeviation = standard_deviation(data)
    numerator = subtraction(x, meanData)
    z = division(numerator, standardDeviation)
    return z
Example #6
0
def sampleSize(data, proportion):
    denominator = power(margin_error(data, sample_size=10), 2)
    q = subtraction(1.0, proportion)
    half_numerator = product(proportion, q)
    z = normalProbabilityDensity(denominator)
    numerator = product(power(z, 2), half_numerator)
    n = division(numerator, denominator)
    return n
Example #7
0
def meanDeviation(data):
    global summation
    num_values = len(data)
    xbar = mean(data)
    willSquare = []
    squared = []
    for items in data:
        willSquare.append(abs(subtraction(items, xbar)))
        for values in willSquare:
            squared.append(power(values, 2))
            summation = sum(squared)
    return division(summation, num_values)
def sampleCorrelation(dataX, dataY):
    #dataX= []
    #dataY = []
    meanX = mean(dataX)
    meanY = mean(dataY)
    deviationX = standard_deviation(dataX)
    deviationY = standard_deviation(dataY)
    rNumerator = 0.0
    for i in range(len(dataX)):
        rNumerator += product(subtraction(dataX[i], meanX),
                              subtraction(dataY[i], meanY))
    rDenominator = product(deviationX, deviationY)
    r = division(rNumerator, rDenominator)
    return r
Example #9
0
def z_score(score, stdev, meanscore):
    try:
        score = int(score)
        stdev = int(stdev)
        meanscore = int(meanscore)

        #Score minus mean score
        difference = (score - meanscore)

        #Divide by Standard Deviation
        result = division(stdev, difference)

        return round(result, 2)

    except ZeroDivisionError:
        print("Error!  Cannot divide by 0")
    except ValueError:
        print("Error! Invalid data inputs")
Example #10
0
def normalProbabilityDensity(x):
    constant = division(1.0, math.sqrt(2 * math.pi))
    return product(constant, math.exp((-x**2) / 2.0))