在下面的词典列表中:
A=[
{key1 : val11, key2 : val21, key3 : val31, key5 : val51, key6 : val61},
{key2 : val22, key3 : val32, key5 : val52, key6 : val62},
{key1 : val13, key2 : val23, key4 : val43, key5 : val53},
{key1 : val14, key3 : val34, key4 : val44, key5 : val54, key6 : val64},
{key4 : val45, key5 : val55, key6 : val65}
]
我已经能够为所有词典中的每个键分配的值相加。但是我很难计算每个键的平均标准误差(SEM)。所以,如果你可以指导我计算每个键对应的SEM,我将非常感激。
谢谢, 亚历
答案 0 :(得分:0)
要计算某个键的平均标准误差,首先需要找到该键的标准偏差:
SEM公式:e = o/sqrt(n)
,其中s
是SEM,o
是标准偏差,n
是样本大小(1) :
import statistics #for simple calculation of the standard deviation of a list
A=[
{'key1' : 1, 'key2' : 21, 'key3':31, 'key5':51, 'key6':61},
{'key2': 22, 'key3' : 32, 'key5':52, 'key6':62},
{'key1':13, 'key2':23, 'key4':43, 'key5':53},
{'key1':14, 'key3':34, 'key4':44, 'key5':54, 'key6':64},
{'key4':45, 'key5':55, 'key6':65}]
full_keys = set([i for b in [c.keys() for c in A] for i in b])
data_listings = {i:list(filter(lambda x:x is not None, map(lambda y:y.get(i), A))) for i in full_keys}
error_listing = {a:statistics.stdev(b)/float(len(b)) for a, b in data_listings.items()}
输出:
{'key5': 0.31622776601683794, 'key1': 2.4113927126900783, 'key3': 0.5091750772173155, 'key4': 0.3333333333333333, 'key6': 0.45643546458763845, 'key2': 0.3333333333333333}