字典列表中的平均值标准误差 (sem)



在字典列表中,如下所示:

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,我将不胜感激。

谢谢亚历克斯

要计算某个键的均值标准误差,首先需要找到该键的标准差:

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}

最新更新