def pop_correlation_coefficient(data): x_data = CsvReader('Tests/Data/female_height.csv').data y_data = CsvReader('Tests/Data/male_height.csv').data x = pop_stand_dev(x_data) y = pop_stand_dev(y_data) divisor = multiplication(x, y) z = len(data) # Covariance calculation: a = subtraction(data, sampleMean) b = subtraction(data, population_mean) c = multiplication(a, b) covariance = division(z, (sum(c))) # Population Correlation Coefficient calculation: d = division(divisor, covariance) return d
def pop_correlation_coefficient(data_x, data_y): x = pop_stand_dev(data_x) y = pop_stand_dev(data_y) divisor = multiplication(x, y) # Covariance calculation: 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) # Population Correlation Coefficient calculation: d = division(divisor, covariance) return d
def median(data): data = [num for elem in data for num in elem] new_data = [float(x) for x in data] new_data = sorted(new_data) length = len(new_data) if length < 1: return None if length % 2 == 0: return division(2.0, addition(new_data[(length - 1) // 2], new_data[(length + 1) // 2])) else: return new_data[(length - 1) // 2]
def pop_correlation_coefficient(data): # x_data = CsvReader('Tests/Data/female_height.csv').data # y_data = CsvReader('Tests/Data/male_height.csv').data x_data = [num for elem in data for num in elem] y_data = [num for elem in data for num in elem] new_x_data = [float(x) for x in x_data] new_y_data = [float(x) for x in y_data] x = pop_stand_dev(new_x_data) y = pop_stand_dev(new_y_data) divisor = multiplication(x, y) z = len(new_x_data) # Covariance calculation: a = subtraction(new_x_data, population_mean(new_x_data)) b = subtraction(new_y_data, population_mean(new_y_data)) c = multiplication(a, b) covariance = division(z, (sum(c))) # Population Correlation Coefficient calculation: d = division(divisor, covariance) return d