Chapter 23 : Statistical Methods¶

Example 23.1, page no. 618¶

In [65]:
import numpy

A = numpy.zeros([3,8])
print "The first row of A denotes the no. of students falling in the marks group starting from (5 −10)... till (40−45)"
A[0] = [5,6,15,10,5,4,2,2]
print "the second row denotes cumulative frequency (less than)"
A[1,0] = 5
for i in range(1,8):
A[1,i] = A[1,i-1]+A[0,i]
print "the third row denotes cumulative frequency(more than)"
A[2,0] = 49
for i in range (1,8):
A[2,i] = A[2,i-1]-A[0,i-1]
print A

The first row of A denotes the no. of students falling in the marks group starting from (5 −10)... till (40−45)
the second row denotes cumulative frequency (less than)
the third row denotes cumulative frequency(more than)
[[  5.   6.  15.  10.   5.   4.   2.   2.]
[  5.  11.  26.  36.  41.  45.  47.  49.]
[ 49.  44.  38.  23.  13.   8.   4.   2.]]


Example 23.2, page no. 619¶

In [63]:
import numpy

A = numpy.zeros([5,16])
print "The first row of A represents the mid values of weekly earnings having interval of 2 in each class=x "
A[0] = [11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41]
print "The second row denotes the no. of employees or in other words frequency=f "
A[1]=[3,6,10,15,24,42,75,90,79,55,36,26,19,13,9,7]
print "Third row denotes f∗x"
for i in range(0,16):
A[2,i] = A[0,i]*A[1,i]
print "Fourth row denotes u=(x−25)/2 "
for i in range(0,16):
A[3,i] = (A[0,i]-25)/2
print "Fifth row denotes f∗x"
for i in range(0,16):
A[4,i] = A[3,i]*A[1,i]
print A
b = 0
print "Sum of all elements of third row=",
for i in range(0,16):
b = b+A[2,i]
print b
f = 0
print "Sum of all elements of second row=",
for i in range(0,16):
f = f+A[1,i]
print f
print "mean=",b/f
d = 0
print "Sum of all elements of fifth row= ",
for i in range(0,16):
d = d+A[4,i]
print d
print "mean by step deviation method= ",25+(2*d/f)

The first row of A represents the mid values of weekly earnings having interval of 2 in each class=x
The second row denotes the no. of employees or in other words frequency=f
Third row denotes f∗x
Fourth row denotes u=(x−25)/2
Fifth row denotes f∗x
[[  1.10000000e+01   1.30000000e+01   1.50000000e+01   1.70000000e+01
1.90000000e+01   2.10000000e+01   2.30000000e+01   2.50000000e+01
2.70000000e+01   2.90000000e+01   3.10000000e+01   3.30000000e+01
3.50000000e+01   3.70000000e+01   3.90000000e+01   4.10000000e+01]
[  3.00000000e+00   6.00000000e+00   1.00000000e+01   1.50000000e+01
2.40000000e+01   4.20000000e+01   7.50000000e+01   9.00000000e+01
7.90000000e+01   5.50000000e+01   3.60000000e+01   2.60000000e+01
1.90000000e+01   1.30000000e+01   9.00000000e+00   7.00000000e+00]
[  3.30000000e+01   7.80000000e+01   1.50000000e+02   2.55000000e+02
4.56000000e+02   8.82000000e+02   1.72500000e+03   2.25000000e+03
2.13300000e+03   1.59500000e+03   1.11600000e+03   8.58000000e+02
6.65000000e+02   4.81000000e+02   3.51000000e+02   2.87000000e+02]
[ -7.00000000e+00  -6.00000000e+00  -5.00000000e+00  -4.00000000e+00
-3.00000000e+00  -2.00000000e+00  -1.00000000e+00   0.00000000e+00
1.00000000e+00   2.00000000e+00   3.00000000e+00   4.00000000e+00
5.00000000e+00   6.00000000e+00   7.00000000e+00   8.00000000e+00]
[ -2.10000000e+01  -3.60000000e+01  -5.00000000e+01  -6.00000000e+01
-7.20000000e+01  -8.40000000e+01  -7.50000000e+01   0.00000000e+00
7.90000000e+01   1.10000000e+02   1.08000000e+02   1.04000000e+02
9.50000000e+01   7.80000000e+01   6.30000000e+01   5.60000000e+01]]
Sum of all elements of third row= 13315.0
Sum of all elements of second row= 509.0
mean= 26.1591355599
Sum of all elements of fifth row=  295.0
mean by step deviation method=  26.1591355599


Example 23.3, page no. 620¶

In [47]:
import numpy

A = numpy.zeros([3,8])
print "The first row of A denotes the no. of students falling in the marks group startin from (5−10)... till (40−45)"

A[0] = [5,6,15,10,5,4,2,2]
print "The second row denotes cumulative frequency (less than)"
A[1]=[5,11,26,36,41,45,47,49]
print "The third row denotes cumulative frequency (more than)"
A[2] = [49,44,38,23,13,8,4,2]
print A
print "Median falls in the class (15−20)=l+((n/2−c)∗h)/f= ",15+((49/2-11)*5)/15
print "Lower quartile also falls in the class (15−20)="
Q1 = 15+((49/4-11)*5)/15
print "Upper quartile also falls in the class (25−30)="
Q3 =25+((3*49/4-36)*5)/5
print "Semiinter quartile range= ",(Q3-Q1)/2

The first row of A denotes the no. of students falling in the marks group startin from (5−10)... till (40−45)
The second row denotes cumulative frequency (less than)
The third row denotes cumulative frequency (more than)
[[  5.   6.  15.  10.   5.   4.   2.   2.]
[  5.  11.  26.  36.  41.  45.  47.  49.]
[ 49.  44.  38.  23.  13.   8.   4.   2.]]
Median falls in the class (15−20)=l+((n/2−c)∗h)/f=  19
Lower quartile also falls in the class (15−20)=
Upper quartile also falls in the class (25−30)=
Semiinter quartile range=  5


Example 23.4, page no. 620¶

In [66]:
import numpy

A = numpy.zeros([3,10])
print "The first row of A denotes the roll no. of students form 1 to 10 and that of B denotes form 11 to 20 "
A[0] = [1,2,3,4,5,6,7,8,9,10]
B[0] = [11,12,13,14,15,16,17,18,19,20]
print "The second row of A and B denotes the corresponding marks in physics"
A[1] = [53,54,52,32,30,60,47,46,35,28]
B[1] = [25,42,33,48,72,51,45,33,65,29]
print "The third row denotes the corresponding marks in chemistry"
A[2] = [58,55,25,32,26,85,44,80,33,72]
B[2] = [10,42,15,46,50,64,39,38,30,36]
print "Median marks in physics=arithmetic mean of 10th and 11th student = ",(28+25)/2
print "Median marks in chemistry=arithmetic mean of 10th and 11th student = ",(72+10)/2

The first row of A denotes the roll no. of students form 1 to 10 and that of B denotes form 11 to 20
The second row of A and B denotes the corresponding marks in physics
The third row denotes the corresponding marks in chemistry
Median marks in physics=arithmetic mean of 10th and 11th student =  26
Median marks in chemistry=arithmetic mean of 10th and 11th student =  41


Example 23.5, page no. 621¶

In [9]:
print "Let the misssing frequencies be f1 and f2 "
print "Sum of given frequencies=12+30+65+25+18 = ",
c =12+30+65+25+18
print c
print "So, f1+f2=229−c = ",229-c
print "Median=46=40+(114.5−(12+30+f1))∗10/65)"
print "f1=33.5=34 "
f1 = 34
f2 = 45

Let the misssing frequencies be f1 and f2
Sum of given frequencies=12+30+65+25+18 =  150
So, f1+f2=229−c =  79
Median=46=40+(114.5−(12+30+f1))∗10/65)
f1=33.5=34


Example 23.6, page no. 622¶

In [10]:
import sympy

s = sympy.Symbol('s')
print "Let the eqidistance be s, then"
t1 = s/30
t2 = s/40
t3 = s/50
print "Average speed = total distance/total time taken",3*s/(t1+t2+t3)

Let the eqidistance be s, then
Average speed = total distance/total time taken 1800/47


Example 23.7, page no. 623¶

In [68]:
import numpy

A = numpy.zeros([5,7])
print "The first row denotes the size of item "
A[0,:] = [6,7,8,9,10,11,12]
print "The second row denotes the corresponding frequency(f)"
A[1,:] = [3,6,9,13,8,5,4]
print "The third row denotes the corresponding deviation(d)"
A[2,:] = [-3,-2,-1,0,1,2,3]
print "The fourth row denotes the corresponding f∗d "
for i in range(0,7):
A[3,i] = A[1,i]*A[2,i]
print "The fifth row denotes the corresponding f∗dˆ2 "
for i in range(0,7):
A[4,i] = A[1,i]*(A[2,i]**2)
print A
b = 0
print "Sum of fourth row elements= ",
for i in range(0,7):
b = b+A[3,i]
print b
c = 0
print "Sum of fifth row elements= ",
for i in range(0,7):
c = c+A[4,i]
print c
d = 0
print "Sum of all frequencies = ",
for i in range(0,7):
d = d+A[1,i]
print d
print "mean=9+b/d = ",9+b/d
print "Standard deviation = (c/d)ˆ0.5 = ",(c/d)**0.5

The first row denotes the size of item
The second row denotes the corresponding frequency(f)
The third row denotes the corresponding deviation(d)
The fourth row denotes the corresponding f∗d
The fifth row denotes the corresponding f∗dˆ2
[[  6.   7.   8.   9.  10.  11.  12.]
[  3.   6.   9.  13.   8.   5.   4.]
[ -3.  -2.  -1.   0.   1.   2.   3.]
[ -9. -12.  -9.   0.   8.  10.  12.]
[ 27.  24.   9.   0.   8.  20.  36.]]
Sum of fourth row elements=  0.0
Sum of fifth row elements=  124.0
Sum of all frequencies =  48.0
mean=9+b/d =  9.0
Standard deviation = (c/d)ˆ0.5 =  1.60727512683


Example 23.8, page no. 624¶

In [70]:
import numpy

A = numpy.zeros([6,9])
print "The first row of A represents the mid values of wage classes having interval of 8 in each class=x "
A[0] = [8.5,16.5,24.5,32.5,40.5,48.5,56.5,64.5,72.5]
print "The second row denotes the no. of men or in other words frequency=f "
A[1] = [2,24,21,18,5,3,5,8,2]
print "Third row denotes f∗x "
for i in range(0,9):
A[2,i] = A[0,i]*A[1,i]
print "Fourth row denotes d=(x−32.5)/8 "
for i in range(0,9):
A[3,i] = (A[0,i]-32.5)/8
print "Fifth row denotes f∗d "
for i in range(0,9):
A[4,i] = A[3,i]*A[1,i]
print "Sixth row denotes f∗(dˆ2)"
for i in range(0,9):
A[5,i] = A[3,i]**2*A[1,i]
print A
b = 0
print "Sum of all elements of sixth row= ",
for i in range(0,9):
b = b+A[5,i]
print b
f = 0
print "Sum of all elements of second row= ",
for i in range(0,9):
f = f+A[1,i]
print f
print "mean= ",b/f
d = 0
print "Sum of all elements of fifth row= ",
for i in range(0,9):
d = d+A[4,i]
print "Mean wage= ",32.5+(8*d/f)
print "standard deviation= ",8*(b/f-(d/f)**2)

The first row of A represents the mid values of wage classes having interval of 8 in each class=x
The second row denotes the no. of men or in other words frequency=f
Third row denotes f∗x
Fourth row denotes d=(x−32.5)/8
Fifth row denotes f∗d
Sixth row denotes f∗(dˆ2)
[[   8.5   16.5   24.5   32.5   40.5   48.5   56.5   64.5   72.5]
[   2.    24.    21.    18.     5.     3.     5.     8.     2. ]
[  17.   396.   514.5  585.   202.5  145.5  282.5  516.   145. ]
[  -3.    -2.    -1.     0.     1.     2.     3.     4.     5. ]
[  -6.   -48.   -21.     0.     5.     6.    15.    32.    10. ]
[  18.    96.    21.     0.     5.    12.    45.   128.    50. ]]
Sum of all elements of sixth row=  375.0
Sum of all elements of second row=  88.0
mean=  4.26136363636
Sum of all elements of fifth row=  Mean wage=  31.8636363636
standard deviation=  34.0402892562


Example 23.9, page no. 626¶

In [72]:
import numpy

A = numpy.zeros([3,10])
B = numpy.zeros([3,10])
print "The first row of A denotes the scores of A and that of B denotes that of B "
A[0] = [12,115,6,73,7,19,119,36,84,29]
B[0] = [47,12,16,42,4,51,37,48,13,0]
print "The second row of A and B denotes the corresponding deviation "
for i in range (0,10):
A[1,i] = A[0,i]-51
B[1,i] = B[0,i]-51
print "The third row of A and B denotes the corresponding deviation square "
for i in range (0,10):
A[2,i] = A[1,i]**2
B[2,i] = B[1,i]**2
print A
print B
b = 0
print "Sum of second row elements of  A=b=",
for i in range (0,10):
b = b+A[1,i]
print b
c = 0
print "sum of second row elements of B=c=",
for i in range (0,10):
c = c+B[1,i]
print c
d = 0
print "Sum of third row elements of A=d=",
for i in range (0,10):
d = d+A[2,i]
print d
e = 0
print "Sum of second row elements of B=e=",
for i in range (0,10):
e = e+B[2,i]
print e
print "Arithmetic mean of A= ",
f = 51+b/10
print f
print "Standard deviation of A= ",
g = (d/10-(b/10)**2)**0.5
print g
print "Arithmetic mean of B= ",
h = 51+c/10
print h
print "Standard deviation of A= ",
i = (e/10-(c/10)**2)**0.5
print i
print "Coefficient of variation of A=",(g/f)*100
print "Coefficient of variation of B=",(i/h)*100

The first row of A denotes the scores of A and that of B denotes that of B
The second row of A and B denotes the corresponding deviation
The third row of A and B denotes the corresponding deviation square
[[   12.   115.     6.    73.     7.    19.   119.    36.    84.    29.]
[  -39.    64.   -45.    22.   -44.   -32.    68.   -15.    33.   -22.]
[ 1521.  4096.  2025.   484.  1936.  1024.  4624.   225.  1089.   484.]]
[[   47.    12.    16.    42.     4.    51.    37.    48.    13.     0.]
[   -4.   -39.   -35.    -9.   -47.     0.   -14.    -3.   -38.   -51.]
[   16.  1521.  1225.    81.  2209.     0.   196.     9.  1444.  2601.]]
Sum of second row elements of  A=b= -10.0
sum of second row elements of B=c= -240.0
Sum of third row elements of A=d= 17508.0
Sum of second row elements of B=e= 9302.0
Arithmetic mean of A=  50.0
Standard deviation of A=  41.8306108012
Arithmetic mean of B=  27.0
Standard deviation of A=  18.8202019118
Coefficient of variation of A= 83.6612216024
Coefficient of variation of B= 69.7044515251


Example 23.10, page no. 628¶

In [14]:
print "If m is the mean of entire data, then"
m = (50*113+60*120+90*115)/(50+60+90)
print m
print "If s is the standard deviation of entire data, then "
s = (((50*6**2)+(60*7**2)+(90*8**2)+(50*3**2)+(60*4**2)+(90*1**2))/200)**0.5
print s

If m is the mean of entire data, then
116
If s is the standard deviation of entire data, then
7.74596669241


Example 23.12, page no. 629¶

In [73]:
import numpy

A = numpy.zeros([2,8])
print "The first row of A denotes the no. of persons falling in the weight group starting from (70−80)... till (140−150)"
A[0] = [12,18,35,42,50,45,20,8]
print "The second row denotes cumulative frequency"
A[1,0] = 12
for i in range(1,8):
A[1,i] = A[1,i-1]+A[0,i]
print "Median falls in the class (110−120) = l+((n/2−c)∗h)/f= ",
Q2 = 110+(8*10)/50
print Q2
print "Lower quartile also falls in the class (90−100)= ",
Q1 = 90+(57.5-30)*10/35
print Q1
print "Upper quartile also falls in the class (120−130)= ",
Q3 = 120+(172.5-157)*10/45
print Q3
print "Quartile coefficient of skewness= ",(Q1+Q3-2*Q2)/(Q3-Q1)

The first row of A denotes the no. of persons falling in the weight group starting from (70−80)... till (140−150)
The second row denotes cumulative frequency
Median falls in the class (110−120) = l+((n/2−c)∗h)/f=  111
Lower quartile also falls in the class (90−100)=  97.8571428571
Upper quartile also falls in the class (120−130)=  123.444444444
Quartile coefficient of skewness=  -0.0272952853598


Example 23.13, page no. 631¶

In [76]:
import numpy

A = numpy.zeros([7,10])
print "The first row of A denotes the corresponding I.R. of students "
A[0] = [105,104,102,101,100,99,98,96,93,92]
print "The second row denotes the corresponding deviation of I.R."
for i in range(0,10):
A[1,i] = A[0,i]-99
print "The third row denotes the square of corresponding deviation of I.R."
for i in range(0,10):
A[2,i] = A[1,i]**2
print "The fourth row denotes the corresponding E.R. of students "
A[3] = [101,103,100,98,95,96,104,92,97,94]
print "The fifth row denotes the corresponding deviation of E.R."
for i in range(0,10):
A[4,i] = A[3,i]-98
print "The sixth row denotes the square of corresponding deviation of E.R."
for i in range(0,10):
A[5,i] = A[4,i]**2
print "The seventh row denotes the product of the two corresponding deviations"
for i in range(0,10):
A[6,i] = A[1,i]*A[4,i]
print A
a = 0
print "The sum of elements of first row=a = ",
for i in range(0,10):
a = a+A[0,i]
print a
b = 0
print "The sum of  elements of second row=b = ",
for i in range(0,10):
b = b+A[1,i]
print b
c = 0
print "The sum of elements of third row=c = ",
for i in range(0,10):
c = c+A[2,i]
print c
d = 0
print "The sum of elements of fourth row=d = ",
for i in range(0,10):
d = d+A[3,i]
print d
e = 0
print "The sum of elements of fifth row=e = ",
for i in range(0,10):
e = e+A[4,i]
print e
f = 0
print "The sum of elements of sixth row=d = ",
for i in range(0,10):
f = f+A[5,i]
print f
g = 0
print "The sum of elements of seventh row=d = ",
for i in range(0,10):
g = g+A[6,i]
print g
print "Coefficient of correlation = ",g/(c*f)**0.5

The first row of A denotes the corresponding I.R. of students
The second row denotes the corresponding deviation of I.R.
The third row denotes the square of corresponding deviation of I.R.
The fourth row denotes the corresponding E.R. of students
The fifth row denotes the corresponding deviation of E.R.
The sixth row denotes the square of corresponding deviation of E.R.
The seventh row denotes the product of the two corresponding deviations
[[ 105.  104.  102.  101.  100.   99.   98.   96.   93.   92.]
[   6.    5.    3.    2.    1.    0.   -1.   -3.   -6.   -7.]
[  36.   25.    9.    4.    1.    0.    1.    9.   36.   49.]
[ 101.  103.  100.   98.   95.   96.  104.   92.   97.   94.]
[   3.    5.    2.    0.   -3.   -2.    6.   -6.   -1.   -4.]
[   9.   25.    4.    0.    9.    4.   36.   36.    1.   16.]
[  18.   25.    6.    0.   -3.   -0.   -6.   18.    6.   28.]]
The sum of elements of first row=a =  990.0
The sum of  elements of second row=b =  0.0
The sum of elements of third row=c =  170.0
The sum of elements of fourth row=d =  980.0
The sum of elements of fifth row=e =  0.0
The sum of elements of sixth row=d =  140.0
The sum of elements of seventh row=d =  92.0
Coefficient of correlation =  0.596347425668