9.2某车间生产滚珠,随机的抽出了50粒,测得他们的直径为(单位mm)15.0 15.8 15.2 15.1 15.9 14.7 14.8 15.5 15.6 15.3 15.1 15.3 15.0 15.6 15.7 14.8 14.5 14.2 14.9 14.9 15.2 15.0 15.3 15.6 15.1 14.9 14.2 14.6 15.8 15.2 15.9 15.2 15.0 14.9 14.8 14.5 15.1 15.5 15.5 15.1 15.1 15.0 15.3 14.7 14.5 15.5 15.0 14.7 14.6 14.2 通过计算得到样本均值为15.0780,样本标准差为0.4325,试问滚珠直径是否服从正态分布
点击查看代码
from scipy.stats import shapiro
data = [15.0, 15.8, 15.2, 15.1, 15.9, 14.7, 14.8, 15.5, 15.6, 15.3,
15.1, 15.3, 15.0, 15.6, 15.7, 14.8, 14.5, 14.2, 14.9, 14.9,
15.2, 15.0, 15.3, 15.6, 15.1, 14.9, 14.2, 14.6, 15.8, 15.2,
15.9, 15.2, 15.0, 14.9, 14.8, 14.5, 15.1, 15.5, 15.5, 15.1,
15.1, 15.0, 15.3, 14.7, 14.5, 15.5, 15.0, 14.7, 14.6, 14.2]
stat, p = shapiro(data)
print(f"Shapiro-Wilk Statistic: {stat}")
print(f"P-value: {p}")
alpha = 0.05
if p > alpha:
print("滚珠直径数据服从正态分布N(15.0780, 0.4325^2)")
else:
print("滚珠直径数据不服从正态分布N(15.0780, 0.4325^2)。")
print("学号:2023310143028")
9.3 在7个不同实验室中测量某种扑尔敏药片的扑尔敏有效含量(以mg计),得到结果如表格(读取外部表格excel文件,第一行为实验室Lab1到Lab7,每一列下面为有效含量)。画出各实验室测量结果的箱线图,设各样本分布来自正态总体N(μi,σ^2)i为μ的下标,i=1,2,...,7,各样本相互独立,试取显著水平α=0.05检验各实验室测量的扑尔敏的有效含量的
点击查看代码
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
file_path = '9.3.xlsx'
data = pd.read_excel(file_path, header=0)
labs = ['Lab1', 'Lab2', 'Lab3', 'Lab4', 'Lab5', 'Lab6', 'Lab7']
assert all(lab in data.columns for lab in labs), "Excel文件中的列名与实验室名称不匹配"
plt.figure(figsize=(12, 8))
sns.boxplot(data=data)
plt.xticks(rotation=45)
plt.title('Boxplot of Chlorpheniramine Content Measurements by Laboratory')
plt.xlabel('Laboratory')
plt.ylabel('Chlorpheniramine Content (mg)')
plt.show()
f_stat, p_value = stats.f_oneway(data['Lab1'], data['Lab2'], data['Lab3'], data['Lab4'], data['Lab5'], data['Lab6'], data['Lab7'])
print(f"F-statistic: {f_stat}")
print(f"P-value: {p_value}")
alpha = 0.05
if p_value < alpha:
print("在显著水平α=0.05下,各实验室测量的扑尔敏有效含量的均值有显著差异。")
else:
print("在显著水平α=0.05下,各实验室测量的扑尔敏有效含量的均值没有显著差异。")
print("学号:2023310143028")