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
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)
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
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 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 normalProbabilityDensity(x): constant = division(1.0, math.sqrt(2 * math.pi)) return product(constant, math.exp((-x**2) / 2.0))