# Chapter 9: Inferences Concerning Variances¶

## Example, Page-269¶

In [2]:
# Variable declaration
from scipy import *
from pylab import *

val = 0
Mine1 = array([8260,8130,8350,8070,8340])

# Calculation

Mean1 = sum(Mine1)/len(Mine1)

for each in Mine1:
val = val + (Mean1-each)**2

var = (val)/(len(Mine1)-1)
std_dev = sqrt(var)

d2 = 2.326   # for n=5

est_std_dev = (max(Mine1)-min(Mine1))/d2

# Result
print "Estimated standard deviation: ",round(est_std_dev,1)
print "Actual standard deviation: ",round(std_dev,1)

Estimated standard deviation:  120.4
Actual standard deviation:  125.5


## Example, page-270¶

In [2]:
# Variable declaration
v = 19                              # degree of freedom
Variance = 1.2* pow(10,-4)          # variance

# Calculation
from scipy import *
from pylab import *

# alpha = 0.05
chi_square1 = 8.907                 # chi square value at alpha/2 from table-5
chi_square2 = 32.852                # chi square value at 1-(alpha/2) from table-5

# we need to find limits of sigma

y1 = (v*Variance) / chi_square2
y2 = (v*Variance) / chi_square1

y1 = round( sqrt(y1), 4)            #lower limit
y2 = round( sqrt(y2), 4)            #upper limit

# Result
print "95% confidence interval: (",y1," , ",y2,")"

95% confidence interval: ( 0.0083  ,  0.016 )


## Example, page-271¶

In [3]:
# Variable declaration
alpha = 0.05      # level of significance
v = 14            # degree of freedom
std_dev = 0.64    # standard deviation(in mil)
sigma = 0.5

# Calculation
from scipy import *
from pylab import *

# null hypothesis: if sigma = 0.5 , Alternative hypothesis if sigma > 0.5

chi_sq_thr = 23.685                                      # theoritical value of chi square at alpha = 0.05 with v = 14
chi_sq_prt = ( v*pow(std_dev,2) ) /pow(sigma,2)          # calculated value of chi square
chi_sq_prt = round(chi_sq_prt,2)

# Result
if(chi_sq_thr > chi_sq_prt):
print "null hypothesis can not be rejected"
print "we can not conclude that lapping process is unsatisfatory"
else:
print "null hypothesis can be rejected"
print "we can conclude that lapping process is unsatisfatory"

null hypothesis can not be rejected
we can not conclude that lapping process is unsatisfatory


## Example, page-273¶

In [4]:
# Variable declaration
v = 11            # degree of freedom
s1 = 0.035        # company-1 work yield
s2 = 0.062        # company-2 work yield
alpha = 0.05      # level of significance

# Calculation
from scipy import *
from pylab import *

# null hypothesis: if square(sigma1) = square(sigma2) , Alternative hypothesis if square(sigma1) < square(sigma2)

f_thr = 2.82                                   # theoritical value of F at alpha = 0.05 with v = 11
f_prt = square(s2) / square(s1)                # calculated value of F
f_prt = round(f_prt,2)

# Result
if(f_thr > f_prt):
print "null hypothesis can not be rejected"
print "data does not support contention"
else:
print "null hypothesis must be rejected"
print "data supports contention"

null hypothesis must be rejected
data supports contention


## Example, Page-273¶

In [5]:
# Variable declaration
alpha = 0.02      # level of significance
val1 = 0
val2 = 0

Mine1 = array([8260,8130,8350,8070,8340])
Mine2 = array([7950,7890,7900,8140,7920,7840])

# Calculation
from scipy import *
from pylab import *

Mean1 = sum(Mine1)/len(Mine1)
Mean2 = sum(Mine2)/len(Mine2)

for each in Mine1:
val1 = val1 + (Mean1-each)**2

for each in Mine2:
val2 = val2 + (Mean2-each)**2

# null hypothesis: if square(sigma1) = square(sigma2) , Alternative hypothesis if square(sigma1) < square(sigma2)
s1_square = val1/(len(Mine1)-1)
s2_square = val2/(len(Mine2)-1)

f_thr = 11.4                   # theoritical value of F at alpha = 0.02 for 4 & 5 DOF
f_prt = s1_square / float(s2_square)            # calculated value of F
f_prt = round(f_prt,2)

# Result
print "Practical F value: ",f_prt
if(f_thr > f_prt):
print "null hypothesis can not be rejected"
print "It can be assumed that variances of two populations sampled are equal."
else:
print "null hypothesis must be rejected"
print "It can not be assumed that variances of two populations sampled are equal."

Practical F value:  1.44
null hypothesis can not be rejected
It can be assumed that variances of two populations sampled are equal.


## Example, page-275¶

In [6]:
# Variable declaration
v1 = 8                    # degree of freedom of sample-1
v2 = 8                    # degree of freedom of sample-2
alpha = 0.02              # level of significance
s1_square = 0.4548        # for sample-1
s2_square = 0.1089        # for sample-2

# Calculation
from scipy import *
from pylab import *

# 98% confidence interval

f1 = 6.03                                    # f value at 0.01
f2 = 1 / 6.03                                # f value at 0.99

y1 = (f2)*(s2_square / s1_square)            # lower limit
y2 = (f1)*(s2_square / s1_square)            # upper limit

y1 = round(y1,2)
y2 = round(y2,2)

# Result
print "98% confidence interval: (",y1," , ",y2,")"

98% confidence interval: ( 0.04  ,  1.44 )