# Variable declaration
from scipy import *
from pylab import *
data = array([[45,204.4,13825.3],[55,130.0,8632.0]])
size = data[0:2,0]
Mean = data[0:2,1]
variance = data[0:2,2]
alpha = 0.05 # level of significance
Z = 1.96 # z value corresponding to alpha/2
# Calculation
y1 = (Mean[0] - Mean[1]) - ( Z* (sqrt( variance[0]/size[0] + variance[1]/size[1] )) ) # Lower limit
y2 = (Mean[0] - Mean[1]) + ( Z* (sqrt( float(variance[0])/size[0] + float(variance[1])/size[1] )) ) # upper limit
y1 = round(y1,2)
y2 = round(y2,2)
# Result
print "95% confidence interval(in kWh per month): (",y1,",",y2,")"
# Variable declaration
from scipy import *
from pylab import *
Mean = array([0.136,0.083])
size = array([32,32])
variance = array([0.004,0.005])
alpha = 0.05 # level of significance
# Calculation
Z = (Mean[0] - Mean[1] - alpha)/(sqrt( variance[0]**2/size[0] + variance[1]**2/size[1] )) # Lower limit
Z = round(Z,2)
# Result
if(Z>1.645):
print "Null hypothesis rejected"
print "The data substantiate the claim"
else:
print "Null hypothesis accepted"
print "The data does not substantiate the claim"
# Variable declaration
alpha = 0.05 #level of significance
n1 = 40 # size of sample-1
n2 = 40 # size of sample-2
std_dev1 = 27 # standard deviation-1
std_dev2 = 31 # standard deviation-2
Mean1 = 1647 # Mean of sample-1 ( in hours)
Mean2 = 1638 # Mean of sample-2 ( in hours)
# Calculation
from scipy import *
from pylab import *
# null hypothesis accepted if z>1.645 else rejected
Z = (Mean1 - Mean2) / (sqrt( square(std_dev1)/float(n1) + square(std_dev2)/float(n2) )) # Z value
Z = round(Z,2)
# Result
if(Z>1.645):
print "Null hypothesis rejected"
print "observed difference between two samples is significant"
else:
print "Null hypothesis accepted"
print "observed difference between two samples is not significant"
# Variable declaration
alpha = 0.05 #level of significance
n1 = 40 # size of sample-1
n2 = 40 # size of sample-2
std_dev1 = 27 # standard deviation-1
std_dev2 = 31 # standard deviation-2
Mean1 = 1647 # Mean of sample-1 ( in hours)
Mean2 = 1638 # Mean of sample-2 ( in hours)
delta1 = 0
delta2 = 16 # in hours
# Calculation
from scipy import *
from pylab import *
std_dev = sqrt( square(std_dev1) + square(std_dev2) )
Z = 1.645 # at alpha = 0.05
Z1 = Z + sqrt(n1)*( (delta1 - delta2)/std_dev )
Z1 = round(Z1,3)
# Probability of Z > -0.817 =0.793
err_prob = 1 - 0.793 # type-2 error probability
# Result
print "type-2 error probability: ",err_prob
# Variable declaration
from scipy import *
from pylab import *
val1 = 0
val2 = 0
Mine1 = array([8260,8130,8350,8070,8340])
Mine2 = array([7950,7890,7900,8140,7920,7840])
alpha = 0.01 # level of significance
deg = len(Mine1) + len(Mine2) - 2 # Degree of freedom
Mean1 = sum(Mine1)/len(Mine1)
Mean2 = sum(Mine2)/len(Mine2)
# Calculation
for each in Mine1:
val1 = val1 + (Mean1-each)**2
for each in Mine2:
val2 = val2 + (Mean2-each)**2
var = (val1 + val2)/(len(Mine1)-1 + len(Mine2)-1)
std_dev = sqrt(var)
t = (Mean1 - Mean2)/(std_dev*(sqrt(1.0/len(Mine1) + 1.0/len(Mine2))))
# Result
if(t>3.250):
print "Null hypothesis rejected"
print "Average heat producing capacity is not same"
else:
print "Null hypothesis accepted"
print "Average heat producing capacity is same"
# Variable declaration
f1 = [] #list for sample-1
f2 = [] #list for sample-2
n1 = 58 # sample-1 size
n2 = 27 # sample-2 size
t = 1.99 # t value corresponding to alpha/2
# Calculation
from scipy import *
from pylab import *
f1 = array([66.4,67.7,68.0,68.0,68.3,68.4,68.6,68.8,68.9,
69.0,69.1,69.2,69.3,69.3,69.5,69.5,69.6,69.7,69.8,69.8,69.9,
70.0,70.0,70.1,70.2,70.3,70.3,70.4,70.5,70.6,70.6,70.8,70.9,
71.0,71.1,71.2,71.3,71.3,71.5,71.6,71.6,71.7,71.8,71.8,71.9,
72.1,72.2,72.3,72.4,72.6,72.7,72.9,
73.1,73.3,73.5,
74.2,74.5,
75.3])
Mean1 = mean(f1)
Mean1 = round(Mean1,2)
std_dev1 = std(f1)
std_dev1 = round(std_dev1,1)
f2 = array([71.2,71.8,72.6,72.8,73.4,73.7,73.9,74.4,74.9,75.5,75.9,
76.3,76.5,76.7,76.9,
77.1,77.3,77.6,77.7,77.8,
78.1,78.2,78.4,78.6,
79.0,79.3,79.8])
Mean2 = mean(f2)
Mean2 = round(Mean2,2)
std_dev2 = std(f2)
std_dev2 = round(std_dev2,1)
y1 = (Mean1 - Mean2) - t*sqrt( ( (n1-1)*pow(std_dev1,2) + (n2-1)*pow(std_dev2,2) ) / (n1+n2-2) ) * sqrt( 1.0/n1 + 1.0/n2 ) # lower limit
y1 = round(y1,1)
y2 = (Mean1 - Mean2) + t*sqrt( ( (n1-1)*pow(std_dev1,2) + (n2-1)*pow(std_dev2,2) ) / (n1+n2-2) ) * sqrt( 1.0/n1 + 1.0/n2 ) # upper limit
y2 = round(y2,1)
if abs(y1)>abs(y2):
m1=abs(y2)
m2=abs(y1)
else:
m1=abs(y1)
m2=abs(y2)
# Result
print "95% large sample confidence interval(in thousand pounds per square): (",m1,",",m2,")"
# Variable declaration
f1 = [] #list for sample-1
f2 = [] #list for sample-2
n1 = 58 # sample-1 size
n2 = 27 # sample-2 size
Z = 1.96 # Z value corresponding to alpha/2
# Calculation
from scipy import *
from pylab import *
f1 = [66.4,67.7,68.0,68.0,68.3,68.4,68.6,68.8,68.9,
69.0,69.1,69.2,69.3,69.3,69.5,69.5,69.6,69.7,
69.8,69.8,69.9,70.0,70.0,70.1,70.2,70.3,70.3,
70.4,70.5,70.6,70.6,70.8,70.9,71.0,71.1,71.2,
71.3,71.3,71.5,71.6,71.6,71.7,71.8,71.8,71.9,
72.1,72.2,72.3,72.4,72.6,72.7,72.9,73.1,73.3,
73.5,74.2,74.5,75.3]
Mean1 = mean(f1)
Mean1 = round(Mean1,2)
std_dev1 = std(f1)
std_dev1 = round(std_dev1,1)
f2 = [71.2,71.8,72.6,72.8,73.4,73.7,73.9,
74.4,74.9,75.5,75.9,76.3,76.5,76.7,
76.9,77.1,77.3,77.6,77.7,77.8,78.1,
78.2,78.4,78.6,79.0,79.3,79.8]
Mean2 = mean(f2)
Mean2 = round(Mean2,2)
std_dev2 = std(f2)
std_dev2 = round(std_dev2,1)
y1 = (Mean1 - Mean2) - Z*sqrt( pow(std_dev1,2)/n1 + pow(std_dev2,2)/n2 ) # lower limit
y1 = round(y1,2)
y1 = round(y1,1)
y2 = (Mean1 - Mean2) + Z*sqrt( pow(std_dev1,2)/n1 + pow(std_dev2,2)/n2 ) # upper limit
y2 = round(y2,1)
if abs(y1)>abs(y2):
m1=abs(y2)
m2=abs(y1)
else:
m1=abs(y1)
m2=abs(y2)
# Result
print "95% large sample confidence interval(in thousand pounds per square): (",m1,",",m2,")"
# Variable declaration
from scipy import *
from pylab import *
val1 = 0
val2 = 0
data1 = array([0.63,2.64,1.85,1.68,1.09,1.67,0.73,1.04,0.68])
data2 = array([3.71,4.09,4.11,3.75,3.49,3.27,3.72,3.49,4.26])
n1 = len(data1)
n2 = len(data2)
alpha = 0.05 # level of significance
Mean1 = sum(data1)/len(data1)
Mean2 = sum(data2)/len(data2)
# Calculation
for each in data1:
val1 = val1 + (Mean1-each)**2
for each in data2:
val2 = val2 + (Mean2-each)**2
val1 = val1/(n1-1)
val2 = val2/(n2-1)
var = (val1 + val2)/(len(Mine1)-1 + len(Mine2)-1)
deg = pow((val1/n1 + val2/n2),2)/(pow(val1/n1,2)/(n1-1) + pow(val2/n2,2)/(n2-1))
deg = round(deg,0)
t = (Mean1 - Mean2)/ sqrt( val1/n1 + val2/n2 ) # upper limit
t = round(t,2)
# Result
if(t<-2.201):
print "Null hypothesis rejected"
print "Mean product volume are different"
else:
print "Null hypothesis accepted"
print "Mean product volume are same"
# Variable declaration
from scipy import *
from pylab import *
val1 = 0
val2 = 0
data1 = array([0.63,2.64,1.85,1.68,1.09,1.67,0.73,1.04,0.68])
data2 = array([3.71,4.09,4.11,3.75,3.49,3.27,3.72,3.49,4.26])
n1 = len(data1)
n2 = len(data2)
alpha = 0.05 # level of significance
Mean1 = sum(data1)/len(data1)
Mean2 = sum(data2)/len(data2)
# Calculation
for each in data1:
val1 = val1 + (Mean1-each)**2
for each in data2:
val2 = val2 + (Mean2-each)**2
val1 = val1/(n1-1)
val2 = val2/(n2-1)
var = (val1 + val2)/(len(Mine1)-1 + len(Mine2)-1)
deg = pow((val1/n1 + val2/n2),2)/(pow(val1/n1,2)/(n1-1) + pow(val2/n2,2)/(n2-1))
deg = round(deg,0)
t = 2.201 # t-value for 11 degree of freedom
y1 = (Mean1 - Mean2 - t*(sqrt(val1/n1 + val2/n2))) # Lower limit
y2 = (Mean1 - Mean2 + t*(sqrt(val1/n1 + val2/n2))) # Lower limit
y1 = round(y1,3)
y2 = round(y2,3)
# Result
print "95% confidence interval(in gallons): (",y1,",",y2,")"
# Variable declaration
n = 10
# Calculation
from scipy import *
from pylab import *
l = array([[45,36],[73,60],[46,44],[124,119],[33,35],[57,51],[83,77],[34,29],[26,24],[17,11]])
l1 = l[:,0]
l2 = l[:,1]
diff = l1 - l2 # diffrence in values
Mean = mean(diff)
std_dev = 4.08
# null hypothesis is rejected if t > 1.833 for v = 9 degrees of freedom
t = (Mean - 0) / (std_dev / sqrt(n)) # t value
t = round(t,2)
# Result
if(t > 1.833):
print "null hypothesis is rejected"
print "Industrial safety program is effective"
else:
print "null hypothesis is accepted"
print "Industrial safety program is effective"
# Variable declaration
n = 10
# Calculation
from scipy import *
from pylab import *
l = array([[45,36],[73,60],[46,44],[124,119],[33,35],[57,51],[83,77],[34,29],[26,24],[17,11]])
l1 = l[:,0]
l2 = l[:,1]
diff = l1 - l2 # diffrence in values
Mean = mean(diff)
std_dev = 4.08
t = 1.833
y1 = (Mean - t*std_dev/sqrt(n)) # Lower limit
y2 = (Mean + t*std_dev/sqrt(n)) # Lower limit
y1 = round(y1,1)
y2 = round(y2,1)
# Result
print "95% confidence interval(in gallons): (",y1,",",y2,")"
# Variable declaration
from scipy import *
from pylab import *
%matplotlib inline
val = 0
data1 = array([27,23,64,44,30,75,26,124,54,30,14])
data2 = array([15,13,22,29,31,64,30,64,56,20,21])
y = [1,1,1,1,1,1,1,1,1,1.1,1]
d = []
alpha = 0.05 # level of significance
for i in range(0,11):
d.append(data1[i]-data2[i])
n = len(d)
Mean = sum(d)/float(len(d))
# Calculation
for each in d:
val = val + (Mean-each)**2
val = val/float(n-1)
deg = n-1
t = 2.228 # t-value for 10 degree of freedom
y1 = (Mean - t*(sqrt(val/n))) # Lower limit
y2 = (Mean + t*(sqrt(val/n))) # upper limit
y1 = round(y1,2)
y2 = round(y2,2)
# Result
print "95% confidence interval: (",y1,",",y2,")"
scatter(d,y)
title("Dot Diagram")