Question: Binomial distributions If we havea binomial distribution(only two possible outcomes such as heads/tails 0/1 yeso true/false ) with n trials and probability of success p
Binomial distributions
If we havea binomial distribution(only two possible outcomes such as heads/tails 0/1 yeso true/false ) with n trials and probability of success p on each trial, then:
The mean (average) is

The variance is

The standard deviation (SD) equals the square root of the variance

For example, suppose you flip a fair coin n = 100 times and we want to determine the number of heads; we have a binomial distribution with n = 100 and p = 0.50. The mean is
= n*p = 100*.50 = 50 heads
(which makes sense, because if you flip a coin 100 times, you would expect to get 50 heads). The variance is
=100 (.50)(1-.50)=25
and the standard deviation (SD) is the square root of the variance, which is 5. That means when you flip a coin n = 100 times, and do that over and over, the average number of heads youll get is 50, and you can expect that to vary by about 5 heads on average.So you could expect sd= 50 5 heads or between 45 and 55 heads if you tossed a fair coin 100 times (A) So it would be unusual to see 40 or 62 heads
#ASSIGNMENT
(+25) Write a python program per the following specifications:
Populate an array(list) of size 50randomly with only integers 0 and 1
Repeat step1 n = 1000 times using either a while loop or a for loop
At this point you should have a total of 50000 observations
Display the number of 0s
Display the number of 1s
Using the Binomial distribution formulas
Display the expected mean of the 1s
Calculate and display the standard deviation (SD)
Answer the question : is the total number of 1s from 4 above. within the mean SD see (A) above
import random # Initialize array myArray = [] a = 0 b = 1 size = 25 j = 0 n =10 # Populate array with size = 25 random integers in the range 0 - 1 #and repeat for n times while (j for kin range(size): randNum = random.randint(a,b) myArray.insert(k, randNum) j = j + 1 # Display array size print("size of my array is :", len(myArray)) # printmyArray 10 values per line k = 0 sub = [] while (k
print("the mean number of 1's is within mean +- sd ??? YES/NO ")
# need to answer this
# compare the number of 1s (variable zeros calculated above
# to see if it is within the range mean sd.
OUTPUT of the sample code
size of my array is : 250
... 0 [0, 1, 0, 0, 0, 0, 0, 1, 1, 1]
... 10 [0, 1, 1, 1, 0, 1, 1, 1, 1, 0]
... 20 [0, 0, 0, 1, 1, 0, 0, 0, 1, 1]
... 30 [1, 1, 1, 1, 1, 1, 0, 0, 1, 0]
... 40 [1, 0, 1, 1, 1, 0, 0, 1, 0, 0]
... 50 [0, 0, 1, 1, 0, 1, 1, 1, 1, 0]
... 60 [1, 0, 0, 0, 1, 0, 0, 0, 0, 1]
... 70 [1, 1, 0, 1, 1, 0, 1, 1, 0, 0]
... 80 [0, 0, 0, 0, 1, 1, 1, 1, 0, 0]
... 90 [1, 1, 1, 0, 0, 1, 1, 0, 0, 1]
... 100 [0, 1, 1, 0, 0, 1, 1, 0, 1, 0]
... 110 [1, 1, 0, 0, 1, 0, 1, 0, 0, 0]
... 120 [1, 0, 0, 0, 0, 0, 0, 1, 1, 1]
... 130 [0, 1, 0, 0, 1, 1, 0, 1, 1, 1]
... 140 [1, 0, 0, 0, 1, 0, 0, 1, 0, 0]
... 150 [0, 0, 1, 1, 0, 1, 0, 1, 1, 1]
... 160 [0, 1, 1, 1, 0, 1, 0, 1, 1, 0]
... 170 [1, 1, 0, 1, 1, 1, 1, 0, 1, 0]
... 180 [0, 1, 1, 1, 0, 1, 0, 0, 0, 1]
... 190 [1, 1, 1, 1, 0, 0, 1, 1, 0, 1]
... 200 [0, 1, 1, 1, 1, 0, 0, 0, 1, 1]
... 210 [1, 0, 1, 1, 1, 1, 1, 0, 0, 0]
... 220 [1, 1, 0, 0, 1, 0, 1, 1, 0, 1]
... 230 [0, 0, 1, 1, 1, 1, 0, 0, 1, 0]
... 240 [1, 0, 0, 1, 1, 0, 1, 0, 1, 0]
number of 1 is: 33
number of 0 is: -8
=====================
mean of My Array: 100 sd (standard deviation: 5
mean +-sd: 105 95
the mean number of 1's is within mean +- sd ???
ED
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
