Question: 1. Please write the following code on Python 3. Also, please share you code and please answer entire solution not just part. Also, please show

1. Please write the following code on Python 3. Also, please share you code and please answer entire solution not just part. Also, please show all outputs. Comment in you code.

Problem 3(a). A first pass at simulation

Write Python code to produce a list of 50 ordered pairs (c,n)(c,n), where cc represents chocolate consumption in kg/year/person and nn represents the number of Nobel laureates per 10 million population, for some country. The values for cc should be random numbers (not necessarily integers!) uniformly distributed between 0 and 15. You may assume that cc and nn are related by

n=0.4c0.8n=0.4c0.8.

However, it is impossible for a nation to have a negative number of Nobel laureates, so if your predicted value of nn is less than 0 for a country, replace that value by 0.

Print your list of ordered pairs; report your values of cc and nn to 2 decimal places.

Problem 3(b). Error term.

Our list of data from part (a) is not a good simulation of real-world data, because it is perfectly linear. That is, even though the per capita chocolate variable is random, the number of Nobel laureates is 100% predicted from that value. So, we'll randomly perturb the number of laureates for each country.

Using the 50 cc and nn values you generated in part (a), generate new nene values, using the following formula:

ne=n+.ne=n+.

Here should be a random variable with normal distribution, mean 0, and standard deviation 1. Using the list of ordered pairs generated in 3(a), create a new list of 50 ordered pairs (c,ne)(c,ne). Each nn should be perturbed by a distinct and randomly generated value -- do not use the same for all nn.

Again, your simulated data should not predict negative numbers of Nobel laureates. Again, do not generate a new list of (c,n)(c,n) values; you must re-use the list of ordered pairs already generated in 3(a). Data you create as the result of evaluating a cell is available for use in other cells. Check it out -- try running the Python command who if you want to prove it to yourself (a good habit to be in!).

Print your new list of ordered pairs.

Problem 3(c). Winners and losers.

Make a new list consisting of all of the ordered pairs (c,ne)(c,ne) from your list from part (b) such that ne>0.4c0.8ne>0.4c0.8 (the nn value increased upon perturbation).

Print this new (shorter) list. Use Python to calculate how many items are in your list of winners. Hint to help you know when you have the answer correct: since the perturbation has mean 0, we expect about half to have gone up...

Problem 3(d). Preparing data to transfer to R.

For future use, split your list of ordered pairs from Problem 3(b) (not 3(c)!) into two lists.

The first list should contain the cc values, and

the second list should contain the nene values.

To actually transfer data to R, we would write it to a file, perhaps as a csv file. We'll leave that for later.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!