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, 21.06.2019 16:50
3(c). is the following command correct? if not, correct the syntax and explain your answers. you can just rewrite/correct only the wrong parts. (4) select p#, city, zipcode, count(*) from client c, property p, viewing v where c.c# = v.c# and v.p# = p.p# group by p#, city having count(*) > 3;
Answers: 1
question
Computers and Technology, 23.06.2019 08:30
When you interpret the behavior of others according to your experiences and understanding of the world your evaluation is
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Which of the following statements is false? a. a class can directly inherit from class object. b. if the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. c. a class's instance variables are normally declared private to enforce good software engineering. d. it's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires.
Answers: 3
question
Computers and Technology, 23.06.2019 19:30
Of the following pieces of information in a document, for which would you most likely insert a mail merge field?
Answers: 3
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
Mathematics, 20.05.2020 23:04
question
Mathematics, 20.05.2020 23:04
question
Chemistry, 20.05.2020 23:04
question
Mathematics, 20.05.2020 23:04
question
Mathematics, 20.05.2020 23:04
Questions on the website: 13722362