1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
solmaris [256]
3 years ago
15

Median of a sample If the distribution is given, as above, the median can be determined easily. In this problem we will learn ho

w 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?

Computers and Technology
1 answer:
kumpel [21]3 years ago
7 0

Answer:

def sample_median(n,P):

return np.median(np.random.choice(np.arange(1,len(P)+1),n,p=P))

Explanation:

See attached picture.

You might be interested in
1. Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the result assigned to a var
shutvik [7]

Answer:

import java.util.Scanner;

public class num6 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int product=0;

       do{

           System.out.println("Enter a number");

           int num = in.nextInt();

           product = num*10;

           System.out.println("The product is " + product);

       }while (product<100);

  }

}

Explanation:

In the Java program above, The user will be prompted to enter a number.

The number is multiplied by 10 and assigned to a variable called product.

A do....while loop has been implemented to check the variable product

As long as this variable is less than 10, the user will be prompted to enter another number.

3 0
3 years ago
A program to add two numbers in C++
Paladinen [302]
I don't know if i understood correctly, but C++ can add numbers by using the + funciton. You could either use:
a = b + c
or
a = a + b
if you want to increment a variable.
7 0
3 years ago
​_______ consists of the analysis​ tools, technologies, and processes by which marketers dig out meaningful patterns in big data
Salsk061 [2.6K]
I think it's value chain analysis.
7 0
3 years ago
Microsoft words spell checker
Virty [35]
To check spelling<span> in a </span>Word<span> document, open up the document, head to the “Review” tab, then click on “</span>Spelling<span> & Grammar” (part of the “Proofing” group of tools). 

</span>
4 0
3 years ago
What are three subject areas that are key to successfully working in the field of robotics
Novosadov [1.4K]

The brain ( computer science engineering)

The nervous system ( electrical engineering)

The body ( Mechanical engineering). The mechanical engineer is in the charge of the physical system that makes up the robot.

4 0
3 years ago
Other questions:
  • Select the correct statement about data preparation.
    10·1 answer
  • Tristan has successfully deleted the blank row. The next thing he wants to do is to increase the length of the first column. A 2
    13·2 answers
  • Why is it important to open the Map Custom Fields dialog box before importing/exporting a list of contacts? Check all that apply
    6·2 answers
  • The media literacy movement hopes to _____.
    15·2 answers
  • To insure QoS of a network, an alternative to “prioritizing traffic” is to __________, which means holding back traffic from non
    8·1 answer
  • Write a program using integers userNum and divNum as input, and output userNum divided by divNum three times.
    7·1 answer
  • Directions and Analysis
    15·1 answer
  • The National Vulnerability Database (NVD) is responsible for actively performing vulnerability testing for every company's softw
    8·1 answer
  • Which tags do you use to write the header and items of an ordered list on a web page?
    14·1 answer
  • Who benefits the most from billing by the second for cloud resources, such as virtual machines?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!