subject

Median of a sample If the distribution is given, as above, the median can be determined easily. In this problem we will learn how to approximate the median when the distribution is not given, but we are given samples that it generates. Similar to distributions, we can define the median of a set to be the set element m′ such that at least half the elements in the set are ≤m′ and at least half the numbers in the collection are ≥m′. If two set elements satisfy this condition, then the median is their average. For example, the median of [3,2,5,5,2,4,1,5,4,4] is 4 and the median of [2,1,5,3,3,5,4,2,4,5] is 3.5. To find the median of a P distribution via access only to samples it generates, we obtain samples from P, caluclate their median , and then repeat the process many times and determine the average of all the medians.

Exercise 2

Write a function sample_median(n, P) that generates n random values using distribution P and returns the median of the collected sample.

Hint: Use function random. choice() to sample data from P and median() to find the median of the samples

* Sample run *

print(sample_median(10,[0.1 0.2 0.1 0.3 0.1 0.2]))
print(sample_median(10,[0.1 0.2 0.1 0.3 0.1 0.2]))
print(sample_median(5,P=[0.3,0.7])
print(sample_median(5,P=[0.3,0.7])
* Expected Output *

4.5
4.0
2.0
1.0
Exercise 4

In this exercise, we explore the relationship between the distribution median mm, the sample median with n samples, and []E[Mn],the expected value of Mn.

Write a function average_sample_median(n, P), that return the average Mn of 1000 samples of size n sampled from the distribution P.

* Sample run *

print(average_sample_median(10,[0.2 ,0.1,0.15,0.15,0.2,0.2]))
print(average_sample_median(10,[0.3 ,0.4,0.3]))
print(average_sample_median(10,P=[0 .99,0.01])
* Expected Output *

3.7855
2.004
1


Question a:

In exercise 2,

Which of the following is a possible output of sample_median(n, [0.12,0.04,0.12,0.12,0.2,0.16,0.16, 0.08]) for any n?

3

9

7

4

Question b:

In exercise 4,

what value does average_sample_median(100,[0.12, 0.04, 0.12, 0.12, 0.2, 0.16, 0.16, 0.08]) return?

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:30
Working on this program in python 3.7: a year in the modern gregorian calendar consists of 365 days. in reality, the earth takes longer to rotate around the sun. to account for the difference in time, every 4 years, a leap year takes place. a leap year is when a year has 366 days: an extra day, february 29th. the requirements for a given year to be a leap year are: 1) the year must be divisible by 42) if the year is a century year (1700, 1800, the year must be evenly divisible by 400some example leap years are 1600, 1712, and 2016.write a program that takes in a year and determines whether that year is a leap year.ex: if the input is 1712, the output is: 1712 is a leap year. ex: if the input is 1913, the output is: 1913 is not a leap year. your program must define and call the function isleapyear(useryear). the function should return true if the input year is a leap year and false otherwise.
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
Which type of file can be used to import data into a spreadsheet?
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
Which text format is this, "the text is transcribed exactly as it sounds and includes all the utterances of the speakers. "?
Answers: 2
question
Computers and Technology, 23.06.2019 17:00
In which of the following ways can using test-taking tips you? a. you can focus on the information that you need to study. b. you will see the answers to the test. c. you will study more. d. you will be less organized.
Answers: 1
You know the right answer?
Median of a sample If the distribution is given, as above, the median can be determined easily. In t...
Questions
question
History, 17.11.2020 20:00
question
Mathematics, 17.11.2020 20:00
question
Physics, 17.11.2020 20:00
Questions on the website: 13722367