赞
踩
一家食品生产企业以生产袋装食品为主,每天的唱片大约为8000袋。按规定每袋的重量应为100克。为对产品重量进行监测,企业质检部门经常要进行抽检,以分析每袋重量是否符合要求,现从某天生产的一批食品中随机抽取25袋,测得每袋重量如下:
import pandas as pd
import numpy as np
import scipy as sp
from scipy import stats
lst = [112.5,102.6,100,116.6,136.8,101,107.5,123.5,95.4,102.8,103,95,102,97.8,101.5,102,108.8,101.6,108.6,98.4,100.5,115.6,102.2,105,93.3]
data = pd.Series(lst)
已知产品重量服从正态分布,且总体标准差为10克,试估计该天产品平均重量的置信区间,置信水平为95%
# 已知 标准差sigma=10,样本量 n = 25, 置信水平 1-a=95%
sigma = 10
n = 25
a = 0.05
# 均值 x_bar = data.mean()
x_bar = data.mean()
计算 z a / 2 z_{a/2} za/2
z_a2 = stats.norm.isf(a/2)
z_a2
1.9599639845400545
带入公式计算:
left = x_bar - z_a2*(sigma/np.sqrt(n))
right = x_bar + z_a2*(sigma/np.sqrt(n))
left,right
(101.44007203091988, 109.27992796908009)
print('该批食品平均重量95%的置信区间为({:.3f},{:.3f})'.format(left,right))
该批食品平均重量95%的置信区间为(101.440,109.280)
一家保险公司收集到由36位投保人组成的随机样本,得到每位投保人的年龄数据如下:
lst = [23,36,42,34,39,34,35,42,53,28,49,39,39,46,45,39,38,45,27,43,54,36,34,48,36,31,47,44,48,45,44,33,24,40,50,32]
data = pd.Series(lst)
设建立投保人平均年龄的90%的置信区间
# 已知 样本量 n = 36, 置信水平 1-a=90%
sigma = 10
n = 36
a = 0.1
# 均值 x_bar = data.mean()
# 样本均值
x_bar = data.mean()
# 样本标准差 s
sigma = data.std()
计算 z a / 2 z_{a/2} za/2
z_a2 = stats.norm.isf(a/2)
z_a2
1.6448536269514729
left = x_bar - z_a2*(sigma/np.sqrt(n))
right = x_bar + z_a2*(sigma/np.sqrt(n))
left,right
投保人平均年龄的90%的置信区间为(37.369,41.631)
已知某种灯泡的寿命服从正态分布,现从一批灯泡中随机抽取16个,测得其使用寿命如下:
lst = [1510,1480,1450,1510,1480,1530,1460,1470,1520,1500,1480,1520,1490,1510,1460,1470]
data = pd.Series(lst)
试建立该灯泡平均使用寿命的95%的置信区间。
#置信度
a = 0.05
# 样本均值
x_bar = data.mean()
# 样本标准差
sigma = data.std()
# 样本量
n = 16
计算 t a / 2 t_{a/2} ta/2
t_a2 = stats.t.isf(a/2,n-1)
t_a2
2.131449545559323
left = x_bar - t_a2*(sigma/np.sqrt(n))
right = x_bar + t_a2*(sigma/np.sqrt(n))
left,right
(1476.8033606044887, 1503.1966393955113)
print('该种灯泡平均使用寿命的95%的置信区间为({:.3f},{:.3f})'.format(left,right))
该种灯泡平均使用寿命的95%的置信区间为(1476.803,1503.197)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。