Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Background The purpose of this assignment is to perform some statistical analysis on a set of data. Your program will read in two sets of
Background The purpose of this assignment is to perform some statistical analysis on a set of data. Your program will read in two sets of numbers stored in separate files which represent statistical (x, y) pairs, represent the numbers as two lists of floats, calculate the biased, weighted mean deviation of the data, and output the result. The formula for biased, weighted mean deviation, a measurement of variation or dispersion of the data from the average value, is: = 21- yi(X; - *)2 Eizo yi 11 where, n-1 #* - Eizo y; x; n-1 Li=0 Xi Design, implement, and test a program that satisfies the requirements below. Requirements 1. The program starts with two text files defined for you below that will be used in your program. The first file is a file Fx containing a (finite) sequence x0, x1, ... , x,-1 of numbers, where each number represents the x; member of the sequence, in order. 2. The program reads in the values in F and constructs a list Lx of floats representing the sequence. 3. The program repeats the previous two requirements for a second file Fy containing the corresponding yo, Y, ... , Yn-1 values, and constructs a list Ly of floats. 4. The program computes the biased, weighted mean deviation o of Lx and Ly. The program returns o, Lx and Ly as output. 5. Your name, MacID, student number, and the date are given in comments at the top of the first Python cell below. 6. Your answers to the design questions and test plan are given in the appropriate Markdown cells below. 7. Your program MUST have valid Python syntax and it must run without errors. Ensure that your program runs properly by running it before you submit. 8. You must sign out with a TA or Al after you have submitted your lab at the submission station. Failure to do so could result in a mark of zero. Design and Implementation Instructions You may assume without penalty that there is exactly one number per line in the files F, and Fy and that both files are the same length. # Code to generate sample text files for testing - DO NOT MODIFY THIS CODE infile1 = open("Ex.txt", 'w') infile1.write("-19 -42 3 5 22 -7 -21 -33 -42") infile1.close() # infile1 = open("Fy.txt", 'W') infile1.write("24 13 45 17 18 37 13 35") infile1.close() 009 11 12 infile1 = open("Fx2.txt", 'w') infile1.write("-4.41 25.17 -29.20 -50.21 35.36 47.7 -11.43 -47.41 -19.6 31.30 -5.27") infile1.close() infile1 = open("Fy2.txt", 'w') infile1.write("56.70 21.58 32.66 65.55 8.58 48.19 60.14 80.54 38.60 100.82 64.30") infile1.close() 19 infile1 = open("Fx3.txt", 'w') infile1.write("3.2 -4.56 2.3 ") infile1.close() 20 infile1 = open("Fy3.txt", 'w') infile1.write("1.01 6.3 ") infile1.close() In [ ]: #DO NOT PUT AN INPUT STATEMENT IN THIS CELL ##################---mean_deviation(filel, file2) - (Lx: 2, Ly: 2, sigma: 6 Marks)---################## def mean_deviation(file1, file2): "" "This function calculates the biased, weighted mean deviation for the x values stored in file1 and the y values stored in file2" # WRITE YOUR CODE BETWEEN HERE AND ... Lx = [] Ly = [] #change this value to your answer #change this value to your answer a = 0 sigmA = for i in range(n): infile = open ('Fy.txt', 'r') sigma = sqrt(sigmA/sigma) #change this value to your answer # ... HERE return Lx, Ly, sigma #Change the values "Fx.txt" and "Fy.txt" to test your code with different files result = mean_deviation("Ex.txt", "Fy.txt") print("Lx =", result[@]) 29 print("Ly =", result[1]) 30 print("sigma =", result[2]) Background The purpose of this assignment is to perform some statistical analysis on a set of data. Your program will read in two sets of numbers stored in separate files which represent statistical (x, y) pairs, represent the numbers as two lists of floats, calculate the biased, weighted mean deviation of the data, and output the result. The formula for biased, weighted mean deviation, a measurement of variation or dispersion of the data from the average value, is: = 21- yi(X; - *)2 Eizo yi 11 where, n-1 #* - Eizo y; x; n-1 Li=0 Xi Design, implement, and test a program that satisfies the requirements below. Requirements 1. The program starts with two text files defined for you below that will be used in your program. The first file is a file Fx containing a (finite) sequence x0, x1, ... , x,-1 of numbers, where each number represents the x; member of the sequence, in order. 2. The program reads in the values in F and constructs a list Lx of floats representing the sequence. 3. The program repeats the previous two requirements for a second file Fy containing the corresponding yo, Y, ... , Yn-1 values, and constructs a list Ly of floats. 4. The program computes the biased, weighted mean deviation o of Lx and Ly. The program returns o, Lx and Ly as output. 5. Your name, MacID, student number, and the date are given in comments at the top of the first Python cell below. 6. Your answers to the design questions and test plan are given in the appropriate Markdown cells below. 7. Your program MUST have valid Python syntax and it must run without errors. Ensure that your program runs properly by running it before you submit. 8. You must sign out with a TA or Al after you have submitted your lab at the submission station. Failure to do so could result in a mark of zero. Design and Implementation Instructions You may assume without penalty that there is exactly one number per line in the files F, and Fy and that both files are the same length. # Code to generate sample text files for testing - DO NOT MODIFY THIS CODE infile1 = open("Ex.txt", 'w') infile1.write("-19 -42 3 5 22 -7 -21 -33 -42") infile1.close() # infile1 = open("Fy.txt", 'W') infile1.write("24 13 45 17 18 37 13 35") infile1.close() 009 11 12 infile1 = open("Fx2.txt", 'w') infile1.write("-4.41 25.17 -29.20 -50.21 35.36 47.7 -11.43 -47.41 -19.6 31.30 -5.27") infile1.close() infile1 = open("Fy2.txt", 'w') infile1.write("56.70 21.58 32.66 65.55 8.58 48.19 60.14 80.54 38.60 100.82 64.30") infile1.close() 19 infile1 = open("Fx3.txt", 'w') infile1.write("3.2 -4.56 2.3 ") infile1.close() 20 infile1 = open("Fy3.txt", 'w') infile1.write("1.01 6.3 ") infile1.close() In [ ]: #DO NOT PUT AN INPUT STATEMENT IN THIS CELL ##################---mean_deviation(filel, file2) - (Lx: 2, Ly: 2, sigma: 6 Marks)---################## def mean_deviation(file1, file2): "" "This function calculates the biased, weighted mean deviation for the x values stored in file1 and the y values stored in file2" # WRITE YOUR CODE BETWEEN HERE AND ... Lx = [] Ly = [] #change this value to your answer #change this value to your answer a = 0 sigmA = for i in range(n): infile = open ('Fy.txt', 'r') sigma = sqrt(sigmA/sigma) #change this value to your answer # ... HERE return Lx, Ly, sigma #Change the values "Fx.txt" and "Fy.txt" to test your code with different files result = mean_deviation("Ex.txt", "Fy.txt") print("Lx =", result[@]) 29 print("Ly =", result[1]) 30 print("sigma =", result[2])
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started