统计和编程

2024-06-11 10:22:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用任何python统计包来检索正态PPCC分布的临界值。如果这些临界值可用,我如何访问它们…例如在numpy或statlib中。假设我有5个样本,我想得到p0.05的临界值。我已经从这个网站(http://www.itl.nist.gov/div898/handbook/eda/section3/eda3676.htm)得到了这个表,但是我想知道这个表在python中是否可用以及如何使用。 谢谢你(友善点(我是个新手程序员)


Tags: numpyhttp网站wwwedagovnist样本
1条回答
网友
1楼 · 发布于 2024-06-11 10:22:03

我还没找到那样的桌子。但是,您可以在这样的代码中使用该表

def normal_ppcc(x, n, level):
    table = {3: [0.8687, 0.879], 4: [0.8234, 0.8666], 5: [0.824, 0.8786], 6: [0.8351, 0.888], 7: [0.8474, 0.897], 8: [0.859, 0.9043], 9: [0.8689, 0.9115], 10: [0.8765, 0.9173], 11: [0.8838, 0.9223], 12: [0.8918, 0.9267], 13: [0.8974, 0.931], 14: [0.9029, 0.9343], 15: [0.908, 0.9376], 16: [0.9121, 0.9405], 17: [0.916, 0.9433], 18: [0.9196, 0.9452], 19: [0.923, 0.9479], 20: [0.9256, 0.9498]}
    if not n in table:
        raise ValueError ('n not in table')
    if not level in [0.01, 0.05]:
        raise ValueError ('invalid level')
    entry = 0 if level == 0.01 else 1
    return x < table[n][entry]

print (normal_ppcc(0.985, 10, 0.05))
print (normal_ppcc(0.8764, 10, 0.01))
print (normal_ppcc(0.9172, 10, 0.05))
print (normal_ppcc(0.92, 10, 0.05))

为了创建表,我将表粘贴到一个新的编辑器窗口中,然后运行这个Python代码。然后我将输出复制粘贴到上面的代码中

lines = '''\
3        0.8687        0.8790
4        0.8234        0.8666
5        0.8240        0.8786
6        0.8351        0.8880
7        0.8474        0.8970
8        0.8590        0.9043
9        0.8689        0.9115
10        0.8765        0.9173
11        0.8838        0.9223
12        0.8918        0.9267
13        0.8974        0.9310
14        0.9029        0.9343
15        0.9080        0.9376
16        0.9121        0.9405
17        0.9160        0.9433
18        0.9196        0.9452
19        0.9230        0.9479
20        0.9256        0.9498'''

table = {}
for line in lines.split('\n'):
    n, x_01, x_05 = line.split()
    table[int(n)] = [float(x_01), float(x_05)]
print (table)

相关问题 更多 >