Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python help please write function to calculate E(y) and Var(y) Only write Python Write a function that uses independent random samples to simulate the following

Python help please write function to calculate E(y) and Var(y)

Only write Python

Write a function that uses independent random samples to simulate the following approximate counting formulas. Number the samples randomly 1 through n.

Y = the number of subsets that test positive. p = probability of infection

I wrote function to make n and k. please look at the code for n and k. It's given already

Now Just write below formula only E(y) and Var(y) in python for calculating variance and estimate

Again only calculate E(y) and Var(y)image text in transcribed

image text in transcribed

Eimport sys #syamadulantamextractucansalamarguments from random import shuffle # random module to use shuffle method Ewith open('output.txt'a'w') as f: # open a file in the same directory in writing mode n = int(sys.argv[1]) # first argument n k = int(sys.argv[2]) #second argumentuk num_lines = int(sys.argv[3]) #third argument total number of lines to write data = ['0']*(n-k) + ['1']*k # create a initial list of n bits with k bits set for i in range(num_lines): # run a loop till num_lines shuffle(data) # shuffle the list f.write(''.join(data) + ' ') #print the listubxmconvertinguintomamstring #and add newline character i E[Y] = Ep; where p; = 1 ("+T6/23/) E[2'] = [](1 + p;) i E[4'] = [](1 + 3p;) Var(2%) = E[4'] - (E[2'])? i Eimport sys #syamadulantamextractucansalamarguments from random import shuffle # random module to use shuffle method Ewith open('output.txt'a'w') as f: # open a file in the same directory in writing mode n = int(sys.argv[1]) # first argument n k = int(sys.argv[2]) #second argumentuk num_lines = int(sys.argv[3]) #third argument total number of lines to write data = ['0']*(n-k) + ['1']*k # create a initial list of n bits with k bits set for i in range(num_lines): # run a loop till num_lines shuffle(data) # shuffle the list f.write(''.join(data) + ' ') #print the listubxmconvertinguintomamstring #and add newline character i E[Y] = Ep; where p; = 1 ("+T6/23/) E[2'] = [](1 + p;) i E[4'] = [](1 + 3p;) Var(2%) = E[4'] - (E[2'])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

What key control concept was missing at Argus Productions?

Answered: 1 week ago

Question

What is Working Capital ? Explain its types.

Answered: 1 week ago