You are viewing a single comment's thread. Return to all comments →
physics = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3] history = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]
mean_x = sum(physics) / len(physics) mean_y = sum(history) / len(history)
sum_xy = sum((x - mean_x) * (y - mean_y) for x, y in zip(physics, history))
sum_x_sq = sum((x - mean_x) ** 2 for x in physics) sum_y_sq = sum((y - mean_y) ** 2 for y in history)
r = sum_xy / ( (sum_x_sq ** 0.5) * (sum_y_sq ** 0.5) )
print(round(r, 3)) # Rounding to 3 decimal places
Seems like cookies are disabled on this browser, please enable them to open this website
Correlation and Regression Lines - A Quick Recap #1
You are viewing a single comment's thread. Return to all comments →
physics = [15, 12, 8, 8, 7, 7, 7, 6, 5, 3] history = [10, 25, 17, 11, 13, 17, 20, 13, 9, 15]
Step 1: Calculate means of both lists
mean_x = sum(physics) / len(physics) mean_y = sum(history) / len(history)
Step 2: Calculate numerator (Covariance)
sum_xy = sum((x - mean_x) * (y - mean_y) for x, y in zip(physics, history))
Step 3: Calculate the denominator (Standard deviations of x and y)
sum_x_sq = sum((x - mean_x) ** 2 for x in physics) sum_y_sq = sum((y - mean_y) ** 2 for y in history)
Step 4: Pearson correlation coefficient formula
r = sum_xy / ( (sum_x_sq ** 0.5) * (sum_y_sq ** 0.5) )
Step 5: Print the result
print(round(r, 3)) # Rounding to 3 decimal places