Suppose you decide to use the number of times you see any of the area codes of the places Yanay has been to in 50 spam calls as your test statistic. Question 7. Write a function called simulate_visited_area_codes that generates exactly one simulated value of your test statistic under the null hypothesis. It should take no arguments and simulate 50 area codes under the assumption that the result of each area is sampled from the range 200-999 inclusive with equal probability. Your function should return the number of times you saw any of the area codes of the places Yanay has been to in those 50 spam calls. Hint: You may find the textbook section on the sample_proportions function to be useful. For model_proportions, under the null hypothesis, what's the chance of drawing one of the area codes Yanay has recently been to

Respuesta :

Answer:

In Python:

import random

def simulate_visited_area_codes():

   area_codes = []

   for i in range(51):

       num = random.randint(200,1000)

       area_codes.append(num)

   visited_codes = [289, 657, 786, 540]

   count = 0

   for i in range(51):

       for j in range(len(visited_codes)):

           if area_codes[i] == visited_codes[j]:

               count+=1

   return count

print("Visited Areas: "+str(simulate_visited_area_codes()))

Explanation:

So many incomplete details in your question, so I will fill in the gap (i.e. make assumptions)

The assumptions are:

  • The 50 area codes is stored in area_codes list; the codes are randomly generated
  • The visited area codes is stored in visited_codes list, the list is initializes with [289, 657, 786, 540]

The program and explanation is as follows: (comments are written in bold)

#This imports the random module

import random

#This defines the function

def simulate_visited_area_codes():

#Thie initializes area_codes to an empty list

   area_codes = []

#This iterates from 1 to 50 and generate 50 random numbers to the area_codes list

   for i in range(51):

       num = random.randint(200,1000)

       area_codes.append(num)

#This initializes the visited_code

   visited_codes = [289, 657, 786, 540]

#This initializes count variable to 0

   count = 0

#This iterates through the list and looks for matching code between the area_code and the visited_code lists

   for i in range(51):

       for j in range(len(visited_codes)):

           if area_codes[i] == visited_codes[j]:

#The count variable is incremented by 1 for matching codes

               count+=1

#This returns the count

   return count

#The main begins here and prints the number of area code visited

print("Visited Areas: "+str(simulate_visited_area_codes()))

Simulate Function:

Simulate one or more responses from the distribution corresponding to a fitted model object.

The code is shown below:-

visited_test_statistics_under_null = make_array()

repetitions = 20000

for i in np.arange(repetitions):

  new_sum_of_correct_area_code = simulate_visited_area_codes()

  visited_test_statistics_under_null = np.append(visited_test_statistics_under_null, new_sum_of_correct_area_code)

visited_test_statistics_under_null( )

Learn more about the topic Simulate Function:

https://brainly.com/question/14492046

ACCESS MORE