Skip to content

Instantly share code, notes, and snippets.

@JaHIY
Created March 19, 2012 14:37
Show Gist options
  • Save JaHIY/2114557 to your computer and use it in GitHub Desktop.
Save JaHIY/2114557 to your computer and use it in GitHub Desktop.
Python: Grabbs
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
python Grubbs.py 1.25 1.27 1.31 1.40 1.40 0.05 #前面一堆是数据,倒数第二的数是可疑值,最后一位是显著性水平a,可用值为 0.05/0.025/0.01
'''
import math
def solve(*args):
a = args[-1]
x = args[-2]
args = list(args[:-2])
args.sort()
n = len(args)
#print(n)
#print(args[0])
avg = round(float(sum(args))/float(n), 5)
s = round(float(math.sqrt(sum(pow(arg-avg, 2) for arg in args)/float(n-1))), 5)
t = round((x-avg)/s, 5)
if x == args[0]:
t = (-1)*t
T_list = ((1.15, 1.15, 1.15), (1.46, 1.48, 1.49), (1.67, 1.71, 1.75), (1.82, 1.89, 1.94), (1.94, 2.02, 2.10), (2.03, 2.13, 2.22), (2.11, 2.21, 2.32), (2.18, 2.29, 2.41), (2.23, 2.36, 2.48), (2.29, 2.41, 2.55), (2.33, 2.46, 2.61), (2.37, 2.51, 2.63), (2.41, 2.55, 2.71), (2.56, 2.71, 2.88))
A_dict = {
0.05: 0,
0.025: 1,
0.01: 2
}
A = A_dict[a]
T = T_list[n-3][A]
#print(T)
result = "Delete" if t > T else "Retain"
return avg, s, t, x, result
if __name__ == '__main__':
import sys
#print(sys.argv[1:])
argv = [float(arg) for arg in sys.argv[1:]]
#print(argv)
avg, s, t, x, result = solve(*argv)
print("Arithmetic mean: %.5f, Standard Deviation: %.5f, T=%.5f, You should %s %.5f" % (avg, s, t, result, x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment