Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The file contains two Python lists, each containing 21 values. These lists contain data about year-on-year changes in two statistics. The list visits holds data

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The file contains two Python lists, each containing 21 values. These lists contain data about year-on-year changes in two statistics. The list visits holds data about changes in visits to the UK by overseas residents, for each quarter from Quarter 1 (Jan to Mar) of 2015 to Quarter 1 of 2020 inclusive. The list spending holds data about changes in spending in the UK by overseas residents, for the same 21 quarters. Both data sets are from the Office for National Statistics (Office for National Statistics, 2020). These statistics show that the visits to the UK by overseas residents decreased by 16% in Quarter 1 of 2020 compared with the same period a year earlier. Also, spending in the UK by overseas residents decreased by 10% in Quarter 1 of 2020 compared with the same period a year earlier, as shown in the figure below. a. 95.py imports the Python function median() you used in Block 2 Part 5 to calculate the median of a list of numbers. Use this function to find the median of visits. In your solution document, give the median. Also provide the Python code you used for calling the median() function and explain how you executed it. (4 marks) b. The Python file q5.py imports the function corr_coef(), which you used in Section 5.4 of Block 2 Part 5 to calculate the correlation coefficient between two lists. i. Use this function to calculate the correlation coefficient between visits and spending In your solution document, provide the resulting figure rounded manually to two decimal places. Also provide the Python code you used for calling the corr_coef() function and explain how you executed it. ii. Give the level of correlation, following Table 5.4 (p. 290) in Block 2 Part 5. iii. Briefly discuss whether any effect you have found is likely to be causal. Give one reason for it being causal and one against. The maximum word limit for Question 5 (b) (i) is 100 words. import math Eldef medianCalist): LE * Calculates the median of a list of numbers. The list must not be empty. number_of_values = len(alist) sorted_list = sortedcalist) # Two cases, depending on whether the number of values is odd or even. quotient = number_of_values // 2 remainder = number_of_values 2 if (remainder as 1): result = sorted_list[quotient] else: result = (sorted_List[quotient - 1] + sorted_list[quotient]) / 2 return result Eldef test mediano: assert median([2]) == 2 assert median([4, 3]) == 3.5 assert median (3, 1, 8, 4, 7, 6, 4, 2, 5, 9]) == 4.5 assert median([7, 2, 6, 2, 5, 3, 1, 6, 8, 6, 6, 4, 9]) == 5 # Unit test test_median Eldef mean(list): Return mean of list** sun = @ count = @ for item in list: sum = sum + iten count = count + 1 return sum / count Eldef test_nean: List = [1, 2, 3, 4, 5] assert(nean(list) == 3) # Unit test test_mean() def corr_coef(list_x, List_y): ** Return correlation between values in list_x and list_y. Lists must be of equal length. x_bar = mean(List_x) y_bar = mean(list_y) sxy = @ SXX = @ syy = @ for index in range(Len(list_x)): x = list_x[index] y = list_y[index] sxy = sxy + (x - x_bar) + (y - y_bar) Sxx = sxx + (x - x_bar) + (x - x_bar) syy = syy + (y - y_bar) + (y - y_bar) return sxy / math.sqrt(sxx * syy) Edef test_corr_coef(: # Data from M140 Unit 9 Example 5 Listi = [78.9, 75.8, 77.3, 74.2, 78.1, 72.8, 77.6, 77.9] List2 = [56.7, 53.1, 56.1, 55.9, 54.1, 48.6, 59.4, 54.0] assert round(corr_coef(listi, list2), 2) == 8.64 # Unit test tma02_stats.py q5.py + x * TM112 213 TMAD2 Q5 86/10/2016 - PP fron tma02_stats import median fron tma2_stats import mean fron tma82_stats import corr_coef * You can use one of two approaches: 1) add suitable code below and then run this file E2) run this file first then do the calculation in the LPython interactive shell. Quarterly ange from a year earlier in visits to the UK from overseas residents CONS) visits = [6.9,1.6,2,7.4,8.8,1.5,3.6,13.1,7.9,8.6,9.2,-5.8, -3.4,-4.5,-3,3.8,-2.5,-1.5,2.8,6.4,-16.1] # Quarterly change from a year earlier in spending during visits to the UK CONS) spending = (3.6,5.7.-4.8,5.7,4.1, 4.1,8.7,8.3,14.1,9.5,22.5,-1.9,2.3,-3,-16.7,-1.8,-7.5,-0.6,9.4,26.5,-9.6]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

Explain consumer behaviour.

Answered: 1 week ago

Question

Explain the factors influencing consumer behaviour.

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago