def Pop_correlation_coefficient(my_population, my_population2): mean1, mean2 = Mean(my_population), Mean(my_population2) sd1, sd2 = Sd(my_population), Sd(my_population2) correlation = 0 for i in range(0, len(my_population)): factor_a = (my_population[i] - mean1) / sd1 factor_b = (my_population2[i] - mean2) / sd2 correlation = correlation + (factor_a * factor_b) pop_correlation_coefficient = correlation / len(my_population) return pop_correlation_coefficient
def Standardised_score(my_population): my_mean = Mean(my_population) my_sd = Sd(my_population) standardised_score = list() for x in my_population: my_score = (x - my_mean) / my_sd standardised_score.append(my_score) return standardised_score
def Z_score(my_population): my_mean = Mean(my_population) my_sd = Sd(my_population) zscore = list() for x in my_population: my_score = (x - my_mean) / my_sd zscore.append(my_score) return zscore
def Variance(my_population): sum = 0 index = 0 my_variance = 0 calculated_mean = Mean(my_population) for index in range(0, len(my_population)): sum += ((my_population[index] - calculated_mean) ** 2) if (len(my_population) == 0): my_variance = 0 else: my_variance = sum/len(my_population) return my_variance
def Proportion(my_population): # Any number 20% above or 20% below the mean is being considered as outlier. # This function returns the proportion of the population which is outlier. my_mean = Mean(my_population) lower_limit = 0.8 * my_mean higher_limit = 1.2 * my_mean count = 0 proportion_success = list() for i in my_population: if (i>higher_limit) or (i< lower_limit): count = count + 1 proportion_success.append(i) p = (count/float(len(my_population))) return p,proportion_success
def sample_mean(self,my_population): sample_list = sample(my_population,math.floor(len(my_population)/2)) write_answer("answer_sample_mean.csv",Mean(sample_list)) return Sample_mean(sample_list)
def mean(self,my_population): return round(Mean(my_population),2)