Question: Cannot import external package spearmanr from scipy. Question 2 The Spearman rank correlation is used to evaluate if the relationship between two variables, X and

Cannot import external package spearmanr from scipy.
Question 2 The Spearman rank correlation is used to evaluate if the relationship between two variables, X and Y is monotonic. The rank correlation measures how closely related the ordering of one variable to the other variable, with no regard to the actual values of the variables. To calculate the Spearman rank correlation for X and Y, p(X, Y): . the values of X and Y are ranked in an ascending order respectively. The smallest value will be given a rank of 1, the next smaller value will be given a rank of 2, etc. If there are multiple entries with the same value, then each entry is ranked equal to the average position. the rank difference for the i-th pair of x; and yi is then calculated and 6 1-1 d? p(X,Y) = 1- N(N2 - 1) where N is the total pairs of data points and d is the rank difference for the i-th pair of data. (a) Create a function calculate_spearman_rank_correlation(X, Y) that returns you the value of the rank correlation, given two sets of data X and Y. (25 marks) (b) Use your function on the test cases and print your results to one (1) decimal place (e.g. 9.8%): Test Case x Y 1 2 3 al N [10, 20, 30, 40, 50] [10, 20, 30, 40, 50] [10, 20, 20, 50, 40] [20, 20, 20, 50, 10, 40] [50, 50, 50, 30, 30, 30] [2, 4, 6, 8, 10] [10, 8, 6, 4, 2] [2, 10, 6, 4, 8] [2, 10, 8, 6, 10, 10] [2, 10, 8, 6, 10, 10] 4 5 (5 marks) Question 2 The Spearman rank correlation is used to evaluate if the relationship between two variables, X and Y is monotonic. The rank correlation measures how closely related the ordering of one variable to the other variable, with no regard to the actual values of the variables. To calculate the Spearman rank correlation for X and Y, p(X, Y): . the values of X and Y are ranked in an ascending order respectively. The smallest value will be given a rank of 1, the next smaller value will be given a rank of 2, etc. If there are multiple entries with the same value, then each entry is ranked equal to the average position. the rank difference for the i-th pair of x; and yi is then calculated and 6 1-1 d? p(X,Y) = 1- N(N2 - 1) where N is the total pairs of data points and d is the rank difference for the i-th pair of data. (a) Create a function calculate_spearman_rank_correlation(X, Y) that returns you the value of the rank correlation, given two sets of data X and Y. (25 marks) (b) Use your function on the test cases and print your results to one (1) decimal place (e.g. 9.8%): Test Case x Y 1 2 3 al N [10, 20, 30, 40, 50] [10, 20, 30, 40, 50] [10, 20, 20, 50, 40] [20, 20, 20, 50, 10, 40] [50, 50, 50, 30, 30, 30] [2, 4, 6, 8, 10] [10, 8, 6, 4, 2] [2, 10, 6, 4, 8] [2, 10, 8, 6, 10, 10] [2, 10, 8, 6, 10, 10] 4 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
