anderson(x,dist='norm')
时间: 2023-11-29 14:04:56 浏览: 32
`anderson()` 函数是用来计算样本数据是否来自于某个指定分布的 Anderson-Darling 检验。该函数会返回两个值,一个是检验统计量的值,另一个是对应的临界值,可以与检验统计量的值比较来判断样本数据是否来自于指定分布。
下面是一个示例代码,展示如何使用 `anderson()` 函数进行 Anderson-Darling 检验:
```python
import numpy as np
from scipy.stats import anderson
# 生成一组随机数据
np.random.seed(123456789)
x = np.random.normal(size=100)
# 进行 Anderson-Darling 检验
result = anderson(x)
# 输出检验统计量的值和临界值
print('A2 =', result.statistic)
print('critical values =', result.critical_values)
# 判断样本数据是否来自于正态分布
if result.statistic < result.critical_values[2]:
print('样本数据来自于正态分布')
else:
print('样本数据不来自于正态分布')
```
上述代码中,我们使用 `numpy.random` 模块生成了一组随机数据 `x`,然后使用 `scipy.stats.anderson()` 方法对 `x` 进行了 Anderson-Darling 检验,并将结果存储在 `result` 变量中。我们输出了检验统计量的值和临界值,并根据检验统计量的值和临界值的比较,判断样本数据是否来自于正态分布。如果检验统计量的值小于临界值的第三个值,则可以认为样本数据来自于正态分布,否则认为不来自于正态分布。