测试是在样品上完成的。这是一个在 Python 中使用OpenTURNS的示例。
import openturns as ot
首先让我们从居中的标准正态分布构建一个大小为 200 的随机样本您可能有自己的数据:
sample = ot.Sample([0, 0.3, -0.1, 0.23, -0.5], 1)
但 OpenTurns 提供了一种构建样本的简单方法
sample = ot.Normal().getSample(200)
现在要执行 Cramer-Von Mises 正态性检验,您只需调用此方法
test_result = ot.NormalityTest.CramerVonMisesNormal(sample)
然后打印结果
print('Component is normal?', test_result.getBinaryQualityMeasure(),
'p-value=%.6g' % test_result.getPValue(),
'threshold=%.6g' % test_result.getThreshold())
>>> Component is normal? True
p-value=0.624469
threshold=0.01
但请始终记住,阈值是任意的,即使样本确实来自正态分布,测试也可能给出假阴性。
如果要测试来自均匀分布的样本,请将“样本”行替换为:sample = ot.Uniform().getSample(200)