Question: (10) Python Exercise [10 points total]. Submit two files: 1. explanations, graphics (if any) and results in PDE format with your Python code, and 2.
(10) Python Exercise [10 points total]. Submit two files: 1. explanations, graphics (if any) and results in PDE format with your Python code, and 2. Python Code itself in ipynb (or .py) format Group work policy: You can discuss the problem together with your friends but you have to submit your own work (PDF and Python codes). Let us consider 1000 voters. Each voter votes yes or no on Proposition X. In this exercise we shall see the fluctuation of the number of yes. a. (2 point) Write a function of p e [0,1] generate 1000 IID. Bernoulli random variables tek, k = 1, , 1000} with probabilities P(1 = 1) = p and P(fi = 0) = 1-p. That is, the input is p and output is (k, k = 1, . . . , 1000). You should not print all the variables , k = 1, . . . , 1000} in the output (save time!). This sequence represents the opinions of voters (Ei = 1 means that the i-th voter says yes, for example). b. (2 point) Using the function in part a, write a function of p e (0, 1] to generate the sequence (Sk = | + . . . + Ee , k = 1, . . . , 1000} of sums of these 's. That is, the input is p and output is the sum (Sk :-1 ++5k ,k = 1,.. , 1000} . You should not print all the variables. Sk represents the cumulative counts of yes in the first k voters. c. (3 points) Using the function in part b, draw a (time-series) plot k-Sk/k, k 1, , 1000 of the sample average Sk/kThat is, the x-axis is k- 1, ,1000, and the y-axis is Sk for three different values of p = 0.25, 0.5, 0.75 . points) Compare the plots of three cases p = 0.25, 0.5, 0.75 in part c and describe the d. (3 similarities and differences (10) Python Exercise [10 points total]. Submit two files: 1. explanations, graphics (if any) and results in PDE format with your Python code, and 2. Python Code itself in ipynb (or .py) format Group work policy: You can discuss the problem together with your friends but you have to submit your own work (PDF and Python codes). Let us consider 1000 voters. Each voter votes yes or no on Proposition X. In this exercise we shall see the fluctuation of the number of yes. a. (2 point) Write a function of p e [0,1] generate 1000 IID. Bernoulli random variables tek, k = 1, , 1000} with probabilities P(1 = 1) = p and P(fi = 0) = 1-p. That is, the input is p and output is (k, k = 1, . . . , 1000). You should not print all the variables , k = 1, . . . , 1000} in the output (save time!). This sequence represents the opinions of voters (Ei = 1 means that the i-th voter says yes, for example). b. (2 point) Using the function in part a, write a function of p e (0, 1] to generate the sequence (Sk = | + . . . + Ee , k = 1, . . . , 1000} of sums of these 's. That is, the input is p and output is the sum (Sk :-1 ++5k ,k = 1,.. , 1000} . You should not print all the variables. Sk represents the cumulative counts of yes in the first k voters. c. (3 points) Using the function in part b, draw a (time-series) plot k-Sk/k, k 1, , 1000 of the sample average Sk/kThat is, the x-axis is k- 1, ,1000, and the y-axis is Sk for three different values of p = 0.25, 0.5, 0.75 . points) Compare the plots of three cases p = 0.25, 0.5, 0.75 in part c and describe the d. (3 similarities and differences
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
