def sample_mean(data, sample_size): total = 0 sample = getSample(data, sample_size) num_values = len(sample) for num in sample: total = addition(total, num) return division(total, num_values)
def sample_mean(data, sample_size): total = 0 # check that get sample returns the proper number of samples # check that sample size is not 0 # check that sample size is not larger than the population # https://realpython.com/python-exceptions/ # https://stackoverflow.com/questions/129507/how-do-you-test-that-a-python-function-throws-an-exception sample = getSample(data, sample_size) num_values = len(sample) for num in sample: total = addition(total, num) return division(total, num_values)
def sample_st_deviation(data, sample_size): dev = 0 sample = getSample(data, sample_size) sample_values = len(sample) x_bar = sample_mean() x = sample_values n = subtraction(sample_values, 1) for dev in sample: dev = subtraction(x, x_bar) square_x_bar = square(dev) add = addition(square_x_bar, square_x_bar) divide = division(add, n) return squareroot(divide)
def ssd(data): total = 0 sample = random.randint(1, len(data)) new_sample = getSample(data, sample) new_mean = mean(new_sample) for numb in new_sample: result = subtraction(numb, new_mean) sq = squaree(result) total = addition(total, sq) n = len(new_sample) d = division(subtraction(1, n), total) samp_sd = squar_rot(d) # actual_sd = statistics.stdev(new_sample) return samp_sd