# Variable declaration
l = [2.4,2.9,2.7,2.6,2.9,2.0,2.8,2.2,2.4,2.4,2.0,2.5] # list of lead concentration
x = [1,1,1,1,1.1,1,1,1,1.1,1.2,1.1,1]
n = 12 # sample size
# Calculation
from scipy import *
from pylab import *
%matplotlib inline
scatter(l,x)
title("DOT DIAGRAM")
xlabel("$ Lead(micro gram/l$")
Mean = sum(l)/len(l) # Mean of sample
Mean = round(Mean,3)
Variance = (sum(square(l)) - pow(sum(l),2)/ n) / (n-1) # Variance of sample
Variance = round(Variance,5)
# Result
std_err = round(sqrt(Variance / n),3) # Estimated standard error
print "Estimated standard error: ",std_err
# Variable declaration
n = 150
std_dev = 6.2 # Standard deviation
# as alpha = 0.01 , z(alpha/2) = 2.575
Z = 2.575 # Z value
# Calculation
from scipy import *
from pylab import *
E = (Z*std_dev)/sqrt(n)
E = round(E,2)
# Result
print "Maximum Error: ",E
# Variable declaration
E = 0.50 # Atmost error
std_dev = 1.6 # Standard deviation
# as alpha = 0.05 , z(alpha/2) = 1.96
Z = 1.96 # Z value
# Calculation
from scipy import *
from pylab import *
n = pow( (Z*std_dev) / E,2 ) # Sample size
n = round(n,-1)
# Result
print "Sample size: ",int(n)
# Variable declaration
n = 6 # number of observations
std_dev = 0.14 # standard deviation(in degree)
# as alpha = 0.02 , t(alpha/2) = 3.365 for v = 5
# Calculation
from scipy import *
from pylab import *
t = 3.365 # i.e. t(0.01) for v=5
std_err = (t*std_dev) / sqrt(n) # estimated standard error
std_err = round(std_err,2)
# Result
print "Maximum error: ",std_err,"degree"
# Variable declaration
n = 100 # sample size
Mean = 21.6 # sample mean
std_dev = 5.1 # standard deviation
# Calculation
from scipy import *
from pylab import *
# as alpha = 0.05 , z(alpha/2) = 1.96
Z = 1.96
y1 = Mean - Z*(std_dev / sqrt(n)) # lower limit of range
y2 = Mean + Z*(std_dev / sqrt(n)) # upper limit of range
y1 = round(y1,1)
y2 = round(y2,1)
# Result
print "95% confidence interval: (",y1,",",y2,")"
# Variable declaration
n = 50 # sample size
Mean = 305.58 # sample mean(in nm)
std_dev = 36.97 # standard deviation(in nm)
# Calculation
from scipy import *
from pylab import *
# as alpha = 0.01 , z(alpha/2) = 2.575
Z = 2.575
y1 = Mean - Z*(std_dev / sqrt(n)) # lower limit of range
y2 = Mean + Z*(std_dev / sqrt(n)) # upper limit of range
y1 = round(y1,2)
y2 = round(y2,2)
# Result
print "99% confidence interval(in nm): (",y1,",",y2,")"
# Variable declaration
n = 16 # sample size
Mean = 3.42 # sample mean
std_dev = 0.68 # standard deviation
# Calculation
from scipy import *
from pylab import *
# t(0.05) = 2.947
t = 2.947
y1 = Mean - t*(std_dev / sqrt(n)) # lower limit of range
y2 = Mean + t*(std_dev / sqrt(n)) # upper limit of range
y1 = round(y1,2)
y2 = round(y2,2)
# Result
print "99% confidence interval(in grams): (",y1,",",y2,")"
# Variable declaration
count = [7,3,1,2,4,1,2,3,1,2] # count list for 10 days
# Calculation
from scipy import *
from pylab import *
lembda = float(sum(count)) / len(count) # maximaum likelihood estimate of lembda
lembda = round(lembda,2)
# we need to find P(x=0 or x=1) using poisson distribution
p = exp(-lembda) + (exp(-lembda) * lembda) / math.factorial(1) # maximum estimated probability
p = round(p,3)
# Result
print "Maximum estimated probability: ",p
#Variable declaration
l = array([5.57,5.76,4.18,4.64,7.02,6.62,6.33,7.24,5.57,7.89,4.67,7.24,6.43,5.59,5.39])
# calculation
Mean = mean(l)
var = 0
for each in l:
var = var + (each-Mean)**2
var = var/len(l)
coff = sqrt(var)/Mean
# Results
print "Maximum likelihood estimates of Mean:",round(Mean,3)," Variance:",round(var,3)
print "Cofficient of variation:",round(coff,3)
# Variable declaration
Mean = 4.5 # mean of normal distribution
std_dev = 1.5 # standard deviation of normal distribution
n = 25 # number of vinyl specimens
x = 3.9
# Calculation
from scipy import *
from pylab import *
# corresponding to x = 3.9 , Z = (x-Mean) / (std_dev/sqrt(n))
Z = (x-Mean) / (std_dev/sqrt(n)) # Z value
Z = round(Z,0)
# from Normal Table P(Z>2.00) = 0.0228 which is same as P(Z<-2.00)
p = 0.0228 # probability P(z<-2.00)
p_val = 2*p # Required P-Value
# Result
print "P-Value: ",p_val
# Variable declaration
alpha = 0.01 # level of significance
x = 27463 # in miles
Mean = 28000 # Mean( in miles)
std_dev = 1348 # standard deviation(in miles)
n = 40 # sample size
# Calculation
from scipy import *
from pylab import *
# null hypothesis is accepted if Z< -z(alpha) and rejected if Z> -z(alpha), z(0.01) = 2.33
Z = (x-Mean) / (std_dev / sqrt(n)) # Z value corresponding to x
Z = round(Z,2)
# Result
if(Z<-2.33):
print "Null hypothesis rejected"
else:
print "Null hypothesis accepted"
# Variable declaration
alpha = 0.01 # level of significance
Mean = 180 # Mean( in pound)
n = 5 # sample size
std_dev = 5.7 # standard deviation(in pound)
x = 169.5 # in pound
# Calculation
from scipy import *
from pylab import *
# consider (1) null hypothesis if value=180 punds (2) alternative hypothesis if value < 180 pounds
t = (x-Mean) / (std_dev / sqrt(n)) # t value corresponding to x
t = round(t,2)
# Result
if(t < -3.747):
print "Null hypothesis rejected"
else:
print "Null hypothesis accepted"
print "The breaking strength is below specifications"
# Variable declaration
n = 16 # sample size
Mean = 3.42 # sample mean
std_dev = 0.68 # standard deviation
# Calculation
from scipy import *
from pylab import *
# t(0.025) = 2.131
t = 2.131
y1 = Mean - t*(std_dev / sqrt(n)) # lower limit of range
y2 = Mean + t*(std_dev / sqrt(n)) # upper limit of range
y1 = round(y1,2)
y2 = round(y2,2)
# Result
print "95% confidence interval(in grams): (",y1,",",y2,")"
# Variable declaration
n = 15 # sample size
Mean1 = 75.20 # sample mean
Mean2 = 77 # sample mean
std_dev = 3.6 # standard deviation
# Calculation
from scipy import *
from pylab import *
# z(0.05) = 1.645
Z = 1.645
y1 = Z + sqrt(n)*((Mean1-Mean2) / std_dev) # lower limit of range
y1 = round(y1,3)
# probability corresponding to Z>y1 is 0.614
p = 0.614 # P(Z > -0.219) = 0.614
prob = 1 - p
# Result
print "Type-2 error probability: ",prob
# Variable declaration
n = 30 # sample size
Mean1 = 2.000 # sample mean
Mean2 = 2.010 # sample mean
std_dev = 0.050 # standard deviation
# Calculation
from scipy import *
from pylab import *
# z(0.025) = 1.96
Z = 1.96
y1 = -Z + sqrt(n)*((Mean1-Mean2) / std_dev)
y2 = Z + sqrt(n)*((Mean1-Mean2) / std_dev)
# probability corresponding to Z>y1 is 0.614
p1 = 0.0015 # P(Z < Y1) = 0.001
p2 = 0.1945 # P(Z > Y2) = 0.194
p = p1 + p2
prob = 1 - p
# Result
print "Type-2 error probability: ",prob
# Variable declaration
alpha = 0.05
beta = 0.10
Mean1 = 20 # mean corresponding to alpha
Mean2 = 21 # mean corresponding to beta
std_dev = 2.4 # standard deviation
# Calculation
from scipy import *
from pylab import *
Z1 = 1.645 # Z value corresponding to alpha=0.05
Z2 = 1.280 # Z value corresponding to beta=0.10
Size = pow( (std_dev*(Z1 + Z2))/(Mean1 - Mean2) ,2) # Minimum sample size
Size = round(Size,-1)
# Result
print "Required sample size: ",int(Size)