In [1]:

```
print "Suppose the coin is unbiased"
print "Then probability of getting the head in a toss = 1/2 "
print "Then, expected no. of successes = a = 1/2∗400"
a = 1/2*400
print "Observed no. of successes = 216"
b = 216
print "The excess of observed value over expected value = ",b-a
print "S. D. of simple sampling = (n∗p∗q)ˆ0.5 = c "
c = (400*0.5*0.5)**0.5
print "Hence, z = (b−a)/c = ",(b-a)/c
print "As z<1.96, the hypothesis is accepted at 5% level of significance"
```

In [2]:

```
print "Suppose the die is unbiased "
print "Then probability of getting 5 or 6 with one die=1/3 "
print "Then, expected no. of successes = a = 1/3∗9000 "
a = 1./3*9000
print "Observed no. of successes = 3240"
b = 3240
print "The excess of observed value over expected value = ",b-a
print "S. D. of simple sampling = (n∗p∗q)ˆ0.5=c"
c = (9000*(1./3)*(2./3))**0.5
print "Hence, z = (b−a)/c = ",(b-a)/c
print "As z>2.58, the hypothesis has to be rejected at 1% level of significance"
```

In [3]:

```
p = 206./840
print "q = 1−p "
q = 1-p
n = 840
print "Standard error of the population of families having a monthly income of rs. 250 or less=(p∗q/n)ˆ0.5 = ",(p*q/n)**0.5
print "Hence taking 103/420 to be the estimate of families having a monthly income of rs. 250 or less, the limits are 20% and 29% approximately"
```

In [6]:

```
n1 = 900
n2 = 1600
p1 = 20./100
p2 = 18.5/100
print "p=(n1∗p1+n2∗p2)/(n1+n2)"
p = (n1*p1+n2*p2)/(n1+n2)
print p
print "q = 1−p "
q = 1-p
print q
print "e=(p∗q∗(1/n1+1/n2))ˆ0.5"
e = (p*q*((1./n1)+(1./n2)))**0.5
print e
z = (p1-p2)/e
print "z = ",z
print "As z<1, the difference between the proportions is not significant. "
```

In [7]:

```
p1 = 0.3
p2 = 0.25
print "q1 = 1−p1 "
q1 = 1-p1
print "q2=1−p2"
q2 = 1-p2
n1 = 1200
n2 = 900
print "e=((p1∗q1/n1)+(p2*q2/n2))ˆ0.5"
e = ((p1*q1/n1)+(p2*q2/n2))**0.5
z = (p1-p2)/e
print "Hence, it is likely that real difference will be hidden."
```

In [11]:

```
print "m and n represents mean and number of objects in sample respectively "
m = 3.4
n = 900.
M = 3.25
d = 1.61
print "z=(m−M)/(d/(nˆ0.5)"
z = (m-M)/(d/(n**0.5))
print "z = ",z
print "As z>1.96, it cannot be regarded as a random sample"
```

In [12]:

```
print "m1 and n1 represents mean and no. of objects in sample 1"
print "m2 and n2 represents mean and no. of objects in sample 2"
m1 = 67.5
m2 = 68.
n1 = 1000.
n2 = 2000.
d = 2.5
print "On the hypothesis that the samples are drawn from the same population of d = 2.5, we get"
z = (m1-m2)/(d*((1/n1)+(1/n2))**0.5)
print "z = ",z
print "Since |z|>1.96, thus samples cannot be regarded as drawn from the same population"
```

In [13]:

```
print "m1, d1 and n1 denotes mean, deviation and no.of objects in first sample "
m1 = 67.85
d1 = 2.56
n1 = 6400.
print "m2, d2 and n2 denotes mean, deviation and no.of objects in second sample"
m2 = 68.55
d2 = 2.52
n2 = 1600.
print "S. E. of the difference of the mean heights is ",
e = ((d**2/n1)+(d2**2/n2))**0.5
print e
print m1-m2
print "|m1−m2|>10e, this is highly significant. hence, the data indicates that the sailors are on the average taller than the soldiers."
```

In [18]:

```
import numpy
A = numpy.zeros((3,9))
n = 9
print "First of row denotes the different values of sample "
A[0,:] = [45,47,50,52,48,47,49,53,51]
print "The second row denotes the corresponding deviation"
for i in range(0,9):
A[1,i] = A[0,i]-48
print "The third row denotes the corresponding square of deviation"
for i in range(0,9):
A[2,i] = A[1,i]**2
print "The sum of second row elements = ",
a =0
for i in range(0,9):
a = a+A[1,i]
print a
print "The sum of third row elements = ",
b = 0
for i in range(0,9):
b = b+A[2,i]
print b
print "let m be the mean "
m = 48+a/n
print "let d be the standard deviation"
d = ((b/n)-(a/n)**2)**0.5
t = (m-47.5)*(n-1)**0.5/d
print t
```

In [19]:

```
print "d and n represents the deviation and no. objects in given sample"
n = 10.
d = 0.04
m = 0.742
M = 0.700
print "Taking the hypothesis that the product is not inferior i.e. there is no significant difference between m and M"
t = (m-M)*(n-1)**0.5/d
print t
print "Degrees of freedom= "
f = n-1
print f
```

In [21]:

```
import numpy
A = numpy.zeros((6,11))
n = 11
print "The first row denotes the boy no. "
A[0,:] = [1,2,3,4,5,6,7,8,9,10,11]
print "The second row denotes the marks in test I(x1)"
A[1,:] = [23,20,19,21,18,20,18,17,23,16,19]
print "The third row denotes the marks in test I(x2)"
A[2,:] = [24,19,22,18,20,22,20,20,23,20,17]
print "The fourth row denotes the difference of marks in two tests(d)"
for i in range (0,11):
A[3,i] = A[2,i]-A[1,i]
print "The fifth row denotes the (d−1)"
for i in range (0,11):
A[4,i] = A[3,i]-1
print "The sixth row denotes the square of elements of fourth row "
for i in range(0,11):
A[5,i] = A[3,i]**2
print A
a = 0
print "The sum of elements of fourth row="
for i in range(0,11):
a = a+A[3,i]
print a
b = 0
print "The sum of elements of sixth row= "
for i in range(0,11):
b = b + A[5,i]
print b
print "Standard deviation"
d = (b/(n-1))**0.5
t = (1-0)*(n)**0.5/2.24
print "d = ",d
print "t = ",t
```